Search in sources :

Example 46 with OMException

use of org.apache.axiom.om.OMException in project webservices-axiom by apache.

the class FirstElementNameWithParserTestCase method runTest.

@Override
protected final void runTest() throws Throwable {
    SOAPEnvelope orgEnvelope = soapFactory.getDefaultEnvelope();
    orgEnvelope.getBody().addChild(soapFactory.createOMElement(qname.getLocalPart(), qname.getNamespaceURI(), qname.getPrefix()));
    SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, new StringReader(orgEnvelope.toString()));
    SOAPBody body = builder.getSOAPEnvelope().getBody();
    runTest(body);
    if (supportsOptimization) {
        // The expectation is that even after looking at the payload element name, registering
        // a custom builder still transforms the element.
        ((CustomBuilderSupport) builder).registerCustomBuilder(CustomBuilder.Selector.PAYLOAD, new CustomBuilder() {

            @Override
            public OMDataSource create(OMElement element) throws OMException {
                try {
                    element.getXMLStreamReaderWithoutCaching().close();
                } catch (XMLStreamException ex) {
                    throw new OMException(ex);
                }
                return new AbstractPushOMDataSource() {

                    @Override
                    public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
                        xmlWriter.writeEmptyElement(qname.getPrefix(), qname.getLocalPart(), qname.getNamespaceURI());
                    }

                    @Override
                    public boolean isDestructiveWrite() {
                        return false;
                    }
                };
            }
        });
        assertThat(body.getFirstElement()).isInstanceOf(OMSourcedElement.class);
    }
}
Also used : OMDataSource(org.apache.axiom.om.OMDataSource) AbstractPushOMDataSource(org.apache.axiom.om.ds.AbstractPushOMDataSource) CustomBuilderSupport(org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) CustomBuilder(org.apache.axiom.om.ds.custombuilder.CustomBuilder) SOAPBody(org.apache.axiom.soap.SOAPBody) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) StringReader(java.io.StringReader) AbstractPushOMDataSource(org.apache.axiom.om.ds.AbstractPushOMDataSource) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) OMException(org.apache.axiom.om.OMException)

Aggregations

OMException (org.apache.axiom.om.OMException)46 IOException (java.io.IOException)13 OMElement (org.apache.axiom.om.OMElement)13 OMFactory (org.apache.axiom.om.OMFactory)12 XMLStreamException (javax.xml.stream.XMLStreamException)11 OMText (org.apache.axiom.om.OMText)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 MessageDigest (java.security.MessageDigest)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 StringReader (java.io.StringReader)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 Iterator (java.util.Iterator)4 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)4 InputStream (java.io.InputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 Writer (java.io.Writer)3 QName (javax.xml.namespace.QName)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 OMAttribute (org.apache.axiom.om.OMAttribute)3 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)3