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

The following examples show how to use javax.xml.stream.XMLStreamException#getMessage() . 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
Source File: Bufr2Xml.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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
Source File: SubscriptionCreationWSWorkflowExecutor.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: AbstractStaxHandler.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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 4
Source File: ReadHeadersInterceptor.java    From cxf with 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 5
Source File: AbstractStaxHandler.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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 6
Source File: StaxEventXMLReader.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 7
Source File: XMLEventReaderImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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 8
Source File: AbstractXMLEventReader.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public Object next() {
	try {
		return nextEvent();
	}
	catch (XMLStreamException ex) {
		throw new NoSuchElementException(ex.getMessage());
	}
}
 
Example 9
Source File: AbstractStaxHandler.java    From ts-reaktive with 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 10
Source File: AbstractStaxHandler.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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 11
Source File: NodeDataWriter.java    From cxf with 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 12
Source File: AbstractStaxHandler.java    From ts-reaktive with 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 13
Source File: AbstractStaxHandler.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 14
Source File: AbstractStaxHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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 15
Source File: ParseUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 16
Source File: AbstractStaxHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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 17
Source File: StAXSource.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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 18
Source File: AbstractStaxHandler.java    From lams with GNU General Public License v2.0 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 19
Source File: SoapPayloadReaderFilter.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private void processBodyPartEvent(XMLEvent event) {
    try {
        StaxUtils.writeEvent(event, bodyPartWriter);
    } catch (XMLStreamException e) {
        throw new RuntimeCamelException("Error reading SOAP Body: " + e.getMessage(), e);
    }
}
 
Example 20
Source File: StaxEventXMLReader.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}