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!

thanks in advance,

Peter

Reply via email to