Search in sources :

Example 91 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project midpoint by Evolveum.

the class CustomDataWriter method write.

@Override
public void write(Object obj, MessagePartInfo part, XMLStreamWriter output) {
    QName rootElement = part.getElementQName();
    Element serialized;
    try {
        serialized = prismContex.domSerializer().serializeAnyData(obj, rootElement);
        StaxUtils.copy(serialized, output);
    //			output.writeCharacters(serialized);
    } catch (SchemaException | XMLStreamException e) {
        // TODO Auto-generated catch block
        throw new Fault(e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) XMLStreamException(javax.xml.stream.XMLStreamException) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Fault(org.apache.cxf.interceptor.Fault)

Example 92 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project webservices-axiom by apache.

the class ByteArrayCustomBuilder method create.

@Override
public OMDataSource create(OMElement element) throws OMException {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        element.serializeAndConsume(baos);
        byte[] bytes = baos.toByteArray();
        return new ByteArrayDataSource(bytes, encoding);
    } catch (XMLStreamException e) {
        throw new OMException(e);
    } catch (OMException e) {
        throw e;
    } catch (Throwable t) {
        throw new OMException(t);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayDataSource(org.apache.axiom.om.ds.ByteArrayDataSource) OMException(org.apache.axiom.om.OMException)

Example 93 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project webservices-axiom by apache.

the class InputStreamDataSource method serialize.

@Override
public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {
    if (data == null) {
        throw new OMException("The InputStreamDataSource does not have a backing object");
    }
    String encoding = format.getCharSetEncoding();
    try {
        if (!data.encoding.equalsIgnoreCase(encoding)) {
            byte[] bytes = getXMLBytes(encoding);
            output.write(bytes);
        } else {
            // Write the input stream to the output stream
            inputStream2OutputStream(data.is, output);
        }
    } catch (UnsupportedEncodingException e) {
        throw new XMLStreamException(e);
    } catch (IOException e) {
        throw new XMLStreamException(e);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) OMException(org.apache.axiom.om.OMException)

Example 94 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project webservices-axiom by apache.

the class TestNextAfterEndDocument method runTest.

protected void runTest() throws Throwable {
    XMLInputFactory factory = staxImpl.newNormalizedXMLInputFactory();
    XMLStreamReader reader = factory.createXMLStreamReader(new StringReader("<root/>"));
    while (reader.next() != XMLStreamReader.END_DOCUMENT) {
    // Just loop
    }
    try {
        reader.next();
        fail("Expected exception");
    } catch (IllegalStateException ex) {
    // Expected
    } catch (NoSuchElementException ex) {
    // This is also OK
    } catch (XMLStreamException ex) {
        fail("Expected IllegalStateException or NoSuchElementException");
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) StringReader(java.io.StringReader) XMLInputFactory(javax.xml.stream.XMLInputFactory) NoSuchElementException(java.util.NoSuchElementException)

Example 95 with XMLStreamException

use of javax.xml.stream.XMLStreamException in project webservices-axiom by apache.

the class ParserInputStreamDataSource method getXMLBytes.

@Override
public byte[] getXMLBytes(String encoding) {
    if (log.isDebugEnabled()) {
        log.debug("Entry ParserInputStreamDataSource.getXMLBytes(encoding)");
    }
    try {
        InputStream is = data.readParserInputStream();
        if (is != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            OMOutputFormat format = new OMOutputFormat();
            format.setCharSetEncoding(encoding);
            try {
                BufferUtils.inputStream2OutputStream(is, baos);
                if (log.isDebugEnabled()) {
                    log.debug("Exit ParserInputStreamDataSource.getXMLBytes(encoding)");
                }
                return baos.toByteArray();
            } catch (IOException e) {
                throw new OMException(e);
            }
        } else {
            //via SerializeAndConsume call
            if (log.isDebugEnabled()) {
                log.warn("Parser was already read, recovering by just returning new byte[0]");
                log.debug("Exit ParserInputStreamDataSource.getXMLBytes(encoding)");
            }
            return new byte[0];
        }
    } catch (XMLStreamException e) {
        throw new OMException(e);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) BAAInputStream(org.apache.axiom.attachments.utils.BAAInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) OMOutputFormat(org.apache.axiom.om.OMOutputFormat) OMException(org.apache.axiom.om.OMException)

Aggregations

XMLStreamException (javax.xml.stream.XMLStreamException)442 XMLStreamReader (javax.xml.stream.XMLStreamReader)137 IOException (java.io.IOException)126 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)75 XMLInputFactory (javax.xml.stream.XMLInputFactory)69 InputStream (java.io.InputStream)66 Document (org.w3c.dom.Document)36 JAXBException (javax.xml.bind.JAXBException)35 Fault (org.apache.cxf.interceptor.Fault)34 Element (org.w3c.dom.Element)32 StringReader (java.io.StringReader)30 XMLEvent (javax.xml.stream.events.XMLEvent)28 DOMSource (javax.xml.transform.dom.DOMSource)27 ByteArrayInputStream (java.io.ByteArrayInputStream)25 ArrayList (java.util.ArrayList)23 QName (javax.xml.namespace.QName)23 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)23 Node (org.w3c.dom.Node)22 StringWriter (java.io.StringWriter)21 XMLEventReader (javax.xml.stream.XMLEventReader)20