Search in sources :

Example 6 with BPELMessageContext

use of org.wso2.carbon.bpel.core.ode.integration.BPELMessageContext in project carbon-business-process by wso2.

the class BPELMessageReceiver method invokeBusinessLogic.

protected final void invokeBusinessLogic(final MessageContext inMessageContext) throws AxisFault {
    if (messageTraceLog.isDebugEnabled()) {
        messageTraceLog.debug("Message received: " + inMessageContext.getAxisService().getName() + "." + inMessageContext.getAxisOperation().getName());
        if (messageTraceLog.isTraceEnabled()) {
            messageTraceLog.trace("Request message: " + inMessageContext.getEnvelope());
        }
    }
    SOAPFactory soapFactory = getSOAPFactory(inMessageContext);
    final BPELMessageContext bpelMessageContext = BPELMessageContextFactory.createBPELMessageContext(inMessageContext, processProxy, soapFactory);
    // Initializing the attachments in the BPEL Message Context
    List<String> attachmentIDs = persistAttachments(inMessageContext.getAttachmentMap());
    if (attachmentIDs != null && !attachmentIDs.isEmpty()) {
        bpelMessageContext.setAttachmentIDList(attachmentIDs);
    }
    if (hasResponse(inMessageContext.getAxisOperation())) {
        handleInOutOperation(bpelMessageContext);
        if (messageTraceLog.isDebugEnabled()) {
            messageTraceLog.debug("Reply Sent: " + inMessageContext.getAxisService().getName() + "." + inMessageContext.getAxisOperation().getName());
            if (messageTraceLog.isTraceEnabled()) {
                messageTraceLog.trace("Response message: " + bpelMessageContext.getOutMessageContext().getEnvelope());
            }
        }
    } else {
        handleInOnlyOperation(bpelMessageContext);
    }
}
Also used : BPELMessageContext(org.wso2.carbon.bpel.core.ode.integration.BPELMessageContext) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 7 with BPELMessageContext

use of org.wso2.carbon.bpel.core.ode.integration.BPELMessageContext in project carbon-business-process by wso2.

the class PeopleActivity method invoke.

public String invoke(ExtensionContext extensionContext) throws FaultException {
    BPELMessageContext taskMessageContext = new BPELMessageContext(hiWSDL);
    UUID messageID = null;
    int tenantId = B4PServiceComponent.getBPELServer().getMultiTenantProcessStore().getTenantId(processId);
    String tenantDomain = null;
    try {
        tenantDomain = B4PContentHolder.getInstance().getRealmService().getTenantManager().getDomain(tenantId);
    } catch (UserStoreException e) {
        log.error(" Cannot find the tenant domain " + e.toString());
    }
    if (tenantDomain == null) {
        tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
    }
    PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
    try {
        // Setting the attachment id attachmentIDList
        List<Long> attachmentIDList = extractAttachmentIDsToBeSentToHumanTask(extensionContext, taskMessageContext);
        taskMessageContext.setOperationName(getOperationName());
        SOAPHelper soapHelper = new SOAPHelper(getBinding(), getSoapFactory(), isRPC);
        MessageContext messageContext = new MessageContext();
        /*
            Adding attachment ID list as a method input to createSoapRequest makes no sense.
            Have to fix. Here we can't embed attachments in MessageContext, as we have only a
            list of attachment ids.
            */
        soapHelper.createSoapRequest(messageContext, (Element) extensionContext.readVariable(inputVarName), getOperation(extensionContext), attachmentIDList);
        // Coordination Context and skipable attribute is only valid for a Task.
        if (InteractionType.TASK.equals(activityType)) {
            // Note: If registration service is not enabled, we don't need to send coor-context.
            if (CoordinationConfiguration.getInstance().isHumantaskCoordinationEnabled() && CoordinationConfiguration.getInstance().isRegistrationServiceEnabled()) {
                messageID = UUID.randomUUID();
                soapHelper.addCoordinationContext(messageContext, messageID.toString(), getRegistrationServiceURL());
            }
            // Adding HumanTask Context overriding attributes.
            soapHelper.addOverridingHumanTaskAttributes(messageContext, isSkipable);
        }
        taskMessageContext.setInMessageContext(messageContext);
        taskMessageContext.setPort(getServicePort());
        taskMessageContext.setService(getServiceName());
        taskMessageContext.setRPCStyleOperation(isRPC);
        taskMessageContext.setTwoWay(isTwoWay);
        taskMessageContext.setSoapFactoryForCurrentMessageFlow(getSoapFactory());
        taskMessageContext.setWsdlBindingForCurrentMessageFlow(getBinding());
        taskMessageContext.setUep(getUnifiedEndpoint());
        taskMessageContext.setCaller(processId.getLocalPart());
        AxisServiceUtils.invokeService(taskMessageContext, getConfigurationContext());
    } catch (AxisFault axisFault) {
        log.error(axisFault, axisFault);
        throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "Error occurred while invoking service " + serviceName, axisFault);
    } catch (B4PCoordinationException coordinationFault) {
        throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "Error occurred while generating Registration Service URL" + serviceName, coordinationFault);
    }
    if (taskMessageContext.getFaultMessageContext() != null || taskMessageContext.getOutMessageContext().isFault()) {
        MessageContext faultContext = taskMessageContext.getFaultMessageContext() != null ? taskMessageContext.getFaultMessageContext() : taskMessageContext.getOutMessageContext();
        log.warn("SOAP Fault: " + faultContext.getEnvelope().toString());
        throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, faultContext.getEnvelope().toString());
    }
    String taskID = SOAPHelper.parseResponseFeedback(taskMessageContext.getOutMessageContext().getEnvelope().getBody());
    // Ignore Notifications, since we are ignore coordination context for notification.
    if (CoordinationConfiguration.getInstance().isHumantaskCoordinationEnabled() && InteractionType.TASK.equals(activityType)) {
        Long instanceID = extensionContext.getProcessId();
        if (CoordinationConfiguration.getInstance().isRegistrationServiceEnabled()) {
            try {
                // Already coordinated with Registration service.
                updateCoordinationData(messageID.toString(), Long.toString(instanceID), taskID);
            } catch (Exception e) {
                log.error("Error occurred while updating humantask coordination data.", e);
            }
        } else {
            // Handler URL by manually.
            try {
                messageID = UUID.randomUUID();
                String protocolHandlerURL = generateTaskProtocolHandlerURL(taskMessageContext);
                if (log.isDebugEnabled()) {
                    log.debug("Generated Protocol Handler URL : " + protocolHandlerURL);
                }
                createCoordinationData(messageID.toString(), protocolHandlerURL, Long.toString(instanceID), taskID);
            } catch (Exception e) {
                log.error("Error occurred while creating humantask coordination data for coordinated task.", e);
            }
        }
    }
    return taskID;
}
Also used : AxisFault(org.apache.axis2.AxisFault) BPELMessageContext(org.wso2.carbon.bpel.core.ode.integration.BPELMessageContext) WSDL11Endpoint(org.apache.ode.bpel.epr.WSDL11Endpoint) UnifiedEndpoint(org.wso2.carbon.unifiedendpoint.core.UnifiedEndpoint) FaultException(org.apache.ode.bpel.common.FaultException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) B4PCoordinationException(org.wso2.carbon.bpel.b4p.coordination.B4PCoordinationException) SocketException(java.net.SocketException) SOAPHelper(org.wso2.carbon.bpel.b4p.utils.SOAPHelper) FaultException(org.apache.ode.bpel.common.FaultException) B4PCoordinationException(org.wso2.carbon.bpel.b4p.coordination.B4PCoordinationException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) BPELMessageContext(org.wso2.carbon.bpel.core.ode.integration.BPELMessageContext) MessageContext(org.apache.axis2.context.MessageContext) UUID(java.util.UUID)

Example 8 with BPELMessageContext

use of org.wso2.carbon.bpel.core.ode.integration.BPELMessageContext in project carbon-business-process by wso2.

the class PeopleActivity method generateTaskProtocolHandlerURL.

private String generateTaskProtocolHandlerURL(BPELMessageContext taskMessageContext) throws FaultException, B4PCoordinationException {
    String tenantTaskService = taskMessageContext.getUep().getAddress();
    int tenantDelimiterIndex = tenantTaskService.indexOf("/t/");
    String tenantIdentifier = "";
    if (tenantDelimiterIndex != -1) {
        // 3 = length("/t/")
        String temp = tenantTaskService.substring(tenantDelimiterIndex + 3);
        int indexOfSlash = temp.indexOf('/');
        tenantIdentifier = "/t/" + ((indexOfSlash != -1) ? temp.substring(0, indexOfSlash) : temp);
    }
    // Else super tenant. -> tenantIdentifier = ""
    String protocolHandlerURL = generateServiceURLUpToWebContext() + tenantIdentifier + BPEL4PeopleConstants.CARBON_ADMIN_SERVICE_CONTEXT_ROOT + "/" + BPEL4PeopleConstants.HT_ENGINE_COORDINATION_PROTOCOL_HANDLER_SERVICE;
    return protocolHandlerURL;
}
Also used : WSDL11Endpoint(org.apache.ode.bpel.epr.WSDL11Endpoint) UnifiedEndpoint(org.wso2.carbon.unifiedendpoint.core.UnifiedEndpoint)

Example 9 with BPELMessageContext

use of org.wso2.carbon.bpel.core.ode.integration.BPELMessageContext in project carbon-business-process by wso2.

the class BPELMessageContextFactory method createBPELMessageContext.

/**
 * Create BPELMessageContext object using information from in message context.
 *
 * @param inMessageContext in message context
 * @param processProxy     BPEL process proxy object
 * @param soapFactory      SOAPFactory instance
 * @return BPELMessageContext instance
 * @throws AxisFault in case of a error(most of the times AxisFault will be thrown from methods
 *                   used inside the implementation).
 */
public static BPELMessageContext createBPELMessageContext(final MessageContext inMessageContext, final BPELProcessProxy processProxy, final SOAPFactory soapFactory) throws AxisFault {
    BPELMessageContext bpelMessageContext = new BPELMessageContext(processProxy.getWsdlDefinition());
    bpelMessageContext.setInMessageContext(inMessageContext);
    bpelMessageContext.setSoapFactoryForCurrentMessageFlow(soapFactory);
    if (hasResponse(inMessageContext.getAxisOperation())) {
        setOutMessageContextToBPELMessageContext(bpelMessageContext);
    }
    fillBindingAndRelatedInformation(bpelMessageContext);
    bpelMessageContext.setRequestMessage(extractRequestMessageFromInMessageContext(inMessageContext));
    return bpelMessageContext;
}
Also used : BPELMessageContext(org.wso2.carbon.bpel.core.ode.integration.BPELMessageContext)

Example 10 with BPELMessageContext

use of org.wso2.carbon.bpel.core.ode.integration.BPELMessageContext in project carbon-business-process by wso2.

the class BPELMessageContextFactory method createBPELMessageContext.

public static BPELMessageContext createBPELMessageContext(final MessageContext inMessageContext, final PartnerService partnerService) {
    BPELMessageContext bpelMessageContext = new BPELMessageContext(partnerService.getWsdlDefinition());
    bpelMessageContext.setInMessageContext(inMessageContext);
    bpelMessageContext.setWsdlBindingForCurrentMessageFlow(partnerService.getBinding());
    setSOAPFactoryAndBindingStyle(bpelMessageContext);
    return bpelMessageContext;
}
Also used : BPELMessageContext(org.wso2.carbon.bpel.core.ode.integration.BPELMessageContext)

Aggregations

BPELMessageContext (org.wso2.carbon.bpel.core.ode.integration.BPELMessageContext)6 MessageContext (org.apache.axis2.context.MessageContext)3 BindingOperation (javax.wsdl.BindingOperation)2 SOAPFactory (org.apache.axiom.soap.SOAPFactory)2 AxisFault (org.apache.axis2.AxisFault)2 WSDL11Endpoint (org.apache.ode.bpel.epr.WSDL11Endpoint)2 Message (org.apache.ode.bpel.iapi.Message)2 BPELFault (org.wso2.carbon.bpel.core.ode.integration.BPELFault)2 WSDLAwareMessage (org.wso2.carbon.bpel.core.ode.integration.axis2.WSDLAwareMessage)2 UnifiedEndpoint (org.wso2.carbon.unifiedendpoint.core.UnifiedEndpoint)2 SocketException (java.net.SocketException)1 UUID (java.util.UUID)1 BindingOutput (javax.wsdl.BindingOutput)1 Fault (javax.wsdl.Fault)1 Operation (javax.wsdl.Operation)1 Part (javax.wsdl.Part)1 SOAP12Body (javax.wsdl.extensions.soap12.SOAP12Body)1 QName (javax.xml.namespace.QName)1 OMElement (org.apache.axiom.om.OMElement)1 OMNode (org.apache.axiom.om.OMNode)1