Java Code Examples for javax.xml.stream.XMLStreamException#getMessage()

The following examples show how to use javax.xml.stream.XMLStreamException#getMessage() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public Bufr2Xml(Message message, NetcdfFile ncfile, OutputStream os, boolean skipMissing) throws IOException {
  indent = new Indent(2);
  indent.setIndentLevel(0);

  try {
    XMLOutputFactory fac = XMLOutputFactory.newInstance();
    staxWriter = fac.createXMLStreamWriter(os, CDM.UTF8);

    staxWriter.writeStartDocument(CDM.UTF8, "1.0");
    // staxWriter.writeCharacters("\n");
    // staxWriter.writeStartElement("bufrMessage");

    writeMessage(message, ncfile);

    staxWriter.writeCharacters("\n");
    staxWriter.writeEndDocument();
    staxWriter.flush();

  } catch (XMLStreamException e) {
    throw new IOException(e.getMessage());
  }
}
 
Example 2
@Override
public final void startDTD(String name, String publicId, String systemId) throws SAXException {
	try {
		StringBuilder builder = new StringBuilder("<!DOCTYPE ");
		builder.append(name);
		if (publicId != null) {
			builder.append(" PUBLIC \"");
			builder.append(publicId);
			builder.append("\" \"");
		}
		else {
			builder.append(" SYSTEM \"");
		}
		builder.append(systemId);
		builder.append("\">");

		dtdInternal(builder.toString());
	}
	catch (XMLStreamException ex) {
		throw new SAXException("Could not handle startDTD: " + ex.getMessage(), ex);
	}
}
 
Example 3
Source Project: cxf   File: ReadHeadersInterceptor.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc}*/
public void handleMessage(SoapMessage message) throws Fault {
    XMLStreamReader xmlReader = message.getContent(XMLStreamReader.class);
    if (xmlReader != null) {
        try {
            while (xmlReader.hasNext()) {
                if (xmlReader.next() == XMLStreamConstants.END_DOCUMENT) {
                    return;
                }
            }
        } catch (XMLStreamException e) {
            throw new SoapFault(e.getMessage(), e,
                                message.getVersion().getSender());
        }
    }
}
 
Example 4
@Override
public final void startDTD(String name, String publicId, String systemId) throws SAXException {
	try {
		StringBuilder builder = new StringBuilder("<!DOCTYPE ");
		builder.append(name);
		if (publicId != null) {
			builder.append(" PUBLIC \"");
			builder.append(publicId);
			builder.append("\" \"");
		}
		else {
			builder.append(" SYSTEM \"");
		}
		builder.append(systemId);
		builder.append("\">");

		dtdInternal(builder.toString());
	}
	catch (XMLStreamException ex) {
		throw new SAXException("Could not handle startDTD: " + ex.getMessage(), ex);
	}
}
 
Example 5
@Override
public void cleanUpPendingTask(String workflowExtRef) throws WorkflowException {
    String errorMsg = null;
    super.cleanUpPendingTask(workflowExtRef);
    try {
        String action = WorkflowConstants.DELETE_SUBSCRIPTION_WS_ACTION;
        ServiceClient client = getClient(action);
        String payload = "<wor:CancelSubscriptionApprovalWorkflowProcessRequest " +
                "           xmlns:wor=\"http://workflow.subscription.apimgt.carbon.wso2.org\">\n" +
                "           <wor:workflowExtRef>" + workflowExtRef + "</wor:workflowExtRef>\n" +
                "        </wor:CancelSubscriptionApprovalWorkflowProcessRequest>";

        client.fireAndForget(AXIOMUtil.stringToOM(payload));
    } catch (AxisFault axisFault) {
        errorMsg = "Error sending out cancel pending subscription approval process message. cause: " + axisFault
                .getMessage();
        throw new WorkflowException(errorMsg, axisFault);
    } catch (XMLStreamException e) {
        errorMsg = "Error converting subscription cleanup String to OMElement. cause: " + e.getMessage();
        throw new WorkflowException(errorMsg, e);
    }
}
 
Example 6
public Object next() {
    Object object = null;
    try{
        object = nextEvent();
    }catch(XMLStreamException streamException){
        fLastEvent = null ;
        //don't swallow the cause
        NoSuchElementException e = new NoSuchElementException(streamException.getMessage());
        e.initCause(streamException.getCause());
        throw e;

    }
    return object;
}
 
Example 7
/**
 * Constructs a new instance of the {@code StaxEventXmlReader} that reads from the given
 * {@code XMLEventReader}. The supplied event reader must be in {@code XMLStreamConstants.START_DOCUMENT} or
 * {@code XMLStreamConstants.START_ELEMENT} state.
 * @param reader the {@code XMLEventReader} to read from
 * @throws IllegalStateException if the reader is not at the start of a document or element
 */
StaxEventXMLReader(XMLEventReader reader) {
	Assert.notNull(reader, "'reader' must not be null");
	try {
		XMLEvent event = reader.peek();
		if (event != null && !(event.isStartDocument() || event.isStartElement())) {
			throw new IllegalStateException("XMLEventReader not at start of document or element");
		}
	}
	catch (XMLStreamException ex) {
		throw new IllegalStateException("Could not read first element: " + ex.getMessage());
	}
	this.reader = reader;
}
 
Example 8
private void processBodyPartEvent(XMLEvent event) {
    try {
        StaxUtils.writeEvent(event, bodyPartWriter);
    } catch (XMLStreamException e) {
        throw new RuntimeCamelException("Error reading SOAP Body: " + e.getMessage(), e);
    }
}
 
Example 9
@Override
public final void endDocument() throws SAXException {
	removeAllNamespaceMappings();
	try {
		endDocumentInternal();
	}
	catch (XMLStreamException ex) {
		throw new SAXException("Could not handle endDocument: " + ex.getMessage(), ex);
	}
}
 
Example 10
public void parse() throws SAXException {
    // parses from a StAX reader and generates SAX events which
    // go through the repeater and are forwarded to the appropriate
    // component
    try {
        reader.bridge();
    } catch( XMLStreamException e ) {
        // wrap it in a SAXException
        SAXParseException se =
            new SAXParseException2(
                e.getMessage(),
                null,
                null,
                e.getLocation() == null ? -1 : e.getLocation().getLineNumber(),
                e.getLocation() == null ? -1 : e.getLocation().getColumnNumber(),
                e);

        // if the consumer sets an error handler, it is our responsibility
        // to notify it.
        if(errorHandler!=null)
            errorHandler.fatalError(se);

        // this is a fatal error. Even if the error handler
        // returns, we will abort anyway.
        throw se;

    } finally {
        try {
            staxReader.close();
        } catch(XMLStreamException xe) {
            //falls through. Not much can be done.
        }
    }
}
 
Example 11
@Override
public final void characters(char[] ch, int start, int length) throws SAXException {
	try {
		String data = new String(ch, start, length);
		if (!this.inCData) {
			charactersInternal(data);
		}
		else {
			cDataInternal(data);
		}
	}
	catch (XMLStreamException ex) {
		throw new SAXException("Could not handle characters: " + ex.getMessage(), ex);
	}
}
 
Example 12
/**
 * Get an exception reporting an unexpected XML element.
 * @param reader the stream reader
 * @return the exception
 */
public static XMLStreamException unexpectedElement(final XMLExtendedStreamReader reader) {
    final XMLStreamException ex = ControllerLogger.ROOT_LOGGER.unexpectedElement(reader.getName(), reader.getLocation());

    return new XMLStreamValidationException(ex.getMessage(),
                                            ValidationError.from(ex, ErrorType.UNEXPECTED_ELEMENT)
                                                    .element(reader.getName()),
                                            ex);
}
 
Example 13
@Override
public final void processingInstruction(String target, String data) throws SAXException {
	try {
		processingInstructionInternal(target, data);
	}
	catch (XMLStreamException ex) {
		throw new SAXException("Could not handle processingInstruction: " + ex.getMessage(), ex);
	}
}
 
Example 14
@Override
public final void comment(char[] ch, int start, int length) throws SAXException {
	try {
		commentInternal(new String(ch, start, length));
	}
	catch (XMLStreamException ex) {
		throw new SAXException("Could not handle comment: " + ex.getMessage(), ex);
	}
}
 
Example 15
Source Project: ts-reaktive   File: AbstractStaxHandler.java    License: MIT License 5 votes vote down vote up
@Override
public final void endDocument() throws SAXException {
    removeAllNamespaceMappings();
    try {
        endDocumentInternal();
    }
    catch (XMLStreamException ex) {
        throw new SAXException("Could not handle endDocument: " + ex.getMessage(), ex);
    }
}
 
Example 16
Source Project: cxf   File: NodeDataWriter.java    License: Apache License 2.0 5 votes vote down vote up
public void write(Object obj, Node n) {
    try {
        Source s = (Source) obj;
        if (s instanceof DOMSource
                && ((DOMSource) s).getNode() == null) {
            return;
        }

        XMLStreamWriter writer = new W3CDOMStreamWriter((Element)n);
        StaxUtils.copy(s, writer);
    } catch (XMLStreamException e) {
        throw new Fault("COULD_NOT_WRITE_XML_STREAM_CAUSED_BY", LOG, e,
                        e.getClass().getCanonicalName(), e.getMessage());
    }
}
 
Example 17
@Override
public final void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
	try {
		startElementInternal(toQName(uri, qName), atts, currentNamespaceMapping());
		newNamespaceMapping();
	}
	catch (XMLStreamException ex) {
		throw new SAXException("Could not handle startElement: " + ex.getMessage(), ex);
	}
}
 
Example 18
Source Project: ts-reaktive   File: AbstractStaxHandler.java    License: MIT License 5 votes vote down vote up
@Override
public final void skippedEntity(String name) throws SAXException {
    try {
        skippedEntityInternal(name);
    }
    catch (XMLStreamException ex) {
        throw new SAXException("Could not handle skippedEntity: " + ex.getMessage(), ex);
    }
}
 
Example 19
@Override
public Object next() {
	try {
		return nextEvent();
	}
	catch (XMLStreamException ex) {
		throw new NoSuchElementException(ex.getMessage());
	}
}
 
Example 20
/**
 * Constructs a new instance of the {@code StaxEventXmlReader} that reads from
 * the given {@code XMLEventReader}. The supplied event reader must be in
 * {@code XMLStreamConstants.START_DOCUMENT} or {@code XMLStreamConstants.START_ELEMENT} state.
 * @param reader the {@code XMLEventReader} to read from
 * @throws IllegalStateException if the reader is not at the start of a document or element
 */
StaxEventXMLReader(XMLEventReader reader) {
	try {
		XMLEvent event = reader.peek();
		if (event != null && !(event.isStartDocument() || event.isStartElement())) {
			throw new IllegalStateException("XMLEventReader not at start of document or element");
		}
	}
	catch (XMLStreamException ex) {
		throw new IllegalStateException("Could not read first element: " + ex.getMessage());
	}
	this.reader = reader;
}