1717package org .springframework .integration .camel .outbound ;
1818
1919import java .util .Map ;
20+ import java .util .Objects ;
2021import java .util .concurrent .CompletableFuture ;
2122
2223import org .apache .camel .CamelContext ;
6869 */
6970public class CamelMessageHandler extends AbstractReplyProducingMessageHandler {
7071
72+ @ Nullable
7173 private ProducerTemplate producerTemplate ;
7274
7375 private Expression exchangePatternExpression = new ValueExpression <>(ExchangePattern .InOnly );
@@ -83,6 +85,7 @@ public class CamelMessageHandler extends AbstractReplyProducingMessageHandler {
8385 @ Nullable
8486 private Expression exchangePropertiesExpression ;
8587
88+ @ Nullable
8689 private StandardEvaluationContext evaluationContext ;
8790
8891 public CamelMessageHandler () {
@@ -197,46 +200,57 @@ public void configure() throws Exception {
197200 }
198201
199202 @ Override
203+ @ Nullable
200204 protected Object handleRequestMessage (Message <?> requestMessage ) {
205+ StandardEvaluationContext localEvaluationContext = Objects .requireNonNull (this .evaluationContext ,
206+ "'evaluationContext' must not be null" );
201207 ExchangePattern exchangePattern =
202- this .exchangePatternExpression .getValue (this . evaluationContext , requestMessage , ExchangePattern .class );
208+ this .exchangePatternExpression .getValue (localEvaluationContext , requestMessage , ExchangePattern .class );
203209
204210 Assert .notNull (exchangePattern , "'exchangePatternExpression' must not evaluate to null" );
205211
206212 Endpoint endpoint = resolveEndpoint (requestMessage );
207213 Exchange exchange = prepareInExchange (endpoint , exchangePattern , requestMessage );
208214
215+ ProducerTemplate localProducerTemplate = Objects .requireNonNull (this .producerTemplate ,
216+ "'producerTemplate' must not be null" );
209217 if (isAsync ()) {
210- CompletableFuture <Exchange > result = this . producerTemplate .asyncSend (endpoint , exchange );
218+ CompletableFuture <Exchange > result = localProducerTemplate .asyncSend (endpoint , exchange );
211219 return result .thenApply (resultExchange -> buildReply (exchangePattern , resultExchange ));
212220 }
213221 else {
214- Exchange result = this . producerTemplate .send (endpoint , exchange );
222+ Exchange result = localProducerTemplate .send (endpoint , exchange );
215223 return buildReply (exchangePattern , result );
216224 }
217225 }
218226
219227 private Endpoint resolveEndpoint (Message <?> requestMessage ) {
228+ StandardEvaluationContext localEvaluationContext = Objects .requireNonNull (this .evaluationContext ,
229+ "'evaluationContext' must not be null" );
220230 String endpointUri =
221231 this .endpointUriExpression != null
222- ? this .endpointUriExpression .getValue (this . evaluationContext , requestMessage , String .class )
232+ ? this .endpointUriExpression .getValue (localEvaluationContext , requestMessage , String .class )
223233 : null ;
224234
235+ ProducerTemplate localProducerTemplate = Objects .requireNonNull (this .producerTemplate ,
236+ "'producerTemplate' must not be null" );
225237 if (StringUtils .hasText (endpointUri )) {
226- return this . producerTemplate .getCamelContext ().getEndpoint (endpointUri );
238+ return localProducerTemplate .getCamelContext ().getEndpoint (endpointUri );
227239 }
228240 else {
229- return this . producerTemplate .getDefaultEndpoint ();
241+ return localProducerTemplate .getDefaultEndpoint ();
230242 }
231243 }
232244
233245 @ SuppressWarnings ("unchecked" )
234246 private Exchange prepareInExchange (Endpoint endpoint , ExchangePattern exchangePattern , Message <?> requestMessage ) {
235247 Exchange exchange = endpoint .createExchange (exchangePattern );
236248
249+ StandardEvaluationContext localEvaluationContext = Objects .requireNonNull (this .evaluationContext ,
250+ "'evaluationContext' must not be null" );
237251 Map <String , Object > exchangeProperties =
238252 this .exchangePropertiesExpression != null
239- ? this .exchangePropertiesExpression .getValue (this . evaluationContext , requestMessage , Map .class )
253+ ? this .exchangePropertiesExpression .getValue (localEvaluationContext , requestMessage , Map .class )
240254 : null ;
241255
242256 if (exchangeProperties != null ) {
0 commit comments