Search in sources :

Example 16 with SOAPModelBuilder

use of org.apache.axiom.soap.SOAPModelBuilder in project webservices-axiom by apache.

the class MTOMStAXSOAPModelBuilderTest method testUTF16MTOMMessage.

public void testUTF16MTOMMessage() throws Exception {
    String contentTypeString = "multipart/Related; charset=\"UTF-8\"; type=\"application/xop+xml\"; boundary=\"----=_AxIs2_Def_boundary_=42214532\"; start=\"SOAPPart\"";
    String cid = "1.urn:uuid:A3ADBAEE51A1A87B2A11443668160994@apache.org";
    String xmlPlusMime1 = "------=_AxIs2_Def_boundary_=42214532\r\n" + "Content-Type: application/xop+xml; charset=UTF-16; type=\"application/soap+xml\"\r\n" + "Content-Transfer-Encoding: 8bit\r\n" + "Content-ID: SOAPPart\r\n" + "\r\n";
    String xmlPlusMime2 = "<soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\"><soapenv:Body><m:data xmlns:m=\"http://www.example.org/stuff\"><m:name m:contentType=\"text/plain\"><xop:Include xmlns:xop=\"http://www.w3.org/2004/08/xop/include\" href=\"cid:" + cid + "\"></xop:Include></m:name></m:data></soapenv:Body></soapenv:Envelope>\r\n";
    String xmlPlusMime3 = "\r\n------=_AxIs2_Def_boundary_=42214532\r\n" + "Content-Transfer-Encoding: binary\r\n" + "Content-ID: " + cid + "\r\n" + "\r\n" + "Foo Bar\r\n" + "------=_AxIs2_Def_boundary_=42214532--\r\n";
    byte[] bytes1 = xmlPlusMime1.getBytes();
    byte[] bytes2 = xmlPlusMime2.getBytes("UTF-16");
    byte[] bytes3 = xmlPlusMime3.getBytes();
    byte[] full = append(bytes1, bytes2);
    full = append(full, bytes3);
    InputStream inStream = new BufferedInputStream(new ByteArrayInputStream(full));
    Attachments attachments = new Attachments(inStream, contentTypeString);
    SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(attachments);
    OMElement root = builder.getDocumentElement();
    root.build();
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OMElement(org.apache.axiom.om.OMElement) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) Attachments(org.apache.axiom.attachments.Attachments)

Example 17 with SOAPModelBuilder

use of org.apache.axiom.soap.SOAPModelBuilder 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)

Example 18 with SOAPModelBuilder

use of org.apache.axiom.soap.SOAPModelBuilder in project webservices-axiom by apache.

the class TestGetFirstElementLocalNameWithParserNoLookahead method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope orgEnvelope = soapFactory.getDefaultEnvelope();
    OMElement payload = soapFactory.createOMElement("payload", soapFactory.createOMNamespace("urn:test", "p"), orgEnvelope.getBody());
    OMElement child = soapFactory.createOMElement("child", null, payload);
    soapFactory.createOMElement("grandchild", null, child);
    SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, new StringReader(orgEnvelope.toString()));
    SOAPBody body = builder.getSOAPEnvelope().getBody();
    body.getFirstElement().getFirstElement();
    assertThat(body.getFirstElementLocalName()).isEqualTo("payload");
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder)

Aggregations

SOAPModelBuilder (org.apache.axiom.soap.SOAPModelBuilder)18 OMElement (org.apache.axiom.om.OMElement)11 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)11 ByteArrayInputStream (java.io.ByteArrayInputStream)4 StringReader (java.io.StringReader)4 CustomBuilderSupport (org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)3 BlobOMDataSourceCustomBuilder (org.apache.axiom.om.ds.custombuilder.BlobOMDataSourceCustomBuilder)3 SOAPFactory (org.apache.axiom.soap.SOAPFactory)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 Schema (javax.xml.validation.Schema)2 SchemaFactory (javax.xml.validation.SchemaFactory)2 Validator (javax.xml.validation.Validator)2 Attachments (org.apache.axiom.attachments.Attachments)2 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)2 OMText (org.apache.axiom.om.OMText)2 CustomBuilder (org.apache.axiom.om.ds.custombuilder.CustomBuilder)2