use of org.wso2.carbon.messaging.Header in project carbon-business-process by wso2.
the class SOAPUtils method handleSoapHeaderPartDef.
private static void handleSoapHeaderPartDef(org.apache.ode.bpel.iapi.Message odeMessage, Definition wsdl, SOAPHeader header, javax.wsdl.extensions.soap.SOAPHeader headerdef, Message msgType) throws BPELFault {
// Is this header part of the "payload" messsage?
boolean payloadMessageHeader = headerdef.getMessage() == null || headerdef.getMessage().equals(msgType.getQName());
boolean requiredHeader = payloadMessageHeader || (headerdef.getRequired() != null && headerdef.getRequired());
if (requiredHeader && header == null) {
throw new BPELFault("SOAP Header missing required element.");
}
if (header == null) {
return;
}
Message hdrMsg = wsdl.getMessage(headerdef.getMessage());
if (hdrMsg == null) {
return;
}
Part p = hdrMsg.getPart(headerdef.getPart());
if (p == null || p.getElementName() == null) {
return;
}
OMElement headerEl = header.getFirstChildWithName(p.getElementName());
if (requiredHeader && headerEl == null) {
throw new BPELFault("SOAP Header missing required element: " + p.getElementName());
}
if (headerEl == null) {
return;
}
odeMessage.setHeaderPart(p.getName(), OMUtils.toDOM(headerEl));
}
use of org.wso2.carbon.messaging.Header 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.wso2.carbon.messaging.Header in project carbon-business-process by wso2.
the class CallBackServiceImpl method sendProtocolMessage.
private void sendProtocolMessage(long taskID, String headerValue, String value) throws AxisFault {
final MessageContext mctx = new MessageContext();
ServiceInvocationContext invocationContext = new ServiceInvocationContext();
invocationContext.setInMessageContext(mctx);
invocationContext.setUep(uep);
invocationContext.setService(serviceName);
invocationContext.setPort(portName);
invocationContext.setCaller(taskName.getLocalPart());
invocationContext.setWsdlBindingForCurrentMessageFlow(binding);
invocationContext.setOperationName(operation);
if (mctx.getEnvelope() == null) {
mctx.setEnvelope(getSoapFactory().createSOAPEnvelope());
}
if (mctx.getEnvelope().getBody() == null) {
getSoapFactory().createSOAPBody(mctx.getEnvelope());
}
if (mctx.getEnvelope().getHeader() == null) {
getSoapFactory().createSOAPHeader(mctx.getEnvelope());
}
// Creating Dummy Element
// Extracting MessageName
List bindingOperations = binding.getBindingOperations();
String messageName = "";
OMNamespace serviceNS = null;
BindingOperation oper;
for (int i = 0; i < bindingOperations.size(); i++) {
oper = (BindingOperation) bindingOperations.get(i);
if (operation.equals(oper.getName())) {
Message message = oper.getOperation().getInput().getMessage();
messageName = message.getQName().getLocalPart();
for (Object ob : message.getParts().keySet()) {
// Here we don't support RPC messages.
Part part = (Part) message.getParts().get(ob);
serviceNS = OMAbstractFactory.getSOAP11Factory().createOMNamespace(part.getElementName().getNamespaceURI(), part.getElementName().getPrefix());
break;
}
break;
}
}
OMElement payload = OMAbstractFactory.getOMFactory().createOMElement(messageName, serviceNS);
mctx.getEnvelope().getBody().addChild(payload);
OMNamespace htpNS = OMAbstractFactory.getSOAP11Factory().createOMNamespace(HumanTaskConstants.HT_PROTOCOL_NAMESPACE, HumanTaskConstants.HT_PROTOCOL_DEFAULT_PREFIX);
SOAPHeaderBlock protocolHeader = mctx.getEnvelope().getHeader().addHeaderBlock(headerValue, htpNS);
protocolHeader.setText(value);
protocolHeader.addAttribute(HumanTaskConstants.B4P_CORRELATION_HEADER_ATTRIBUTE, Long.toString(taskID), htpNS);
OMNamespace b4pNS = OMAbstractFactory.getSOAP11Factory().createOMNamespace(HumanTaskConstants.B4P_NAMESPACE, "b4p");
SOAPHeaderBlock header = mctx.getEnvelope().getHeader().addHeaderBlock(HumanTaskConstants.B4P_CORRELATION_HEADER, b4pNS);
header.addAttribute(HumanTaskConstants.B4P_CORRELATION_HEADER_ATTRIBUTE, Long.toString(taskID), b4pNS);
AxisServiceUtils.invokeService(invocationContext, HumanTaskServiceComponent.getHumanTaskServer().getTaskStoreManager().getHumanTaskStore(tenantId).getConfigContext());
}
use of org.wso2.carbon.messaging.Header in project carbon-business-process by wso2.
the class CallBackServiceImpl method invoke.
@Override
public void invoke(OMElement payload, long taskId) throws AxisFault {
final MessageContext mctx = new MessageContext();
ServiceInvocationContext invocationContext = new ServiceInvocationContext();
invocationContext.setInMessageContext(mctx);
invocationContext.setUep(uep);
invocationContext.setService(serviceName);
invocationContext.setPort(portName);
invocationContext.setCaller(taskName.getLocalPart());
invocationContext.setWsdlBindingForCurrentMessageFlow(binding);
invocationContext.setOperationName(operation);
if (mctx.getEnvelope() == null) {
mctx.setEnvelope(getSoapFactory().createSOAPEnvelope());
}
if (mctx.getEnvelope().getBody() == null) {
getSoapFactory().createSOAPBody(mctx.getEnvelope());
}
if (mctx.getEnvelope().getHeader() == null) {
getSoapFactory().createSOAPHeader(mctx.getEnvelope());
}
mctx.getEnvelope().getBody().addChild(payload);
OMNamespace ns = OMAbstractFactory.getSOAP11Factory().createOMNamespace(HumanTaskConstants.B4P_NAMESPACE, "b4p");
SOAPHeaderBlock header = mctx.getEnvelope().getHeader().addHeaderBlock(HumanTaskConstants.B4P_CORRELATION_HEADER, ns);
header.addAttribute(HumanTaskConstants.B4P_CORRELATION_HEADER_ATTRIBUTE, Long.toString(taskId), ns);
AxisServiceUtils.invokeService(invocationContext, HumanTaskServiceComponent.getHumanTaskServer().getTaskStoreManager().getHumanTaskStore(tenantId).getConfigContext());
}
use of org.wso2.carbon.messaging.Header 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());
}
Aggregations