use of org.wso2.carbon.bpel.b4p.coordination.context.ExitProtocolMessage in project carbon-business-process by wso2.
the class TerminationTask method invokeProtocolHandler.
private synchronized void invokeProtocolHandler(ExitProtocolMessage message) {
OMElement payload = message.toOM();
Options options = new Options();
options.setTo(new EndpointReference(message.getTaskProtocolHandlerURL()));
options.setAction(WSConstants.WS_HT_COORDINATION_PROTOCOL_EXIT_ACTION);
options.setTransportInProtocol(org.apache.axis2.Constants.TRANSPORT_HTTPS);
ServiceClient serviceClient = null;
try {
serviceClient = new ServiceClient();
serviceClient.setOptions(options);
// Setting basic auth headers.
String tenantDomain = MultitenantUtils.getTenantDomainFromUrl(message.getTaskProtocolHandlerURL());
if (message.getTaskProtocolHandlerURL().equals(tenantDomain)) {
// this is a Super tenant registration service
CarbonUtils.setBasicAccessSecurityHeaders(CoordinationConfiguration.getInstance().getProtocolHandlerAdminUser(), CoordinationConfiguration.getInstance().getProtocolHandlerAdminPassword(), serviceClient);
} else {
if (log.isDebugEnabled()) {
log.debug("Sending exit protocol message to tenant domain: " + tenantDomain);
}
// Tenant's registration service
String username = "";
String password = "";
try {
UserRegistry configSystemRegistry = B4PContentHolder.getInstance().getRegistryService().getConfigSystemRegistry(tenantID);
Resource taskCoordination = configSystemRegistry.get(REG_TASK_COORDINATION);
if (taskCoordination != null) {
username = taskCoordination.getProperty(USERNAME);
password = taskCoordination.getProperty(PASSWORD);
} else {
log.error("Task coordination is not configured for tenant : " + tenantDomain + ". Dropping Exit Coordination message. Affected Tasks ids : " + message.getTaskIDs());
return;
}
} catch (RegistryException e) {
log.warn("Error while accessing Registry Service for tenant : " + tenantDomain + ". Dropping Exit Coordination message. Affected Tasks ids : " + message.getTaskIDs(), e);
return;
}
CarbonUtils.setBasicAccessSecurityHeaders(username, password, serviceClient);
}
serviceClient.fireAndForget(payload);
if (log.isDebugEnabled()) {
log.debug("Sent exit protocol message to " + message.getTaskProtocolHandlerURL());
}
} catch (AxisFault axisFault) {
log.error("Error occurred while invoking HT Protocol Handler " + message.getTaskProtocolHandlerURL() + ". Affected Tasks ids : " + message.getTaskIDs(), axisFault);
}
}
use of org.wso2.carbon.bpel.b4p.coordination.context.ExitProtocolMessage in project carbon-business-process by wso2.
the class TerminationTask method run.
@Override
public void run() {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext privilegedCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
privilegedCarbonContext.setTenantId(tenantID, true);
try {
List<TaskProtocolHandler> taskProtocolHandlers = null;
try {
taskProtocolHandlers = getHTProtocolHandlerURLWithTasks(instanceID);
} catch (Exception e) {
log.error("Error occurred while retrieving coordination data", e);
}
String currentProtocolHandler = "";
ExitProtocolMessage currentExitMessage = null;
for (TaskProtocolHandler taskProtocolHandler : taskProtocolHandlers) {
// Task Protocol Handler and Task ID should be not null
if (taskProtocolHandler.getProtocolHandlerURL() != null && taskProtocolHandler.getTaskID() != null) {
if (!currentProtocolHandler.equals(taskProtocolHandler.getProtocolHandlerURL())) {
// found a new protocol handler URL, so invoking old exit message.
if (currentExitMessage != null) {
// To ignore initial condition, we do null check here.
invokeProtocolHandler(currentExitMessage);
}
currentExitMessage = new ExitProtocolMessage(taskProtocolHandler.getProtocolHandlerURL());
currentProtocolHandler = taskProtocolHandler.getProtocolHandlerURL();
}
currentExitMessage.getTaskIDs().add(taskProtocolHandler.getTaskID());
if (log.isDebugEnabled()) {
log.debug("building exit protocol message for task id:" + taskProtocolHandler.getTaskID());
}
}
}
if (currentExitMessage != null) {
// Here we do last invocation.
invokeProtocolHandler(currentExitMessage);
}
// Cleaning coordination data.
boolean deleted = false;
try {
deleted = deleteCoordinationData(instanceID);
} catch (Exception e) {
log.error("Error occurred while cleaning coordination data for process instance id " + instanceID, e);
}
if (deleted && log.isDebugEnabled()) {
log.debug("Coordination data are removed from database for process instance id " + instanceID);
}
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
Aggregations