Search in sources :

Example 6 with SOAPModelBuilder

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

the class TestRegisterCustomBuilder method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPModelBuilder builder = SOAPSampleSet.WSA.getMessage(spec).getAdapter(SOAPSampleAdapter.class).getBuilder(metaFactory);
    ((CustomBuilderSupport) builder).registerCustomBuilder(new CustomBuilder.Selector() {

        @Override
        public boolean accepts(OMContainer parent, int depth, String namespaceURI, String localName) {
            return depth == 3 && namespaceURI.equals("http://www.w3.org/2005/08/addressing") && localName.equals("To");
        }
    }, new BlobOMDataSourceCustomBuilder(MemoryBlob.FACTORY, "utf-8"));
    SOAPHeader header = builder.getSOAPEnvelope().getHeader();
    ArrayList al = header.getHeaderBlocksWithNSURI("http://www.w3.org/2005/08/addressing");
    assertEquals(al.size(), 4);
    for (int i = 0; i < al.size(); i++) {
        SOAPHeaderBlock shb = (SOAPHeaderBlock) al.get(i);
        if ("To".equals(shb.getLocalName())) {
            assertNotNull(shb.getDataSource());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) CustomBuilderSupport(org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) BlobOMDataSourceCustomBuilder(org.apache.axiom.om.ds.custombuilder.BlobOMDataSourceCustomBuilder) CustomBuilder(org.apache.axiom.om.ds.custombuilder.CustomBuilder) SOAPSampleAdapter(org.apache.axiom.ts.soap.SOAPSampleAdapter) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) BlobOMDataSourceCustomBuilder(org.apache.axiom.om.ds.custombuilder.BlobOMDataSourceCustomBuilder) OMContainer(org.apache.axiom.om.OMContainer) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Example 7 with SOAPModelBuilder

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

the class TestRegisterCustomBuilderForPayload method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPModelBuilder builder = message.getAdapter(SOAPSampleAdapter.class).getBuilder(metaFactory);
    ((CustomBuilderSupport) builder).registerCustomBuilder(CustomBuilder.Selector.PAYLOAD, new BlobOMDataSourceCustomBuilder(MemoryBlob.FACTORY, "utf-8"));
    SOAPEnvelope envelope = builder.getSOAPEnvelope();
    OMElement payload = envelope.getBody().getFirstElement();
    if (message.getPayload() == null) {
        assertThat(payload).isNull();
    } else if (message.getPayload().getLocalName().equals("Fault")) {
        assertThat(payload).isInstanceOf(SOAPFault.class);
    } else {
        assertThat(payload).isInstanceOf(OMSourcedElement.class);
        BlobOMDataSource.Data data = (BlobOMDataSource.Data) ((OMSourcedElement) payload).getObject(BlobOMDataSource.class);
        assertThat(data).isNotNull();
        InputSource is = new InputSource(data.getBlob().getInputStream());
        is.setEncoding(data.getEncoding());
        assertAbout(xml()).that(is).ignoringNamespaceDeclarations().hasSameContentAs(message.getPayloadInputSource());
    }
    // We need to ignore redundant namespace declarations because the custom builder needs
    // to preserve the namespace context when serializing to the blob.
    assertAbout(xml()).that(envelope.getXMLStreamReader(false)).ignoringPrologAndEpilog().ignoringRedundantNamespaceDeclarations().hasSameContentAs(message.getInputStream());
    if (payload instanceof OMSourcedElement) {
        assertThat(((OMSourcedElement) payload).isExpanded()).isFalse();
    }
}
Also used : InputSource(org.xml.sax.InputSource) BlobOMDataSource(org.apache.axiom.om.ds.BlobOMDataSource) SOAPSampleAdapter(org.apache.axiom.ts.soap.SOAPSampleAdapter) CustomBuilderSupport(org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport) OMElement(org.apache.axiom.om.OMElement) SOAPFault(org.apache.axiom.soap.SOAPFault) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) BlobOMDataSourceCustomBuilder(org.apache.axiom.om.ds.custombuilder.BlobOMDataSourceCustomBuilder) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 8 with SOAPModelBuilder

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

the class TestBuilderDetach method runTest.

@Override
protected void runTest() throws Throwable {
    MTOMSample sample = MTOMSample.SAMPLE1;
    InstrumentedInputStream in = new InstrumentedInputStream(sample.getInputStream());
    MultipartBody mb = MultipartBody.builder().setInputStream(in).setContentType(sample.getContentType()).build();
    SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, mb);
    SOAPEnvelope envelope = builder.getSOAPEnvelope();
    long countBeforeDetach = in.getCount();
    builder.detach();
    assertThat(in.getCount()).isGreaterThan(countBeforeDetach);
    assertThat(in.isClosed()).isFalse();
    int binaryCount = 0;
    for (Iterator<OMNode> it = envelope.getDescendants(false); it.hasNext(); ) {
        OMNode node = it.next();
        if (node instanceof OMText) {
            OMText text = (OMText) node;
            if (text.isBinary()) {
                IOTestUtils.compareStreams(sample.getPart(text.getContentID()), text.getDataHandler().getInputStream());
                binaryCount++;
            }
        }
    }
    assertThat(binaryCount).isGreaterThan(0);
    in.close();
}
Also used : OMNode(org.apache.axiom.om.OMNode) MultipartBody(org.apache.axiom.mime.MultipartBody) InstrumentedInputStream(org.apache.axiom.testutils.io.InstrumentedInputStream) OMText(org.apache.axiom.om.OMText) MTOMSample(org.apache.axiom.ts.soap.MTOMSample) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

Example 9 with SOAPModelBuilder

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

the class AttachmentsTest method testSWAWriteWithIncomingOrder.

public void testSWAWriteWithIncomingOrder() throws Exception {
    // Read the stream that has soap xml followed by BAttachment then AAttachment
    InputStream inStream = SwASample.SAMPLE1.getInputStream();
    Attachments attachments = new Attachments(inStream, SwASample.SAMPLE1.getContentType());
    // Get the contentIDs to force the reading
    attachments.getAllContentIDs();
    // Get the root
    SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(attachments.getRootPartInputStream(), "UTF-8");
    OMElement root = builder.getDocumentElement();
    StringWriter xmlWriter = new StringWriter();
    root.serialize(xmlWriter);
    // Serialize the message using the legacy behavior (order by content id)
    OMOutputFormat format = new OMOutputFormat();
    format.setCharSetEncoding("utf-8");
    format.setDoingSWA(true);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    MIMEOutputUtils.writeSOAPWithAttachmentsMessage(xmlWriter, baos, attachments, format);
    String text = baos.toString();
    // Assert that AAttachment occurs before BAttachment since
    // that is the natural ordering of the content ids.
    assertTrue(text.indexOf("BAttachment") < text.indexOf("AAttachment"));
}
Also used : StringWriter(java.io.StringWriter) InputStream(java.io.InputStream) OMElement(org.apache.axiom.om.OMElement) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 10 with SOAPModelBuilder

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

the class TestDTD method runTest.

@Override
protected void runTest() throws Throwable {
    String message = "<!DOCTYPE test []>" + soapFactory.getDefaultEnvelope();
    XMLStreamReader parser = StAXUtils.createXMLStreamReader(new StringReader(message));
    ;
    try {
        SOAPModelBuilder builder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(metaFactory, parser);
        // The processing must fail before we can get the SOAPEnvelope
        builder.getSOAPEnvelope();
        fail("Expected SOAPProcessingException");
    } catch (SOAPProcessingException ex) {
    // Expected
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) SOAPProcessingException(org.apache.axiom.soap.SOAPProcessingException) StringReader(java.io.StringReader) 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