1 package org.onap.so.bpmn.common.scripts
3 import javax.ws.rs.core.Response
5 import org.camunda.bpm.engine.delegate.DelegateExecution
6 import org.slf4j.Logger
7 import org.slf4j.LoggerFactory
9 import com.fasterxml.jackson.databind.ObjectMapper
11 import org.onap.so.bpmn.core.UrnPropertiesReader
12 import org.onap.logging.filter.base.ONAPComponents
13 import org.onap.so.client.HttpClient
14 import org.onap.so.client.HttpClientFactory
16 import static org.onap.so.bpmn.common.scripts.GenericUtils.isBlank
18 public class CNFAdapterAsync extends AbstractServiceTaskProcessor {
19 private static final Logger logger = LoggerFactory.getLogger(CNFAdapterAsync.class)
21 ExceptionUtil exceptionUtil = new ExceptionUtil()
22 ObjectMapper mapper = new ObjectMapper();
25 public void preProcessRequest(DelegateExecution execution) {
26 logger.debug("Start preProcessRequest");
28 String apiPath = execution.getVariable("apiPath")
29 if (isBlank(apiPath)) {
30 String msg = "Cannot process CNF adapter call : API PATH is null"
31 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
34 //Object cnfRequestPayloadFromExecutionVariable = execution.getVariable("cnfRequestPayload")
36 String cnfRequestPayload = execution.getVariable("cnfRequestPayload")
37 if (isBlank(cnfRequestPayload)) {
38 String msg = "Cannot process CNF adapter call : cnfRequestPayload is null"
39 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
42 String correlator = execution.getVariable("correlator")
43 if (isBlank(correlator)) {
44 String msg = "Cannot process CNF adapter call : correlator is null"
45 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
48 String messageType = execution.getVariable("messageType")
49 if (isBlank(messageType)) {
50 String msg = "Cannot process CNF adapter call : messageType is null"
51 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
54 String timeout = UrnPropertiesReader.getVariable("mso.adapters.cnf.timeout", execution);
55 if (isBlank(timeout)) {
56 logger.debug("Setting CNF Adapter timeout to default : PT30M")
60 execution.setVariable("timeout",timeout)
62 logger.debug("Enter preProcessRequest: {}",execution.getVariable("messageType"));
65 void callCnfAdapter(DelegateExecution execution) {
66 logger.debug("Start callCnfAdapter")
67 String cnfAdapterEndpoint = execution.getVariable("apiPath")
68 URL requestUrl = new URL(cnfAdapterEndpoint)
69 String cnfRequest = execution.getVariable("cnfRequestPayload")
70 logger.debug("cnfRequest : " + cnfRequest)
71 HttpClient httpClient = new HttpClientFactory().newJsonClient(requestUrl, ONAPComponents.EXTERNAL)
72 Response httpResponse = httpClient.post(cnfRequest)
73 int responseCode = httpResponse.getStatus()
74 logger.debug("CNF sync response code is: " + responseCode)
75 if(responseCode < 200 || responseCode >= 300){
76 exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from CNF.")
78 logger.debug("End callCnfAdapter")