use of org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse in project so by onap.
the class WorkflowContextHolderTest method testProcessCallback.
@Test
public void testProcessCallback() throws Exception {
String requestId = UUID.randomUUID().toString();
String message = "TEST MESSATGE";
String responseMessage = "Successfully processed request";
int testCode = 200;
WorkflowContextHolder contextHolder = WorkflowContextHolder.getInstance();
WorkflowCallbackResponse callbackResponse = new WorkflowCallbackResponse();
callbackResponse.setMessage(message);
callbackResponse.setResponse(responseMessage);
callbackResponse.setStatusCode(testCode);
contextHolder.processCallback("testAsyncProcess", "process-instance-id", requestId, callbackResponse);
// same object returned
WorkflowContext contextFound = contextHolder.getWorkflowContext(requestId);
if (contextFound == null)
throw new Exception("Expected to find Context Object");
WorkflowResponse testResponse = contextFound.getWorkflowResponse();
Assert.assertEquals(200, testResponse.getMessageCode());
Assert.assertEquals(message, testResponse.getMessage());
Assert.assertEquals(responseMessage, testResponse.getResponse());
}
use of org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse in project so by onap.
the class WorkflowActionBBTasks method sendErrorSyncAck.
public void sendErrorSyncAck(DelegateExecution execution) {
final String requestId = (String) execution.getVariable(BBConstants.G_REQUEST_ID);
try {
ExceptionBuilder exceptionBuilder = new ExceptionBuilder();
String errorMsg = (String) execution.getVariable("WorkflowActionErrorMessage");
if (errorMsg == null) {
errorMsg = "WorkflowAction failed unexpectedly.";
}
String processKey = exceptionBuilder.getProcessKey(execution);
String buildworkflowException = "<aetgt:WorkflowException xmlns:aetgt=\"http://org.onap/so/workflow/schema/v1\"><aetgt:ErrorMessage>" + errorMsg + "</aetgt:ErrorMessage><aetgt:ErrorCode>7000</aetgt:ErrorCode></aetgt:WorkflowException>";
WorkflowCallbackResponse callbackResponse = new WorkflowCallbackResponse();
callbackResponse.setStatusCode(500);
callbackResponse.setMessage("Fail");
callbackResponse.setResponse(buildworkflowException);
WorkflowContextHolder.getInstance().processCallback(processKey, execution.getProcessInstanceId(), requestId, callbackResponse);
execution.setVariable("sentSyncResponse", true);
} catch (Exception ex) {
logger.error(" Sending Sync Error Activity Failed. {}", ex.getMessage(), ex);
}
}
use of org.onap.so.bpmn.common.workflow.context.WorkflowCallbackResponse in project so by onap.
the class WorkflowActionBBTasks method sendSyncAck.
public void sendSyncAck(DelegateExecution execution) {
final String requestId = (String) execution.getVariable(BBConstants.G_REQUEST_ID);
final String resourceId = (String) execution.getVariable("resourceId");
ServiceInstancesResponse serviceInstancesResponse = new ServiceInstancesResponse();
RequestReferences requestRef = new RequestReferences();
requestRef.setInstanceId(resourceId);
requestRef.setRequestId(requestId);
serviceInstancesResponse.setRequestReferences(requestRef);
ObjectMapper mapper = new ObjectMapper();
String jsonRequest = "";
try {
jsonRequest = mapper.writeValueAsString(serviceInstancesResponse);
} catch (JsonProcessingException e) {
workflowAction.buildAndThrowException(execution, "Could not marshall ServiceInstancesRequest to Json string to respond to API Handler.", e);
}
WorkflowCallbackResponse callbackResponse = new WorkflowCallbackResponse();
callbackResponse.setStatusCode(200);
callbackResponse.setMessage("Success");
callbackResponse.setResponse(jsonRequest);
String processKey = execution.getProcessEngineServices().getRepositoryService().getProcessDefinition(execution.getProcessDefinitionId()).getKey();
WorkflowContextHolder.getInstance().processCallback(processKey, execution.getProcessInstanceId(), requestId, callbackResponse);
logger.info("Successfully sent sync ack.");
updateInstanceId(execution);
}
Aggregations