Search in sources :

Example 21 with SOAPHeaderBlock

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

the class TestExamineMustUnderstandHeaderBlocks method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPHeader header = soapFactory.createSOAPHeader();
    // Add header blocks using DOM
    Element domHeader = (Element) header;
    Document document = domHeader.getOwnerDocument();
    Element[] headerBlocks = new Element[3];
    for (int i = 0; i < 3; i++) {
        headerBlocks[i] = document.createElementNS("urn:test", "p:h" + i);
    }
    headerBlocks[1].setAttributeNS(spec.getEnvelopeNamespaceURI(), "S:mustUnderstand", "1");
    for (int i = 0; i < 3; i++) {
        // Clone the nodes because conversion to SOAPHeaderBlock is destructive
        domHeader.appendChild(headerBlocks[i].cloneNode(true));
    }
    // Use the Axiom API to iterate over the header blocks
    Iterator<SOAPHeaderBlock> it = header.examineMustUnderstandHeaderBlocks(null);
    assertThat(it.hasNext()).isTrue();
    SOAPHeaderBlock headerBlock = it.next();
    assertAbout(xml()).that(xml(OMElement.class, headerBlock)).hasSameContentAs(xml(Element.class, headerBlocks[1]));
    assertThat(it.hasNext()).isFalse();
}
Also used : OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) Document(org.w3c.dom.Document) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Example 22 with SOAPHeaderBlock

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

the class TestWrongParent3 method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPFaultDetail parent = soapFactory.createSOAPFaultDetail();
    OMElement child1 = soapFactory.createOMElement("child1", null, parent);
    SOAPHeaderBlock hb = soapFactory.createSOAPHeaderBlock("MyHeader", soapFactory.createOMNamespace("urn:test", "p"));
    try {
        child1.insertSiblingBefore(hb);
        fail("Expected SOAPProcessingException");
    } catch (SOAPProcessingException ex) {
    // Expected
    }
}
Also used : SOAPProcessingException(org.apache.axiom.soap.SOAPProcessingException) SOAPFaultDetail(org.apache.axiom.soap.SOAPFaultDetail) OMElement(org.apache.axiom.om.OMElement) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock)

Example 23 with SOAPHeaderBlock

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

the class TestExamineMustUnderstandHeaderBlocks method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope soapEnvelope = soapFactory.createSOAPEnvelope();
    SOAPHeader soapHeader = soapFactory.createSOAPHeader(soapEnvelope);
    OMNamespace namespace = soapFactory.createOMNamespace("http://www.example.org", "test");
    soapHeader.addHeaderBlock("echoOk1", namespace).setRole("http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver");
    SOAPHeaderBlock headerBlock1 = soapHeader.addHeaderBlock("echoOk2", namespace);
    headerBlock1.setRole("http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver");
    headerBlock1.setMustUnderstand(true);
    soapHeader.addHeaderBlock("echoOk3", namespace).setMustUnderstand(true);
    Iterator iterator = soapHeader.examineMustUnderstandHeaderBlocks("http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver");
    iterator.hasNext();
    SOAPHeaderBlock headerBlock = (SOAPHeaderBlock) iterator.next();
    assertFalse("SOAP Header Test : - examineMustUnderstandHeaderBlocks method returns empty iterator", headerBlock == null);
    assertTrue("SOAP Header Test : - HeaderBlock local name mismatch", headerBlock.getLocalName().equals("echoOk2"));
    assertTrue("SOAP Header Test : - HeaderBlock role value mismatch", headerBlock.getRole().equals("http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver"));
    assertFalse("SOAP Header Test : - examineMustUnderstandHeaderBlocks method returns an iterator with more than one object", iterator.hasNext());
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) Iterator(java.util.Iterator) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Example 24 with SOAPHeaderBlock

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

the class TestCloneWithSourcedElement2 method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope sourceEnv = soapFactory.getDefaultEnvelope();
    SOAPBody body = sourceEnv.getBody();
    SOAPHeader header = sourceEnv.getHeader();
    // Create a header OMSE
    OMDataSource dsHdr = new StringOMDataSource("<hdr:myheader xmlns:hdr=\"urn://test\">Hello World</hdr:myheader>");
    OMNamespace hdrNS = header.getOMFactory().createOMNamespace("urn://test", "hdr");
    SOAPFactory sf = (SOAPFactory) header.getOMFactory();
    SOAPHeaderBlock shb = sf.createSOAPHeaderBlock("myheader", hdrNS, dsHdr);
    // test setting processing flag
    shb.setProcessed();
    header.addChild(shb);
    // Create a payload
    OMDataSource ds = new StringOMDataSource("<tns:payload xmlns:tns=\"urn://test\">Hello World</tns:payload>");
    OMNamespace ns = body.getOMFactory().createOMNamespace("urn://test", "tns");
    OMSourcedElement omse = body.getOMFactory().createOMElement(ds, "payload", ns);
    body.addChild(omse);
    copyAndCheck(sourceEnv);
    // The source SOAPHeaderBlock should not be expanded in the process
    assertFalse(shb.isExpanded());
}
Also used : SOAPBody(org.apache.axiom.soap.SOAPBody) OMNamespace(org.apache.axiom.om.OMNamespace) OMDataSource(org.apache.axiom.om.OMDataSource) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) SOAPHeader(org.apache.axiom.soap.SOAPHeader) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 25 with SOAPHeaderBlock

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

the class TestGetXMLStreamReaderWithoutCachingWithPartiallyBuiltHeaderBlock method runTest.

@Override
protected void runTest(SOAPEnvelope envelope) throws Throwable {
    SOAPHeaderBlock headerBlock = (SOAPHeaderBlock) envelope.getHeader().getFirstChildWithName(new QName("http://www.w3.org/2005/08/addressing", "ReplyTo"));
    headerBlock.getFirstElement().getFirstOMChild();
    assertFalse(headerBlock.isComplete());
    XMLStreamReader reader = envelope.getXMLStreamReaderWithoutCaching();
    while (reader.hasNext()) {
        reader.next();
    }
    assertFalse(headerBlock.isComplete());
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) QName(javax.xml.namespace.QName) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock)

Aggregations

SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)40 SOAPHeader (org.apache.axiom.soap.SOAPHeader)22 QName (javax.xml.namespace.QName)15 OMNamespace (org.apache.axiom.om.OMNamespace)13 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)12 OMElement (org.apache.axiom.om.OMElement)8 OMAttribute (org.apache.axiom.om.OMAttribute)4 OMNode (org.apache.axiom.om.OMNode)4 SOAPBody (org.apache.axiom.soap.SOAPBody)4 SOAPProcessingException (org.apache.axiom.soap.SOAPProcessingException)4 BooleanAttributeAccessor (org.apache.axiom.ts.soap.BooleanAttributeAccessor)4 SOAPFault (org.apache.axiom.soap.SOAPFault)3 SOAPFaultDetail (org.apache.axiom.soap.SOAPFaultDetail)3 StringReader (java.io.StringReader)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)2 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)2 BlobOMDataSource (org.apache.axiom.om.ds.BlobOMDataSource)2 SOAPCloneOptions (org.apache.axiom.soap.SOAPCloneOptions)2 SOAPFaultCode (org.apache.axiom.soap.SOAPFaultCode)2