2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.common.scripts
23 import org.camunda.bpm.engine.delegate.BpmnError
24 import org.camunda.bpm.engine.delegate.DelegateExecution;
25 import org.onap.so.bpmn.core.WorkflowException
26 import org.onap.so.logger.MessageEnum
27 import org.onap.so.logger.MsoLogger
31 class VnfAdapterUtils {
32 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, VnfAdapterUtils.class);
35 private AbstractServiceTaskProcessor taskProcessor
37 public VnfAdapterUtils(AbstractServiceTaskProcessor taskProcessor) {
38 this.taskProcessor = taskProcessor
41 ExceptionUtil exceptionUtil = new ExceptionUtil()
43 public void validateVnfResponse(DelegateExecution execution, String responseVar, String responseCodeVar, String errorResponseVar) {
44 def method = getClass().getSimpleName() + '.validateVnfResponse(' +
45 'execution=' + execution.getId() +
46 ', responseVar=' + responseVar +
47 ', responseCodeVar=' + responseCodeVar +
48 ', errorResponseVar=' + errorResponseVar +
50 msoLogger.trace('Entered ' + method)
53 def prefix = execution.getVariable('prefix')
55 def response = execution.getVariable(responseVar)
56 def responseCode = execution.getVariable(responseCodeVar)
57 def errorResponse = execution.getVariable(errorResponseVar)
59 // The following if statement never appears to be true as any VNF Adapter error seems to be stored in 'errorResponse'.
60 // Also, the value is stored as a WorkflowException object, not a String. Added the else if to provide the proper
61 // functionality but leaving the original code in case it is hit under some circumstances.
62 if (response.contains("WorkflowException")) {
63 execution.setVariable(prefix + "ErrorResponse", response)
64 //execution.setVariable(prefix + "ResponseCode", responseCode)
65 msoLogger.debug(" Sub Vnf flow Error WorkflowException Response - " + "\n" + response)
66 throw new BpmnError("MSOWorkflowException")
67 } else if (errorResponse != null && errorResponse instanceof WorkflowException) {
68 // Not sure the variables with the associated prefix are still used
69 execution.setVariable(prefix + "ErrorResponse", errorResponse.getErrorMessage())
70 execution.setVariable(prefix + "ResponseCode", errorResponse.getErrorCode())
71 msoLogger.debug("Sub Vnf flow Error WorkflowException " + prefix + "ErrorResponse" + " - " + errorResponse.getErrorMessage())
72 // this is the important part to ensure we hit the Fallout Handler
73 throw new BpmnError("MSOWorkflowException")
74 } else if (errorResponse != null && errorResponse instanceof WorkflowException) {
75 // Not sure the variables with the associated prefix are still used
76 execution.setVariable(prefix + "ErrorResponse", errorResponse.getErrorMessage())
77 execution.setVariable(prefix + "ResponseCode", errorResponse.getErrorCode())
78 msoLogger.debug("Sub Vnf flow Error WorkflowException " + prefix + "ErrorResponse" + " - " + errorResponse.getErrorMessage())
79 // this is the important part to ensure we hit the Fallout Handler
80 throw new BpmnError("MSOWorkflowException")
82 } catch (BpmnError e) {
84 } catch (Exception e) {
85 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
86 exceptionUtil.buildAndThrowWorkflowException(execution, 5000, 'Internal Error- Unable to validate VNF Response ' + e.getMessage())