Search in sources :

Example 1 with FaultException

use of org.apache.ode.bpel.common.FaultException in project carbon-business-process by wso2.

the class BPEL4PeopleExtensionOperation method onRequestReceived.

/**
 * Called when the response for the above service is received
 *
 * @param mexId MessageExchange id
 */
@Override
public void onRequestReceived(String mexId) throws FaultException {
    if (log.isDebugEnabled()) {
        log.debug("People Activity Response received : mexId " + mexId);
    }
    Element notificationMessageEle = extensionContext.getInternalInstance().getMyRequest(mexId);
    if ("".equals(outputVarName) || outputVarName == null) {
        // if output variable is null or empty, these is no way to process the response from the task as we do
        // not have
        // a variable from bpel file to assign the values to. Hence what what we can do is to return a fault and
        // exit.
        log.error("Output variable not specified correctly for the remoteTask activity.Hence the error condition." + "Please verify and correct your BPEL process remoteTask");
        extensionContext.completeWithFault(cid, new FaultException(BPEL4PeopleConstants.B4P_FAULT, BPEL4PeopleConstants.NON_RECOVERABLE_ERROR));
    } else {
        Node part = extensionContext.getPartData(notificationMessageEle, outputVarName);
        if (messageTraceLog.isTraceEnabled()) {
            messageTraceLog.trace("B4P Response Message: " + DOMUtils.domToString(notificationMessageEle));
            messageTraceLog.trace("B4P Response Part: " + DOMUtils.domToString(part));
        }
        if (CoordinationConfiguration.getInstance().isHumantaskCoordinationEnabled() && notificationMessageEle.hasChildNodes()) {
            String taskID = "";
            Element correlationHeader = DOMUtils.findChildByName(notificationMessageEle, new QName(BPEL4PeopleConstants.B4P_NAMESPACE, BPEL4PeopleConstants.B4P_CORRELATION_HEADER), true);
            if (correlationHeader != null) {
                taskID = correlationHeader.getAttributeNS(BPEL4PeopleConstants.B4P_NAMESPACE, BPEL4PeopleConstants.B4P_CORRELATION_HEADER_ATTRIBUTE);
                try {
                    deleteCoordinationTaskData(taskID);
                } catch (Exception e) {
                    log.error("Error occurred while cleaning coordination data for task id " + taskID, e);
                }
            }
            // Checking for fault
            Element fault = DOMUtils.findChildByName(notificationMessageEle, new QName(WSConstants.WS_HT_COORDINATION_PROTOCOL_FAULT));
            if (fault != null) {
                if (fault.hasAttribute("headerPart")) {
                    if (log.isDebugEnabled()) {
                        log.debug("Throwing Fault to People Activity Scope since received Fault Protocol Message " + "for task" + taskID + ".");
                    }
                    extensionContext.completeWithFault(cid, new FaultException(BPEL4PeopleConstants.B4P_FAULT, BPEL4PeopleConstants.NON_RECOVERABLE_ERROR));
                    ;
                }
            }
            // Checking for Skip
            Element skipped = DOMUtils.findChildByName(notificationMessageEle, new QName(WSConstants.WS_HT_COORDINATION_PROTOCOL_SKIPPED));
            if (skipped != null) {
                if (skipped.hasAttribute("headerPart")) {
                    if (log.isDebugEnabled()) {
                        log.debug("Skipping People Activity since received Skipped Protocol Message for task " + taskID + ".");
                    }
                    // Set extension as complete, since task is skipped. No value write to output variable.
                    extensionContext.complete(cid);
                    return;
                }
            }
        }
        extensionContext.writeVariable(outputVarName, notificationMessageEle);
        extensionContext.complete(cid);
    }
}
Also used : FaultException(org.apache.ode.bpel.common.FaultException) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) FaultException(org.apache.ode.bpel.common.FaultException)

Example 2 with FaultException

use of org.apache.ode.bpel.common.FaultException in project carbon-business-process by wso2.

the class PeopleActivity method init.

private void init(ExtensionContext extensionContext, Element element) throws FaultException {
    if (!element.getLocalName().equals(BPEL4PeopleConstants.PEOPLE_ACTIVITY) || !element.getNamespaceURI().equals(BPEL4PeopleConstants.B4P_NAMESPACE)) {
        throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "No " + BPEL4PeopleConstants.PEOPLE_ACTIVITY + " activity found");
    }
    name = element.getAttribute(BPEL4PeopleConstants.PEOPLE_ACTIVITY_NAME);
    inputVarName = element.getAttribute(BPEL4PeopleConstants.PEOPLE_ACTIVITY_INPUT_VARIABLE);
    outputVarName = element.getAttribute(BPEL4PeopleConstants.PEOPLE_ACTIVITY_OUTPUT_VARIABLE);
    isSkipable = "yes".equalsIgnoreCase(element.getAttribute(BPEL4PeopleConstants.PEOPLE_ACTIVITY_IS_SKIPABLE));
    processStandardElement(element);
    processAttachmentPropagationElement(element);
    String duDir = extensionContext.getDUDir().toString();
    String duVersion = duDir.substring(duDir.lastIndexOf('-') + 1);
    if (duVersion.endsWith("/")) {
        duVersion = duVersion.substring(0, duVersion.lastIndexOf("/"));
    } else if (duVersion.endsWith("\\")) {
        duVersion = duVersion.substring(0, duVersion.lastIndexOf("\\"));
    }
    // //Commenting this logic to fix memory issues.
    // DeploymentUnitDir du = new DeploymentUnitDir(new File(extensionContext.getDUDir()));
    // processId = new QName(extensionContext.getProcessModel().getQName().getNamespaceURI(),
    // extensionContext.getProcessModel().getQName().getLocalPart() + "-" +
    // du.getStaticVersion());
    processId = new QName(extensionContext.getProcessModel().getQName().getNamespaceURI(), extensionContext.getProcessModel().getQName().getLocalPart() + "-" + duVersion);
    Integer tenantId = B4PServiceComponent.getBPELServer().getMultiTenantProcessStore().getTenantId(processId);
    DeploymentUnitDir du = B4PServiceComponent.getBPELServer().getMultiTenantProcessStore().getTenantsProcessStore(tenantId).getDeploymentUnitDir(processId);
    isTwoWay = activityType.equals(InteractionType.TASK);
    deriveServiceEPR(du, extensionContext);
}
Also used : FaultException(org.apache.ode.bpel.common.FaultException) QName(javax.xml.namespace.QName) DeploymentUnitDir(org.apache.ode.store.DeploymentUnitDir)

Example 3 with FaultException

use of org.apache.ode.bpel.common.FaultException 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 4 with FaultException

use of org.apache.ode.bpel.common.FaultException in project carbon-business-process by wso2.

the class PeopleActivity method getBinding.

public Binding getBinding() throws FaultException {
    Service serviceDef = hiWSDL.getService(serviceName);
    if (serviceDef == null) {
        throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "Service definition is not available for service " + serviceName);
    }
    Port port = serviceDef.getPort(getServicePort());
    if (port == null) {
        throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "Service port is not available for service " + serviceName + " and port " + getServicePort());
    }
    Binding binding = port.getBinding();
    if (binding == null) {
        throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "Service binding is not available for service " + serviceName + " and port " + getServicePort());
    }
    return binding;
}
Also used : HTTPBinding(javax.wsdl.extensions.http.HTTPBinding) SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) Binding(javax.wsdl.Binding) FaultException(org.apache.ode.bpel.common.FaultException) Port(javax.wsdl.Port) Service(javax.wsdl.Service)

Example 5 with FaultException

use of org.apache.ode.bpel.common.FaultException in project carbon-business-process by wso2.

the class PeopleActivity method deriveServiceEPR.

private void deriveServiceEPR(DeploymentUnitDir du, ExtensionContext extensionContext) throws FaultException {
    DeployDocument deployDocument = du.getDeploymentDescriptor();
    BpelRuntimeContext runTimeContext = extensionContext.getInternalInstance();
    // TODO neeed to extend ExtentionContext
    OProcess oProcess = runTimeContext.getProcessModel();
    TDeployment.Process hiProcess = null;
    List<TDeployment.Process> processList = deployDocument.getDeploy().getProcessList();
    for (TDeployment.Process process : processList) {
        if (process.getName().equals(oProcess.getQName())) {
            hiProcess = process;
            break;
        }
    }
    if (hiProcess == null) {
        throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "Related process: " + oProcess.getQName() + " not found");
    }
    List<TInvoke> tInvokeList = hiProcess.getInvokeList();
    for (TInvoke tInvoke : tInvokeList) {
        if (tInvoke.getPartnerLink().equals(partnerLinkName)) {
            serviceName = tInvoke.getService().getName();
            servicePort = tInvoke.getService().getPort();
            break;
        }
    }
    if (serviceName == null || servicePort == null) {
        log.error("service and port for human interaction is not found in the deploy.xml");
        throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "Service or port for human interaction is not found in the deploy.xml");
    }
    // get the callback information for the TASK
    if (activityType.equals(InteractionType.TASK)) {
        List<TProvide> tProvideList = hiProcess.getProvideList();
        for (TProvide tProvide : tProvideList) {
            if (tProvide.getPartnerLink().equals(partnerLinkName)) {
                callbackServiceName = tProvide.getService().getName();
                callbackServicePort = tProvide.getService().getPort();
                break;
            }
        }
        if (callbackServiceName == null || callbackServicePort == null) {
            throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "Service or port for human task callback is not found in the deploy.xml");
        }
    }
    hiWSDL = du.getDefinitionForService(serviceName);
    Service service = hiWSDL.getService(serviceName);
    Port port = service.getPort(servicePort);
    List extList = port.getExtensibilityElements();
    for (Object extEle : extList) {
        if (extEle instanceof SOAPAddressImpl) {
            SOAPAddressImpl soapAddress = (SOAPAddressImpl) extEle;
            serviceURI = soapAddress.getLocationURI();
            break;
        }
    }
    if (serviceURI == null) {
        throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "Service URI is not available");
    }
}
Also used : SOAPAddressImpl(com.ibm.wsdl.extensions.soap.SOAPAddressImpl) OProcess(org.apache.ode.bpel.o.OProcess) Port(javax.wsdl.Port) Service(javax.wsdl.Service) OProcess(org.apache.ode.bpel.o.OProcess) TDeployment(org.apache.ode.bpel.dd.TDeployment) TInvoke(org.apache.ode.bpel.dd.TInvoke) FaultException(org.apache.ode.bpel.common.FaultException) DeployDocument(org.apache.ode.bpel.dd.DeployDocument) BpelRuntimeContext(org.apache.ode.bpel.runtime.BpelRuntimeContext) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) TProvide(org.apache.ode.bpel.dd.TProvide)

Aggregations

FaultException (org.apache.ode.bpel.common.FaultException)10 QName (javax.xml.namespace.QName)3 WSDL11Endpoint (org.apache.ode.bpel.epr.WSDL11Endpoint)3 UnifiedEndpoint (org.wso2.carbon.unifiedendpoint.core.UnifiedEndpoint)3 Binding (javax.wsdl.Binding)2 Port (javax.wsdl.Port)2 Service (javax.wsdl.Service)2 HTTPBinding (javax.wsdl.extensions.http.HTTPBinding)2 SOAPBinding (javax.wsdl.extensions.soap.SOAPBinding)2 SOAP12Binding (javax.wsdl.extensions.soap12.SOAP12Binding)2 AxisFault (org.apache.axis2.AxisFault)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 SOAPAddressImpl (com.ibm.wsdl.extensions.soap.SOAPAddressImpl)1 SocketException (java.net.SocketException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)1 OMElement (org.apache.axiom.om.OMElement)1