camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Best practice to parse JSON response and retry if error
Date Tue, 22 May 2012 10:03:38 GMT
On Tue, May 22, 2012 at 12:00 PM, Raul Kripalani <raul@fusesource.com> wrote:
> Have you tried encapsulating both the HTTP invocation + the JSON
> unmarshalling behind a direct: endpoint? i.e.
>
> from("direct:doHttpInvocation")
>       .to("http://localhost:8088/?cmd=ls%20/tmp/unlock")
>       .unmarshal().json(JsonLibrary.Jackson, ShellResponse.class);
>
> The default error handler in this new route (DefaultErrorHandler) will
> immediately return the exception to the caller.
>
> From the parent route, you invoke the direct endpoint using:
> .to("direct:doHttpInvocation"). Hence, the two operations become one from
> the viewpoint of the parent route, so it should now cycle over
> "direct:doHttpInvocation" for redeliveries.
>
> Let us know if that worked for you.
>

You would most likely need to disable error handling on the direct
route, then the redelivery will happen
from calling the direct endpoint (eg the route itself).

 from("direct:doHttpInvocation")
       .errorHandler(noErrorHandler())
       .to("http://localhost:8088/?cmd=ls%20/tmp/unlock")
       .unmarshal().json(JsonLibrary.Jackson, ShellResponse.class);



> Regards,
>
> *Raúl Kripalani*
> Principal Consultant | FuseSource Corp.
> raul@fusesource.com | fusesource.com <http://www.fusesource.com/>
> skype: raul.fuse | twitter: @raulvk <http://twitter.com/raulvk>,
> @fusenews<http://twitter.com/fusenews>
>
> <http://twitter.com/fusenews>
>
>
> On 21 May 2012 22:13, Nestor Urquiza <nestor.urquiza@gmail.com> wrote:
>
>> One way to solve this (successfully tested) would be using a bean
>> encapsulating all the logic (http request, unmarshalling, testing for
>> errors):
>> <code>
>> //So we are probably better just building a bean that invokes the http
>> service, analyze the response and throws Exception if error
>>        .setHeader("url",
>> constant("http://localhost:8088/cmd=ls%20/tmp/unlock
>> ")).bean(ShellBeanService.class)
>> </code>
>>
>> I believe a nice feature would be to allow to go to a particular point in
>> the case of a failure. I am unsure how to achieve that though.
>>
>> I would appreciate any feedback on this.
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Best-practice-to-parse-JSON-response-and-retry-if-error-tp5711530p5713181.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>



-- 
Claus Ibsen
-----------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Mime
View raw message