JSONPath error in Content based router

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

JSONPath error in Content based router

contactreji
This post was updated on .
I have a route like below

 <route customId="false" id="route360">
        <from uri="jetty:http://0.0.0.0:8081/branch?httpMethodRestrict=PUT
"/>
        <onException id="onException172" useOriginalMessage="true">
            <exception>java.lang.Exception</exception>
            <process id="process755"/>
            <log id="log656" loggingLevel="ERROR" message="${exception}"/>
            <to id="to509" pattern="InOnly"
uri="seda:exception_reporters?multipleConsumers=true"/>
            <process id="process756"/>
        </onException>
        <log id="log657" message="Received http payload : ${body}"/>
        <process id="process757"/>
        <process id="process758"/>
        <process id="process759"/>
        <choice id="choice15">
            <when id="when37">
                <jsonpath
suppressExceptions="false">$.[?(@.age>20)]</jsonpath>
                <to id="to510"
uri="direct:429552d4-3d87-3666-bd8d-a0db589044f3"/>
            </when>
            <when id="when38">
                <jsonpath
suppressExceptions="false">$.[?(@.age<20)]</jsonpath>
                <to id="to511"
uri="direct:62eb1a9e-5720-3b67-8e70-8e00701a866e"/>
            </when>
            <otherwise id="otherwise7">
                <to id="to512"
uri="direct:cdf1dcb8-4228-3117-a220-cdc00647a5d5"/>
            </otherwise>
        </choice>
    </route>


And I am using test payload as below

{
"age" : 12
}

When the value of age is > 20, my filters work fine. But when it is less
than 20, I get following error

14:23:13.305 [qtp1747371038-41] ERROR
com.company.camel.core.route.RouteErrorHandler - Error has occurred:
com.jayway.jsonpath.InvalidPathException: Filter: [?] can not be applied to
primitives. Current context is:
14:23:13.306 [qtp1747371038-41] ERROR route360 -
org.apache.camel.ExpressionEvaluationException:
com.jayway.jsonpath.InvalidPathException: Filter: [?] can not be applied to
primitives. Current context is:
14:23:13.310 [Camel (c01d8372-a93c-3b39-a961-57c58cf51a6b) thread #265 -
seda://exception_reporters] INFO  route361 - creating entry in error table
{"error_message":"com.jayway.jsonpath.InvalidPathException: Filter: [?] can
not be applied to primitives. Current context is:
","error_code":"APIC.8000"}

Any idea?

Regards
Reji Mathews
Reji Mathews Sr. Engineer - Middleware Integrations / SOA ( Open Source - Apache Camel & Jboss Fuse ESB | Mule ESB ) LinkedIn - http://in.linkedin.com/pub/reji-mathews/31/9a2/40a Twitter - reji_mathews
Reply | Threaded
Open this post in threaded view
|

Re: JSONPath error in Content based router

Claus Ibsen-2
Hi

Smells like you data is streaming and can only be read once. And so
when the data is < 20 then the content based router is evaluating 2
times, and the 2nd time for < 20 the data cannot be re-read.

See more at
https://camel.apache.org/manual/latest/stream-caching.html

On Fri, Jul 10, 2020 at 8:30 PM Reji Mathews <[hidden email]> wrote:

>
> I have a route like below
>
>  <route customId="false" id="route360">
>         <from uri="jetty:http://0.0.0.0:8081/branch?httpMethodRestrict=PUT
> "/>
>         <onException id="onException172" useOriginalMessage="true">
>             <exception>java.lang.Exception</exception>
>             <process id="process755"/>
>             <log id="log656" loggingLevel="ERROR" message="${exception}"/>
>             <to id="to509" pattern="InOnly"
> uri="seda:exception_reporters?multipleConsumers=true"/>
>             <process id="process756"/>
>         </onException>
>         <log id="log657" message="Received http payload : ${body}"/>
>         <process id="process757"/>
>         <process id="process758"/>
>         <process id="process759"/>
>         <choice id="choice15">
>             <when id="when37">
>                 <jsonpath
> suppressExceptions="false">$.[?(@.age&gt;20)]</jsonpath>
>                 <to id="to510"
> uri="direct:429552d4-3d87-3666-bd8d-a0db589044f3"/>
>             </when>
>             <when id="when38">
>                 <jsonpath
> suppressExceptions="false">$.[?(@.age&lt;20)]</jsonpath>
>                 <to id="to511"
> uri="direct:62eb1a9e-5720-3b67-8e70-8e00701a866e"/>
>             </when>
>             <otherwise id="otherwise7">
>                 <to id="to512"
> uri="direct:cdf1dcb8-4228-3117-a220-cdc00647a5d5"/>
>             </otherwise>
>         </choice>
>     </route>
>
>
> And I am using test payload as below
>
> {
> "age" : 12
> }
>
> When the value of age is > 20, my filters work fine. But when it is less
> than 20, I get following error
>
> 14:23:13.305 [qtp1747371038-41] ERROR
> com.huawei.camel.core.route.RouteErrorHandler - Error has occurred:
> com.jayway.jsonpath.InvalidPathException: Filter: [?] can not be applied to
> primitives. Current context is:
> 14:23:13.306 [qtp1747371038-41] ERROR route360 -
> org.apache.camel.ExpressionEvaluationException:
> com.jayway.jsonpath.InvalidPathException: Filter: [?] can not be applied to
> primitives. Current context is:
> 14:23:13.310 [Camel (c01d8372-a93c-3b39-a961-57c58cf51a6b) thread #265 -
> seda://exception_reporters] INFO  route361 - creating entry in error table
> {"error_message":"com.jayway.jsonpath.InvalidPathException: Filter: [?] can
> not be applied to primitives. Current context is:
> ","error_code":"APIC.8000"}
>
> Any idea?
>
> Regards
> Reji Mathews



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2
Reply | Threaded
Open this post in threaded view
|

Re: JSONPath error in Content based router

contactreji
Oh! that's interesting. Thanks for the clue!

On Fri, Jul 17, 2020 at 4:36 AM Claus Ibsen <[hidden email]> wrote:

> Hi
>
> Smells like you data is streaming and can only be read once. And so
> when the data is < 20 then the content based router is evaluating 2
> times, and the 2nd time for < 20 the data cannot be re-read.
>
> See more at
> https://camel.apache.org/manual/latest/stream-caching.html
>
> On Fri, Jul 10, 2020 at 8:30 PM Reji Mathews <[hidden email]>
> wrote:
> >
> > I have a route like below
> >
> >  <route customId="false" id="route360">
> >         <from uri="jetty:
> http://0.0.0.0:8081/branch?httpMethodRestrict=PUT
> > "/>
> >         <onException id="onException172" useOriginalMessage="true">
> >             <exception>java.lang.Exception</exception>
> >             <process id="process755"/>
> >             <log id="log656" loggingLevel="ERROR"
> message="${exception}"/>
> >             <to id="to509" pattern="InOnly"
> > uri="seda:exception_reporters?multipleConsumers=true"/>
> >             <process id="process756"/>
> >         </onException>
> >         <log id="log657" message="Received http payload : ${body}"/>
> >         <process id="process757"/>
> >         <process id="process758"/>
> >         <process id="process759"/>
> >         <choice id="choice15">
> >             <when id="when37">
> >                 <jsonpath
> > suppressExceptions="false">$.[?(@.age&gt;20)]</jsonpath>
> >                 <to id="to510"
> > uri="direct:429552d4-3d87-3666-bd8d-a0db589044f3"/>
> >             </when>
> >             <when id="when38">
> >                 <jsonpath
> > suppressExceptions="false">$.[?(@.age&lt;20)]</jsonpath>
> >                 <to id="to511"
> > uri="direct:62eb1a9e-5720-3b67-8e70-8e00701a866e"/>
> >             </when>
> >             <otherwise id="otherwise7">
> >                 <to id="to512"
> > uri="direct:cdf1dcb8-4228-3117-a220-cdc00647a5d5"/>
> >             </otherwise>
> >         </choice>
> >     </route>
> >
> >
> > And I am using test payload as below
> >
> > {
> > "age" : 12
> > }
> >
> > When the value of age is > 20, my filters work fine. But when it is less
> > than 20, I get following error
> >
> > 14:23:13.305 [qtp1747371038-41] ERROR
> > com.huawei.camel.core.route.RouteErrorHandler - Error has occurred:
> > com.jayway.jsonpath.InvalidPathException: Filter: [?] can not be applied
> to
> > primitives. Current context is:
> > 14:23:13.306 [qtp1747371038-41] ERROR route360 -
> > org.apache.camel.ExpressionEvaluationException:
> > com.jayway.jsonpath.InvalidPathException: Filter: [?] can not be applied
> to
> > primitives. Current context is:
> > 14:23:13.310 [Camel (c01d8372-a93c-3b39-a961-57c58cf51a6b) thread #265 -
> > seda://exception_reporters] INFO  route361 - creating entry in error
> table
> > {"error_message":"com.jayway.jsonpath.InvalidPathException: Filter: [?]
> can
> > not be applied to primitives. Current context is:
> > ","error_code":"APIC.8000"}
> >
> > Any idea?
> >
> > Regards
> > Reji Mathews
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>
Reji Mathews Sr. Engineer - Middleware Integrations / SOA ( Open Source - Apache Camel & Jboss Fuse ESB | Mule ESB ) LinkedIn - http://in.linkedin.com/pub/reji-mathews/31/9a2/40a Twitter - reji_mathews