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;
25 import org.apache.commons.lang3.*
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
29 import org.onap.so.bpmn.common.scripts.ExceptionUtil
30 import org.onap.so.logger.MessageEnum
31 import org.onap.so.logger.MsoLogger
36 class ReceiveWorkflowMessage extends AbstractServiceTaskProcessor {
37 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, ReceiveWorkflowMessage.class);
40 ExceptionUtil exceptionUtil = new ExceptionUtil()
43 * Process the incoming variables.
45 * @param execution The flow's execution instance.
47 public void preProcessRequest (DelegateExecution execution) {
48 def method = getClass().getSimpleName() + '.preProcessRequest(' +
49 'execution=' + execution.getId() +
51 msoLogger.trace('Entered ' + method)
53 def prefix="RCVWFMSG_"
54 execution.setVariable("prefix", prefix)
55 setSuccessIndicator(execution, false)
59 // Confirm that timeout value has been provided in 'RCVWFMSG_timeout'.
60 def timeout = execution.getVariable('RCVWFMSG_timeout')
61 msoLogger.debug('Timeout value is \'' + timeout + '\'')
62 if ((timeout == null) || (timeout.isEmpty())) {
63 String msg = getProcessKey(execution) + ': Missing or empty input variable \'RCVWFMSG_timeout\''
65 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
66 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
69 // Confirm that message type has been provided in 'RCVWFMSG_messageType'
70 def messageType = execution.getVariable('RCVWFMSG_messageType')
71 msoLogger.debug('Message type is \'' + messageType + '\'')
72 if ((messageType == null) || (messageType.isEmpty())) {
73 String msg = getProcessKey(execution) + ': Missing or empty input variable \'RCVWFMSG_messageType\''
75 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
76 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
79 // Confirm that correlator value has been provided in 'RCVWFMSG_correlator'
80 def correlator = execution.getVariable('RCVWFMSG_correlator')
81 msoLogger.debug('Correlator value is \'' + correlator + '\'')
82 if ((correlator == null) || (correlator.isEmpty())) {
83 String msg = getProcessKey(execution) + ': Missing or empty input variable \'RCVWFMSG_correlator\''
85 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
86 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
88 execution.setVariable(messageType + '_CORRELATOR', correlator)
90 msoLogger.trace('Exited ' + method)
91 } catch (BpmnError e) {
93 } catch (Exception e) {
94 String msg = 'Caught exception in ' + method + ": " + e
96 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "");
97 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
102 * Process a received message.
104 * @param execution The flow's execution instance.
106 public void processReceivedMessage(DelegateExecution execution){
107 def method = getClass().getSimpleName() + '.processReceivedMessage(' +
108 'execution=' + execution.getId() +
110 msoLogger.trace('Entered ' + method)
112 String messageType = null;
113 String receivedMessage = null;
116 messageType = execution.getVariable('RCVWFMSG_messageType')
117 receivedMessage = execution.getVariable(messageType + '_MESSAGE')
118 msoLogger.debug(getProcessKey(execution) + ": received message:\n" + receivedMessage)
120 // The received message is made available to the calling flow in WorkflowResponse
121 execution.setVariable("WorkflowResponse", receivedMessage)
123 setSuccessIndicator(execution, true)
125 msoLogger.trace('Exited ' + method)
126 } catch (Exception e) {
127 receivedMessage = receivedMessage == null || String.valueOf(receivedMessage).isEmpty() ? "NONE" : receivedMessage
128 String msg = "Error processing received workflow message: " + receivedMessage
129 msoLogger.debug(getProcessKey(execution) + ': ' + msg)
130 exceptionUtil.buildWorkflowException(execution, 7020, msg)