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