Search in sources :

Example 1 with ServiceInvocationContext

use of org.wso2.carbon.humantask.core.integration.utils.ServiceInvocationContext 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());
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) List(java.util.List) OMElement(org.apache.axiom.om.OMElement) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) MessageContext(org.apache.axis2.context.MessageContext) ServiceInvocationContext(org.wso2.carbon.humantask.core.integration.utils.ServiceInvocationContext) UnifiedEndpoint(org.wso2.carbon.unifiedendpoint.core.UnifiedEndpoint)

Example 2 with ServiceInvocationContext

use of org.wso2.carbon.humantask.core.integration.utils.ServiceInvocationContext 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());
}
Also used : OMNamespace(org.apache.axiom.om.OMNamespace) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) MessageContext(org.apache.axis2.context.MessageContext) ServiceInvocationContext(org.wso2.carbon.humantask.core.integration.utils.ServiceInvocationContext)

Aggregations

OMNamespace (org.apache.axiom.om.OMNamespace)2 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)2 MessageContext (org.apache.axis2.context.MessageContext)2 ServiceInvocationContext (org.wso2.carbon.humantask.core.integration.utils.ServiceInvocationContext)2 List (java.util.List)1 OMElement (org.apache.axiom.om.OMElement)1 UnifiedEndpoint (org.wso2.carbon.unifiedendpoint.core.UnifiedEndpoint)1