Search in sources :

Example 1 with BlobOMDataSourceCustomBuilder

use of org.apache.axiom.om.ds.custombuilder.BlobOMDataSourceCustomBuilder 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 2 with BlobOMDataSourceCustomBuilder

use of org.apache.axiom.om.ds.custombuilder.BlobOMDataSourceCustomBuilder 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 3 with BlobOMDataSourceCustomBuilder

use of org.apache.axiom.om.ds.custombuilder.BlobOMDataSourceCustomBuilder in project webservices-axiom by apache.

the class TestRegisterCustomBuilderForPayloadAfterSOAPFaultCheck method runTest.

@Override
protected void runTest(SOAPEnvelope envelope) throws Throwable {
    SOAPModelBuilder builder = (SOAPModelBuilder) envelope.getBuilder();
    // Do a fault check.  This is normally done in the engine (Axiom) and should
    // not cause inteference with the custom builder processing
    envelope.getBody().hasFault();
    // Do the registration here...this simulates when it could occure in the engine
    // (After the fault check and during phase processing...probably dispatch phase)
    ((CustomBuilderSupport) builder).registerCustomBuilder(CustomBuilder.Selector.PAYLOAD, new BlobOMDataSourceCustomBuilder(MemoryBlob.FACTORY, "utf-8"));
    OMElement bodyElement = envelope.getBody().getFirstElement();
    assertTrue(bodyElement instanceof OMSourcedElement);
}
Also used : CustomBuilderSupport(org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport) OMElement(org.apache.axiom.om.OMElement) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) BlobOMDataSourceCustomBuilder(org.apache.axiom.om.ds.custombuilder.BlobOMDataSourceCustomBuilder) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Aggregations

BlobOMDataSourceCustomBuilder (org.apache.axiom.om.ds.custombuilder.BlobOMDataSourceCustomBuilder)3 CustomBuilderSupport (org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport)3 SOAPModelBuilder (org.apache.axiom.soap.SOAPModelBuilder)3 OMElement (org.apache.axiom.om.OMElement)2 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)2 SOAPSampleAdapter (org.apache.axiom.ts.soap.SOAPSampleAdapter)2 ArrayList (java.util.ArrayList)1 OMContainer (org.apache.axiom.om.OMContainer)1 BlobOMDataSource (org.apache.axiom.om.ds.BlobOMDataSource)1 CustomBuilder (org.apache.axiom.om.ds.custombuilder.CustomBuilder)1 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)1 SOAPFault (org.apache.axiom.soap.SOAPFault)1 SOAPHeader (org.apache.axiom.soap.SOAPHeader)1 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)1 InputSource (org.xml.sax.InputSource)1