17
17
package org .springframework .integration .camel .outbound ;
18
18
19
19
import java .util .Map ;
20
+ import java .util .Objects ;
20
21
import java .util .concurrent .CompletableFuture ;
21
22
22
23
import org .apache .camel .CamelContext ;
68
69
*/
69
70
public class CamelMessageHandler extends AbstractReplyProducingMessageHandler {
70
71
72
+ @ Nullable
71
73
private ProducerTemplate producerTemplate ;
72
74
73
75
private Expression exchangePatternExpression = new ValueExpression <>(ExchangePattern .InOnly );
@@ -83,6 +85,7 @@ public class CamelMessageHandler extends AbstractReplyProducingMessageHandler {
83
85
@ Nullable
84
86
private Expression exchangePropertiesExpression ;
85
87
88
+ @ Nullable
86
89
private StandardEvaluationContext evaluationContext ;
87
90
88
91
public CamelMessageHandler () {
@@ -197,46 +200,57 @@ public void configure() throws Exception {
197
200
}
198
201
199
202
@ Override
203
+ @ Nullable
200
204
protected Object handleRequestMessage (Message <?> requestMessage ) {
205
+ StandardEvaluationContext localEvaluationContext = Objects .requireNonNull (this .evaluationContext ,
206
+ "'evaluationContext' must not be null" );
201
207
ExchangePattern exchangePattern =
202
- this .exchangePatternExpression .getValue (this . evaluationContext , requestMessage , ExchangePattern .class );
208
+ this .exchangePatternExpression .getValue (localEvaluationContext , requestMessage , ExchangePattern .class );
203
209
204
210
Assert .notNull (exchangePattern , "'exchangePatternExpression' must not evaluate to null" );
205
211
206
212
Endpoint endpoint = resolveEndpoint (requestMessage );
207
213
Exchange exchange = prepareInExchange (endpoint , exchangePattern , requestMessage );
208
214
215
+ ProducerTemplate localProducerTemplate = Objects .requireNonNull (this .producerTemplate ,
216
+ "'producerTemplate' must not be null" );
209
217
if (isAsync ()) {
210
- CompletableFuture <Exchange > result = this . producerTemplate .asyncSend (endpoint , exchange );
218
+ CompletableFuture <Exchange > result = localProducerTemplate .asyncSend (endpoint , exchange );
211
219
return result .thenApply (resultExchange -> buildReply (exchangePattern , resultExchange ));
212
220
}
213
221
else {
214
- Exchange result = this . producerTemplate .send (endpoint , exchange );
222
+ Exchange result = localProducerTemplate .send (endpoint , exchange );
215
223
return buildReply (exchangePattern , result );
216
224
}
217
225
}
218
226
219
227
private Endpoint resolveEndpoint (Message <?> requestMessage ) {
228
+ StandardEvaluationContext localEvaluationContext = Objects .requireNonNull (this .evaluationContext ,
229
+ "'evaluationContext' must not be null" );
220
230
String endpointUri =
221
231
this .endpointUriExpression != null
222
- ? this .endpointUriExpression .getValue (this . evaluationContext , requestMessage , String .class )
232
+ ? this .endpointUriExpression .getValue (localEvaluationContext , requestMessage , String .class )
223
233
: null ;
224
234
235
+ ProducerTemplate localProducerTemplate = Objects .requireNonNull (this .producerTemplate ,
236
+ "'producerTemplate' must not be null" );
225
237
if (StringUtils .hasText (endpointUri )) {
226
- return this . producerTemplate .getCamelContext ().getEndpoint (endpointUri );
238
+ return localProducerTemplate .getCamelContext ().getEndpoint (endpointUri );
227
239
}
228
240
else {
229
- return this . producerTemplate .getDefaultEndpoint ();
241
+ return localProducerTemplate .getDefaultEndpoint ();
230
242
}
231
243
}
232
244
233
245
@ SuppressWarnings ("unchecked" )
234
246
private Exchange prepareInExchange (Endpoint endpoint , ExchangePattern exchangePattern , Message <?> requestMessage ) {
235
247
Exchange exchange = endpoint .createExchange (exchangePattern );
236
248
249
+ StandardEvaluationContext localEvaluationContext = Objects .requireNonNull (this .evaluationContext ,
250
+ "'evaluationContext' must not be null" );
237
251
Map <String , Object > exchangeProperties =
238
252
this .exchangePropertiesExpression != null
239
- ? this .exchangePropertiesExpression .getValue (this . evaluationContext , requestMessage , Map .class )
253
+ ? this .exchangePropertiesExpression .getValue (localEvaluationContext , requestMessage , Map .class )
240
254
: null ;
241
255
242
256
if (exchangeProperties != null ) {
0 commit comments