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());
}
}
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);
}
}
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());
}
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);
}
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);
}
Aggregations