Search in sources :

Example 26 with SOAPHeader

use of org.apache.axiom.soap.SOAPHeader in project carbon-business-process by wso2.

the class SOAPUtils method handleSOAPHeaderElementsInBindingOperation.

@SuppressWarnings("unchecked")
private static void handleSOAPHeaderElementsInBindingOperation(SOAPEnvelope soapEnvelope, SOAPFactory soapFactory, org.apache.ode.bpel.iapi.Message messageFromOde, Operation wsdlOperation, final javax.wsdl.extensions.soap.SOAPHeader soapHeaderElementDefinition) throws BPELFault {
    Map<String, Node> headerParts = messageFromOde.getHeaderParts();
    Message responseMessageDefinition = wsdlOperation.getOutput() != null ? wsdlOperation.getOutput().getMessage() : null;
    // If there isn't a message attribute in header element definition or if the
    // message attribute value is equal to the response message QName, then this
    // header element is part of the actual payload.
    // Refer SOAP Binding specification at http://www.w3.org/TR/wsdl#_soap-b.
    final boolean isHeaderElementAPartOfPayload = soapHeaderElementDefinition.getMessage() == null || ((wsdlOperation.getStyle() != OperationType.ONE_WAY) && soapHeaderElementDefinition.getMessage().equals(responseMessageDefinition.getQName()));
    if (soapHeaderElementDefinition.getPart() == null) {
        // Part information not found. Ignoring this header definition.
        return;
    }
    if (isHeaderElementAPartOfPayload && (responseMessageDefinition != null && responseMessageDefinition.getPart(soapHeaderElementDefinition.getPart()) == null)) {
        // we should throw a exception.
        throw new BPELFault("SOAP Header Element Definition refer unknown part.");
    }
    Element partElement = null;
    if (headerParts.size() > 0 && isHeaderElementAPartOfPayload) {
        try {
            partElement = (Element) headerParts.get(soapHeaderElementDefinition.getPart());
        } catch (ClassCastException e) {
            throw new BPELFault("SOAP Header must be a DOM Element.", e);
        }
    }
    // message payload. This is because, some headers will provided by SOAP engine.
    if (partElement == null && isHeaderElementAPartOfPayload) {
        if (messageFromOde.getPart(soapHeaderElementDefinition.getPart()) != null) {
            partElement = messageFromOde.getPart(soapHeaderElementDefinition.getPart());
        } else {
            throw new BPELFault("Missing Required part in response message.");
        }
    }
    // and can be found and extracted from the odeMessage object
    if (partElement == null && messageFromOde.getParts().size() > 0 && !isHeaderElementAPartOfPayload) {
        try {
            partElement = (Element) messageFromOde.getPart(soapHeaderElementDefinition.getPart());
        } catch (ClassCastException e) {
            throw new BPELFault("Soap header must be an element" + messageFromOde.getPart(soapHeaderElementDefinition.getPart()));
        }
    }
    // just ignore this case.
    if (partElement == null) {
        return;
    }
    org.apache.axiom.soap.SOAPHeader soapHeader = soapEnvelope.getHeader();
    if (soapHeader == null) {
        soapHeader = soapFactory.createSOAPHeader(soapEnvelope);
    }
    OMElement omPart = OMUtils.toOM(partElement, soapFactory);
    for (Iterator<OMNode> i = omPart.getChildren(); i.hasNext(); ) {
        soapHeader.addChild(i.next());
    }
}
Also used : Message(javax.wsdl.Message) BPELFault(org.wso2.carbon.bpel.core.ode.integration.BPELFault) OMNode(org.apache.axiom.om.OMNode) Node(org.w3c.dom.Node) OMElement(org.apache.axiom.om.OMElement) Element(org.w3c.dom.Element) OMElement(org.apache.axiom.om.OMElement) SOAPHeader(org.apache.axiom.soap.SOAPHeader) OMNode(org.apache.axiom.om.OMNode)

Example 27 with SOAPHeader

use of org.apache.axiom.soap.SOAPHeader in project carbon-business-process by wso2.

the class SOAPHelper method createSoapRequest.

/**
 * Create a SOAP request and add a list of attachment ids to the SOAP Header
 *
 * @param msgCtx           base message context which will be manipulated through out the operation
 * @param message          element to be included in the SOAP Body
 * @param op               operation incorporated with the request
 * @param attachmentIDList list of attachment ids to be included in the SOAP header
 * @throws AxisFault Exception if operation/input not found for the binding or if any exception thrown from
 *                   the axis2 level operations
 */
public void createSoapRequest(MessageContext msgCtx, Element message, Operation op, List<Long> attachmentIDList) throws AxisFault {
    createSoapRequest(msgCtx, message, op);
    SOAPHeader header = msgCtx.getEnvelope().getHeader();
    if (attachmentIDList != null && !attachmentIDList.isEmpty()) {
        addAttachmentIDHeader(header, attachmentIDList);
    }
}
Also used : SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Example 28 with SOAPHeader

use of org.apache.axiom.soap.SOAPHeader in project carbon-business-process by wso2.

the class SOAPHelper method addCoordinationContext.

/**
 * Adding ws-Coordination context to soap request.
 *
 * @param msgCtx              MessageContext
 * @param messageID           UUID as a WS-Coordination identifier
 * @param registrationService URL of the ws-coordination registration service.
 */
public void addCoordinationContext(MessageContext msgCtx, String messageID, String registrationService) {
    SOAPHeader header = msgCtx.getEnvelope().getHeader();
    EndpointReference epr = new EndpointReference();
    epr.setAddress(registrationService);
    CoordinationContext context = new HumanTaskCoordinationContextImpl(messageID, epr);
    header.addChild(context.toOM());
}
Also used : HumanTaskCoordinationContextImpl(org.wso2.carbon.bpel.b4p.coordination.context.impl.HumanTaskCoordinationContextImpl) SOAPHeader(org.apache.axiom.soap.SOAPHeader) EndpointReference(org.apache.axis2.addressing.EndpointReference) CoordinationContext(org.wso2.carbon.bpel.b4p.coordination.context.CoordinationContext)

Example 29 with SOAPHeader

use of org.apache.axiom.soap.SOAPHeader in project carbon-business-process by wso2.

the class SOAPHelper method addOverridingHumanTaskAttributes.

public void addOverridingHumanTaskAttributes(MessageContext msgCtx, boolean isSkipable) {
    SOAPHeader header = msgCtx.getEnvelope().getHeader();
    OMNamespace omNs = soapFactory.createOMNamespace(BPEL4PeopleConstants.HT_CONTEXT_NAMESPACE, BPEL4PeopleConstants.HT_CONTEXT_DEFAULT_PREFIX);
    OMElement contextRequest = header.getFirstChildWithName(new QName(BPEL4PeopleConstants.HT_CONTEXT_NAMESPACE, BPEL4PeopleConstants.HT_CONTEXT_REQUEST));
    // If context element is not exist create new one.
    if (contextRequest == null) {
        contextRequest = soapFactory.createOMElement(BPEL4PeopleConstants.HT_CONTEXT_REQUEST, omNs);
    }
    OMElement isSkipableElement = soapFactory.createOMElement(BPEL4PeopleConstants.HT_CONTEXT_IS_SKIPABLE, omNs);
    isSkipableElement.setText(Boolean.toString(isSkipable));
    contextRequest.addChild(isSkipableElement);
    header.addChild(contextRequest);
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Example 30 with SOAPHeader

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

the class TestBlobOMDataSource method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPEnvelope soapEnvelope = soapFactory.createSOAPEnvelope();
    SOAPHeader soapHeader = soapFactory.createSOAPHeader(soapEnvelope);
    String localName = "myPayload";
    String encoding = "utf-8";
    String payload = "<tns:myPayload xmlns:tns=\"urn://test\">Payload One</tns:myPayload>";
    OMNamespace ns = soapFactory.createOMNamespace("urn://test", "tns");
    BlobOMDataSource ds = new BlobOMDataSource(Blobs.createBlob(payload.getBytes(encoding)), encoding);
    // Set an empty MustUnderstand property on the data source
    ds.setProperty(SOAPHeaderBlock.MUST_UNDERSTAND_PROPERTY, null);
    OMSourcedElement omse = soapFactory.createSOAPHeaderBlock(localName, ns, ds);
    soapHeader.addChild(omse);
    OMNode firstChild = soapHeader.getFirstOMChild();
    assertTrue("Expected OMSourcedElement child", firstChild instanceof SOAPHeaderBlock);
    SOAPHeaderBlock child = (SOAPHeaderBlock) firstChild;
    assertTrue("OMSourcedElement is expanded.  This is unexpected", !child.isExpanded());
    assertThat(child.getDataSource()).isSameAs(ds);
    // Make sure that getting the MustUnderstand property does not cause expansion.
    assertTrue(!child.getMustUnderstand());
    assertTrue("OMSourcedElement is expanded.  This is unexpected", !child.isExpanded());
    assertThat(child.getDataSource()).isSameAs(ds);
    // A BlobOMDataSource does not consume the backing object when read.
    // Thus getting the XMLStreamReader of the BlobOMDataSource should not
    // cause expansion of the OMSourcedElement.
    XMLStreamReader reader = child.getXMLStreamReader();
    reader.next();
    assertTrue("OMSourcedElement is expanded.  This is unexpected", !child.isExpanded());
    // Likewise, a BlobOMDataSource does not consume the backing object when
    // written.  Thus serializing the OMSourcedElement should not cause the expansion
    // of the OMSourcedElement.
    assertTrue("The payload was not present in the output", soapHeader.toString().indexOf(payload) > 0);
    assertTrue("OMSourcedElement is expanded.  This is unexpected", !child.isExpanded());
    assertThat(child.getDataSource()).isSameAs(ds);
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMNamespace(org.apache.axiom.om.OMNamespace) XMLStreamReader(javax.xml.stream.XMLStreamReader) BlobOMDataSource(org.apache.axiom.om.ds.BlobOMDataSource) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) 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