@@ -74,28 +74,29 @@ public abstract class CamelBehavior extends AbstractBpmnActivityBehavior impleme
7474 protected CamelContext camelContextObj ;
7575 protected List <MapExceptionEntry > mapExceptions ;
7676
77- protected abstract void setPropertTargetVariable (FlowableEndpoint endpoint );
78-
7977 public enum TargetType {
8078 BODY_AS_MAP , BODY , PROPERTIES
8179 }
8280
83- protected TargetType toTargetType ;
81+ protected TargetType determineToTargetType (FlowableEndpoint endpoint ) {
82+ if (endpoint .isCopyVariablesToBodyAsMap ()) {
83+ return TargetType .BODY_AS_MAP ;
84+ }
8485
85- protected void updateTargetVariables (FlowableEndpoint endpoint ) {
86- toTargetType = null ;
87- if (endpoint .isCopyVariablesToBodyAsMap ())
88- toTargetType = TargetType .BODY_AS_MAP ;
89- else if (endpoint .isCopyCamelBodyToBody ())
90- toTargetType = TargetType .BODY ;
91- else if (endpoint .isCopyVariablesToProperties ())
92- toTargetType = TargetType .PROPERTIES ;
86+ if (endpoint .isCopyCamelBodyToBody ()) {
87+ return TargetType .BODY ;
88+ }
89+
90+ if (endpoint .isCopyVariablesToProperties ()) {
91+ return TargetType .PROPERTIES ;
92+ }
9393
94- if (toTargetType == null )
95- setPropertTargetVariable (endpoint );
94+ return getDefaultToTargetType ();
9695 }
9796
98- protected void copyVariables (Map <String , Object > variables , Exchange exchange , FlowableEndpoint endpoint ) {
97+ protected abstract TargetType getDefaultToTargetType ();
98+
99+ protected void copyVariables (Map <String , Object > variables , Exchange exchange , FlowableEndpoint endpoint , TargetType toTargetType ) {
99100 switch (toTargetType ) {
100101 case BODY_AS_MAP :
101102 copyVariablesToBodyAsMap (variables , exchange );
@@ -112,8 +113,6 @@ protected void copyVariables(Map<String, Object> variables, Exchange exchange, F
112113
113114 @ Override
114115 public void execute (DelegateExecution execution ) {
115- setAppropriateCamelContext (execution );
116-
117116 boolean isV5Execution = false ;
118117 if ((Context .getCommandContext () != null && Flowable5Util .isFlowable5ProcessDefinitionId (Context .getCommandContext (), execution .getProcessDefinitionId ())) ||
119118 (Context .getCommandContext () == null && Flowable5Util .getFlowable5CompatibilityHandler () != null )) {
@@ -143,11 +142,14 @@ public void execute(DelegateExecution execution) {
143142
144143 protected FlowableEndpoint createEndpoint (DelegateExecution execution , boolean isV5Execution ) {
145144 String uri = "flowable://" + getProcessDefinitionKey (execution , isV5Execution ) + ":" + execution .getCurrentActivityId ();
146- return getEndpoint (uri );
145+ CamelContext camelContext = getCamelContext (execution , isV5Execution );
146+ return getEndpoint (camelContext , uri );
147147 }
148148
149- protected FlowableEndpoint getEndpoint (String key ) {
150- for (Endpoint e : camelContextObj .getEndpoints ()) {
149+ protected abstract CamelContext getCamelContext (DelegateExecution execution , boolean isV5Execution );
150+
151+ protected FlowableEndpoint getEndpoint (CamelContext camelContext , String key ) {
152+ for (Endpoint e : camelContext .getEndpoints ()) {
151153 if (e .getEndpointKey ().equals (key ) && (e instanceof FlowableEndpoint )) {
152154 return (FlowableEndpoint ) e ;
153155 }
@@ -160,8 +162,8 @@ protected Exchange createExchange(DelegateExecution activityExecution, FlowableE
160162 ex .setProperty (FlowableProducer .PROCESS_ID_PROPERTY , activityExecution .getProcessInstanceId ());
161163 ex .setProperty (FlowableProducer .EXECUTION_ID_PROPERTY , activityExecution .getId ());
162164 Map <String , Object > variables = activityExecution .getVariables ();
163- updateTargetVariables (endpoint );
164- copyVariables (variables , ex , endpoint );
165+ TargetType toTargetType = determineToTargetType (endpoint );
166+ copyVariables (variables , ex , endpoint , toTargetType );
165167 return ex ;
166168 }
167169
@@ -232,8 +234,6 @@ protected boolean isASync(DelegateExecution execution) {
232234 return async ;
233235 }
234236
235- protected abstract void setAppropriateCamelContext (DelegateExecution execution );
236-
237237 protected String getStringFromField (Expression expression , DelegateExecution execution ) {
238238 if (expression != null ) {
239239 Object value = expression .getValue (execution );
0 commit comments