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: response code in http component
Date Mon, 30 Mar 2009 14:48:18 GMT
Hi



On Mon, Mar 30, 2009 at 4:33 PM, Peter Maas <pfmmaas@gmail.com> wrote:
> Hi,
>
> according to the documentation of the HTTP component it should be possible
> to retrieve the response code if the call fails. I fail to grasp how to
> exactly use this.  I wanted to use the enrich pattern to call an external
> http based service to enrich the current message:
>
>                from("file:src/data")
>                        .setHeader("id",
> vpro.xpath("//vpro:schedule/@channel", String.class))
>                        .enrich("direct:couchdb", new AggregationStrategy(){
>                                public Exchange aggregate(Exchange original,
> Exchange resource) {
>                                        Message responseOut =
> resource.getOut();
>                                        int responseCode =
> responseOut.getHeader(HttpConstants.HTTP_RESPONSE_CODE, Integer.class);
>                                        System.out.println(responseCode
+ " "
> + responseOut.getBody(String.class));
>                                        return original;
>                                }
>                        }
>                        )
>                        .to("...")
>
>
> and in the resource route:
>
>                from("direct:couchdb")
>                        .setBody(constant(""))
>                        .setHeader("CamelHttpMethod", constant("GET"))
>                        .setHeader(HttpConstants.HTTP_URI,
> constant(LOCAL_DB).append(header("id")))
>                        .to("http://couchdb");
>
> The executed HTTP GET arrives at the server as I expected, since it doesn't
> know the resource it returns a 404. The 404 is thrown as a
> HttpOperationFailedException which triggers a retry...
>
> I'm probably missing something vital, but would really like a push in the
> right direction here!
Ah since you use a sub route before doing the actual HTTP invocation
you should disable the error handler to avoid it doing a retry
from("direct:crouchdb").errorHandler(noErrorHandler())....

In fact you can configure it as a global to avoid the default error
handler all together.

Its up for debate in Camel 2.0 how the defaults for error handling should be.

We will later start a separate thread for this as a open discussion.
But we would definitly value the community feedback on this one.


>
> thanks in advance,
>
> Peter



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Mime
View raw message