Four Stars

[resolved] Problem with Simple

Hello,
I'have somes trouble with Simple code.
We're using AMQ to transit XML message to process:
<?xml version="1.0"?>
<response>
<sender>CP2</sender>
<method>createThreshold</method>
<userId>monmail@mondomaine.fr</userId>
<threshold>
<oldId>SA01</oldId>
<startDate>1996-01-01</startDate>
<endDate>1996-12-31</endDate>
<amount>78,206.35</amount>
</threshold>
</response>

I would like create a simple expression to process "method" field when the value is 'createThreshold'. So i've written the following expression
"${body.response.method} == 'createThreshold'"

At the route execution, i've that stacktrace in log:
Démarrage du job QueueRouter a 11:22 20/06/2014.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in
SLF4J: Found binding in
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type
MainSupport INFO Apache Camel 2.10.4 starting
ManagementStrategyFactory INFO JMX enabled.
SpringCamelContext INFO Apache Camel 2.10.4 (CamelContext: QueueRouter-ctx) is starting
DefaultTypeConverter INFO Loaded 175 type converters
XPathBuilder INFO Created default XPathFactory com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl@28bcd128
SpringCamelContext INFO Route: Read AMQ_cJMS_1 started and consuming from: Endpoint
SpringCamelContext INFO Route: createThreshold_cMessagingEndpoint_3 started and consuming from: Endpoint
SpringCamelContext INFO Route: updateThreshold_cMessagingEndpoint_4 started and consuming from: Endpoint
SpringCamelContext INFO Route: otherwise_cMessagingEndpoint_6 started and consuming from: Endpoint
ultManagementLifecycleStrategy INFO StatisticsLevel at All so enabling load performance statistics
SpringCamelContext INFO Total 4 routes, of which 4 is started.
SpringCamelContext INFO Apache Camel 2.10.4 (CamelContext: QueueRouter-ctx) started in 0.560 seconds
connecting to socket on port 3829
connected
] DefaultErrorHandler ERROR Failed delivery for (MessageId: ID:S-EURISK-007664-63132-1403251779388-3:3:1:1:1 on ExchangeId: ID-S-EURISK-007664-64019-1403256162745-0-1). Exhausted after delivery attempt: 1 caught: org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke method: .response.method on null due to: org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke method: response on null due to: org.apache.camel.component.bean.MethodNotFoundException: Method with name: response not found on bean: <?xml version="1.0"?><response><sender>CP2000</sender><method>createThreshold</method><userId>monmail@mondomaine.fr</userId><threshold><oldId>SA01</oldId><startDate>1996-01-01</startDate><endDate>1996-12-31</endDate><amount>78,206.35</amount></threshold></response> of type: java.lang.String. Exchange]
org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke method: .response.method on null due to: org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke method: response on null due to: org.apache.camel.component.bean.MethodNotFoundException: Method with name: response not found on bean: <?xml version="1.0"?><response><sender>CP2000</sender><method>createThreshold</method><userId>monmail@mondomaine.fr</userId><threshold><oldId>SA01</oldId><startDate>1996-01-01</startDate><endDate>1996-12-31</endDate><amount>78,206.35</amount></threshold></response> of type: java.lang.String. Exchange]
at org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:117)
at org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:132)
at org.apache.camel.model.language.ExpressionDefinition.evaluate(ExpressionDefinition.java:121)
at org.apache.camel.model.language.ExpressionDefinition.evaluate(ExpressionDefinition.java:113)
at org.apache.camel.builder.ExpressionBuilder$30.evaluate(ExpressionBuilder.java:720)
at org.apache.camel.support.ExpressionAdapter.evaluate(ExpressionAdapter.java:36)
at org.apache.camel.builder.BinaryPredicateSupport.matchesReturningFailureMessage(BinaryPredicateSupport.java:60)
at org.apache.camel.builder.BinaryPredicateSupport.matches(BinaryPredicateSupport.java:50)
at org.apache.camel.language.simple.ast.BinaryExpression$5.evaluate(BinaryExpression.java:227)
at org.apache.camel.util.ExpressionToPredicateAdapter.matches(ExpressionToPredicateAdapter.java:34)
at org.apache.camel.builder.SimpleBuilder.matches(SimpleBuilder.java:75)
at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:66)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:334)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:220)
at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:308)
at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)
at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)
at org.apache.camel.processor.RouteInflightRepositoryProcessor.processNext(RouteInflightRepositoryProcessor.java:48)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:99)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:86)
at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:104)
at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:560)
at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:498)
at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:467)
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:325)
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:263)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1058)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1050)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:947)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
] EndpointMessageListener WARN Execution of JMS message listener failed. Caused by: ]]
org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke method: response on null due to: org.apache.camel.component.bean.MethodNotFoundException: Method with name: response not found on bean: <?xml version="1.0"?><response><sender>CP2000</sender><method>createThreshold</method><userId>monmail@mondomaine.fr</userId><threshold><oldId>SA01</oldId><startDate>1996-01-01</startDate><endDate>1996-12-31</endDate><amount>78,206.35</amount></threshold></response> of type: java.lang.String. Exchange]
at org.apache.camel.language.bean.BeanExpression$OgnlInvokeProcessor.process(BeanExpression.java:285)
at org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:114)
at org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:132)
at org.apache.camel.model.language.ExpressionDefinition.evaluate(ExpressionDefinition.java:121)
at org.apache.camel.model.language.ExpressionDefinition.evaluate(ExpressionDefinition.java:113)
at org.apache.camel.builder.ExpressionBuilder$30.evaluate(ExpressionBuilder.java:720)
at org.apache.camel.support.ExpressionAdapter.evaluate(ExpressionAdapter.java:36)
at org.apache.camel.builder.BinaryPredicateSupport.matchesReturningFailureMessage(BinaryPredicateSupport.java:60)
at org.apache.camel.builder.BinaryPredicateSupport.matches(BinaryPredicateSupport.java:50)
at org.apache.camel.language.simple.ast.BinaryExpression$5.evaluate(BinaryExpression.java:227)
at org.apache.camel.util.ExpressionToPredicateAdapter.matches(ExpressionToPredicateAdapter.java:34)
at org.apache.camel.builder.SimpleBuilder.matches(SimpleBuilder.java:75)
at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:66)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:334)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:220)
at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:308)
at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)
at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)
at org.apache.camel.processor.RouteInflightRepositoryProcessor.processNext(RouteInflightRepositoryProcessor.java:48)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:99)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:86)
at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:104)
at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:560)
at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:498)
at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:467)
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:325)
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:263)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1058)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1050)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:947)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

thanks for help.
1 ACCEPTED SOLUTION

Accepted Solutions
Employee

Re: [resolved] Problem with Simple

Hi Hervé,
Simple doesn't understand XML - that syntax works when the body is a Java Bean instead of just a String of XML. The most direct way to do this with your XML is to use XPath rather than Simple. I'll give you a couple of options.
Option 1: Just use XPath
For your predicates on your router paths, you can select the XPath language. Select it and use an XPath expression something like this:
"/response/method"
and
"/response/method"

Option 2: Pull value with XPath, evaluate with Simple
Step 1: Add a cSetHeader component after your JMS listener and add a property to be set
- Choose the XPath Language
- Name the new header property (for instance, Response_Method)
- Set the expression to: "/response/method/text()"
Step 2: Evaluate with Simple
- In your Router predicate choose the Simple language
- Set it like this: "${header.Response_Method} == 'createThreshold'"

Deciding which option is better really depends on your end use case, but either should get the job done Smiley Happy
Best Regards,
Ben
2 REPLIES
Employee

Re: [resolved] Problem with Simple

Hi Hervé,
Simple doesn't understand XML - that syntax works when the body is a Java Bean instead of just a String of XML. The most direct way to do this with your XML is to use XPath rather than Simple. I'll give you a couple of options.
Option 1: Just use XPath
For your predicates on your router paths, you can select the XPath language. Select it and use an XPath expression something like this:
"/response/method"
and
"/response/method"

Option 2: Pull value with XPath, evaluate with Simple
Step 1: Add a cSetHeader component after your JMS listener and add a property to be set
- Choose the XPath Language
- Name the new header property (for instance, Response_Method)
- Set the expression to: "/response/method/text()"
Step 2: Evaluate with Simple
- In your Router predicate choose the Simple language
- Set it like this: "${header.Response_Method} == 'createThreshold'"

Deciding which option is better really depends on your end use case, but either should get the job done Smiley Happy
Best Regards,
Ben
Four Stars

Re: [resolved] Problem with Simple

Hi Ben,
Thanks for your answser. I will using xpath expression.
I was looking for the best method to evalute the method tag content, that can contains values like "*Threshold". I knew how doing that with simple... now i'know with xpath Smiley Happy
"response/method"

Regards