1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
package org.openecomp.mso.bpmn.common.scripts;
import groovy.json.*
import org.apache.commons.lang3.*
import org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.delegate.DelegateExecution
import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor
import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
class ReceiveWorkflowMessage extends AbstractServiceTaskProcessor {
ExceptionUtil exceptionUtil = new ExceptionUtil()
/**
* Process the incoming variables.
*
* @param execution The flow's execution instance.
*/
public void preProcessRequest (DelegateExecution execution) {
def method = getClass().getSimpleName() + '.preProcessRequest(' +
'execution=' + execution.getId() +
')'
def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
logDebug('Entered ' + method, isDebugLogEnabled)
def prefix="RCVWFMSG_"
execution.setVariable("prefix", prefix)
setSuccessIndicator(execution, false)
try {
// Confirm that timeout value has been provided in 'RCVWFMSG_timeout'.
def timeout = execution.getVariable('RCVWFMSG_timeout')
logDebug('Timeout value is \'' + timeout + '\'', isDebugLogEnabled)
if ((timeout == null) || (timeout.isEmpty())) {
String msg = getProcessKey(execution) + ': Missing or empty input variable \'RCVWFMSG_timeout\''
logDebug(msg, isDebugLogEnabled)
logError(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
}
// Confirm that message type has been provided in 'RCVWFMSG_messageType'
def messageType = execution.getVariable('RCVWFMSG_messageType')
logDebug('Message type is \'' + messageType + '\'', isDebugLogEnabled)
if ((messageType == null) || (messageType.isEmpty())) {
String msg = getProcessKey(execution) + ': Missing or empty input variable \'RCVWFMSG_messageType\''
logDebug(msg, isDebugLogEnabled)
logError(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
}
// Confirm that correlator value has been provided in 'RCVWFMSG_correlator'
def correlator = execution.getVariable('RCVWFMSG_correlator')
logDebug('Correlator value is \'' + correlator + '\'', isDebugLogEnabled)
if ((correlator == null) || (correlator.isEmpty())) {
String msg = getProcessKey(execution) + ': Missing or empty input variable \'RCVWFMSG_correlator\''
logDebug(msg, isDebugLogEnabled)
logError(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
}
execution.setVariable(messageType + '_CORRELATOR', correlator)
logDebug('Exited ' + method, isDebugLogEnabled)
} catch (BpmnError e) {
throw e
} catch (Exception e) {
String msg = 'Caught exception in ' + method + ": " + e
logDebug(msg, isDebugLogEnabled)
logError(msg)
exceptionUtil.buildAndThrowWorkflowException(execution, 2000, msg)
}
}
/**
* Process a received message.
*
* @param execution The flow's execution instance.
*/
public void processReceivedMessage(DelegateExecution execution){
def method = getClass().getSimpleName() + '.processReceivedMessage(' +
'execution=' + execution.getId() +
')'
def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
logDebug('Entered ' + method, isDebugLogEnabled)
String messageType = null;
String receivedMessage = null;
try {
messageType = execution.getVariable('RCVWFMSG_messageType')
receivedMessage = execution.getVariable(messageType + '_MESSAGE')
logDebug(getProcessKey(execution) + ": received message:\n" + receivedMessage, isDebugLogEnabled)
// The received message is made available to the calling flow in WorkflowResponse
execution.setVariable("WorkflowResponse", receivedMessage)
setSuccessIndicator(execution, true)
logDebug('Exited ' + method, isDebugLogEnabled)
} catch (Exception e) {
receivedMessage = receivedMessage == null || String.valueOf(receivedMessage).isEmpty() ? "NONE" : receivedMessage
String msg = "Error processing received workflow message: " + receivedMessage
logDebug(getProcessKey(execution) + ': ' + msg, isDebugLogEnabled)
exceptionUtil.buildWorkflowException(execution, 7020, msg)
}
}
}
|