Maybe you need stream caching
http://camel.apache.org/why-is-my-message-body-empty.html

On Fri, May 20, 2016 at 1:12 PM, grzechol
<grzegorz.olszew...@outlook.com> wrote:
> Hi guys,
>
> I have a problem injecting multiple @JsonPath arguments using bean binding.
>
> Here is my sample json:
> {"key1":"val1","key2":"val2"}
>
> My bean method processing that JSON:
> @Handler
> public void process(@JsonPath("$.key1") String value1, @JsonPath("$.key2")
> String value2) {
>     System.out.println("Got key1: " + value1);
>     System.out.println("Got key2: " + value2);
> }
>
> And my route:
> <route id="test">
>     <from uri="timer://foo?period=0&amp;repeatCount=1" />
>     <to uri="http4:localhost:8084/example_json" />
>     <to uri="bean:myBean" />
> </route>
>
> I got the following exception message: "Property ['key2'] not found in path
> $" (stacktrace: http://pastebin.com/TMrK4wC0)
>
> Everything works perfectly fine when I use only one @JsonPath method
> argument, key1 or key2 it doesn't matter. But it doesn't work with two
> arguments, regardless of their order. I always receive error message taht
> the second parameter is not found in path "$" regardless which one is second
> - key1 or key2.
>
> The weird thing is it works perfectly fine with JSON read from filesystem
> instead of http service:
>
> <route id="test">
>     <from uri="file:/tmp/example?noop=true" />
>     <to uri="bean:myBean" />
> </route>
>
> Log messages indicate Camel reads the same file twice to evaluate two
> JsonPath expressions, but I'm not sure it it's true:
>
> 2016.05.20 07:29:04.600 DEBUG Camel (camel-1) thread #0 -
> file:///tmp/example org.apache.camel.component.file.GenericFileConverter -
> Read file /tmp/example/example.json (no charset)
> 2016.05.20 07:29:04.607 DEBUG Camel (camel-1) thread #0 -
> file:///tmp/example com.jayway.jsonpath.internal.CompiledPath - Evaluating
> path: $['key1']
> Got key1: val1
> 2016.05.20 07:29:57.518 DEBUG Camel (camel-1) thread #0 -
> file:///tmp/example org.apache.camel.component.file.GenericFileConverter -
> Read file /tmp/example/example.json (no charset)
> 2016.05.20 07:29:57.525 DEBUG Camel (camel-1) thread #0 -
> file:///tmp/example com.jayway.jsonpath.internal.CompiledPath - Evaluating
> path: $['key2']
> Got key2: val2
>
> I'm using Apache Camel 2.17.1 with Jayway Json Path 2.0.0.
>
> BR,
> Grzegorz
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Inject-multiple-JsonPath-parameters-to-bean-method-tp5782825.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Reply via email to