Search in sources :

Example 16 with SOAPHeader

use of org.apache.axiom.soap.SOAPHeader 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 17 with SOAPHeader

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

the class TestBodyHeaderOrder method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope env = soapFactory.createSOAPEnvelope();
    soapFactory.createSOAPBody(env);
    soapFactory.createSOAPHeader(env);
    assertTrue("Header isn't the first child!", env.getFirstElement() instanceof SOAPHeader);
}
Also used : SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Example 18 with SOAPHeader

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

the class TestGetHeaderWithParser method runTest.

@Override
protected void runTest(SOAPEnvelope envelope) throws Throwable {
    SOAPHeader header = envelope.getHeader();
    assertEquals("Header Test : - Header local name mismatch", SOAPConstants.HEADER_LOCAL_NAME, header.getLocalName());
    assertEquals("Header Test : - Header namespace mismatch", spec.getEnvelopeNamespaceURI(), header.getNamespace().getNamespaceURI());
}
Also used : SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Example 19 with SOAPHeader

use of org.apache.axiom.soap.SOAPHeader in project wso2-synapse by wso2.

the class LogMediator method getHeadersLogMessage.

private String getHeadersLogMessage(MessageContext synCtx) {
    StringBuffer sb = new StringBuffer();
    if (synCtx.getEnvelope() != null) {
        SOAPHeader header = synCtx.getEnvelope().getHeader();
        if (header != null) {
            for (Iterator iter = header.examineAllHeaderBlocks(); iter.hasNext(); ) {
                Object o = iter.next();
                if (o instanceof SOAPHeaderBlock) {
                    SOAPHeaderBlock headerBlk = (SOAPHeaderBlock) o;
                    sb.append(separator).append(headerBlk.getLocalName()).append(" : ").append(headerBlk.getText());
                } else if (o instanceof OMElement) {
                    OMElement headerElem = (OMElement) o;
                    sb.append(separator).append(headerElem.getLocalName()).append(" : ").append(headerElem.getText());
                }
            }
        }
    }
    setCustomProperties(sb, synCtx);
    return trimLeadingSeparator(sb);
}
Also used : Iterator(java.util.Iterator) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) OMElement(org.apache.axiom.om.OMElement) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Example 20 with SOAPHeader

use of org.apache.axiom.soap.SOAPHeader in project wso2-synapse by wso2.

the class HeaderMediator method addCustomHeader.

private void addCustomHeader(MessageContext synCtx, String value) {
    SOAPEnvelope env = synCtx.getEnvelope();
    if (env == null) {
        return;
    }
    SOAPFactory fac = (SOAPFactory) env.getOMFactory();
    SOAPHeader header = env.getHeader();
    if (header == null) {
        header = fac.createSOAPHeader(env);
    }
    if (!isImplicit()) {
        SOAPHeaderBlock hb = header.addHeaderBlock(qName.getLocalPart(), fac.createOMNamespace(qName.getNamespaceURI(), qName.getPrefix()));
        hb.setText(value);
    } else if (hasEmbeddedXml()) {
        addHeaderChildrenToMessageContext(synCtx, embeddedXmlContent);
    } else {
        // header mediator has an implicit xml element but its content cannot be found.
        handleException("Header mediator has an implicit xml element but its content cannot be found.", synCtx);
    }
}
Also used : SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Aggregations

SOAPHeader (org.apache.axiom.soap.SOAPHeader)56 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)33 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)32 OMElement (org.apache.axiom.om.OMElement)18 OMNamespace (org.apache.axiom.om.OMNamespace)15 QName (javax.xml.namespace.QName)13 Iterator (java.util.Iterator)10 OMNode (org.apache.axiom.om.OMNode)10 SOAPFactory (org.apache.axiom.soap.SOAPFactory)9 SOAPBody (org.apache.axiom.soap.SOAPBody)8 SOAPFault (org.apache.axiom.soap.SOAPFault)5 OMException (org.apache.axiom.om.OMException)4 EndpointReference (org.apache.axis2.addressing.EndpointReference)4 OMAttribute (org.apache.axiom.om.OMAttribute)3 SOAPFaultCode (org.apache.axiom.soap.SOAPFaultCode)3 SOAPFaultDetail (org.apache.axiom.soap.SOAPFaultDetail)3 SOAPFaultReason (org.apache.axiom.soap.SOAPFaultReason)3 BooleanAttributeAccessor (org.apache.axiom.ts.soap.BooleanAttributeAccessor)3 Element (org.w3c.dom.Element)3 StringReader (java.io.StringReader)2