use of org.wso2.carbon.bpel.b4p.utils.SOAPHelper 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;
}
Aggregations