Search in sources :

Example 1 with CustomBuilderSupport

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

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

use of org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport 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)

Example 4 with CustomBuilderSupport

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

CustomBuilderSupport (org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport)4 SOAPModelBuilder (org.apache.axiom.soap.SOAPModelBuilder)4 OMElement (org.apache.axiom.om.OMElement)3 BlobOMDataSourceCustomBuilder (org.apache.axiom.om.ds.custombuilder.BlobOMDataSourceCustomBuilder)3 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)2 CustomBuilder (org.apache.axiom.om.ds.custombuilder.CustomBuilder)2 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)2 SOAPSampleAdapter (org.apache.axiom.ts.soap.SOAPSampleAdapter)2 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 OMContainer (org.apache.axiom.om.OMContainer)1 OMDataSource (org.apache.axiom.om.OMDataSource)1 OMException (org.apache.axiom.om.OMException)1 AbstractPushOMDataSource (org.apache.axiom.om.ds.AbstractPushOMDataSource)1 BlobOMDataSource (org.apache.axiom.om.ds.BlobOMDataSource)1 SOAPBody (org.apache.axiom.soap.SOAPBody)1 SOAPFault (org.apache.axiom.soap.SOAPFault)1 SOAPHeader (org.apache.axiom.soap.SOAPHeader)1