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: camel-http keeps throwing exception regardless of throwExceptionOnFailure value
Date Wed, 11 Sep 2013 13:33:36 GMT
Try setting the option on HTTP_URI instead as its an option for Camel
and not the remote web server

On Wed, Sep 11, 2013 at 3:00 PM, roger_rabbit <roger_rabbit@gmx.fr> wrote:
> Hi,
>
> I need to get the status code of a http/POST call that may fail, but that
> should never stop the route, but log the errors instead.
> But whatever solution I try, my route keeps failing as soon as I have a code
> 400+, and am never able to manage the return code:
>
> /Failed delivery for (MessageId: topic_mmh.test.in_ID_myHost on ExchangeId:
> someId). On delivery attempt: 0 caught:
> org.apache.camel.component.http.HttpOperationFailedException: HTTP operation
> failed invoking http://www.google.fr/ju?throwExceptionOnFailure=false with
> statusCode: 405/
>
> I have tried it two ways :
> According to  camel-http doc <http://camel.apache.org/http.html>   :
>         from("direct:in")
>                         .process(fillInBodyWithHttpPostData)
>                         .setHeader(Exchange.HTTP_METHOD, constant("POST"))
>                         .setHeader(Exchange.HTTP_URI, constant("http://www.google.fr/ju"))
//
> error 405
>                         .setHeader(Exchange.HTTP_QUERY,
> constant("throwExceptionOnFailure=false"))
>                         .setHeader(Exchange.CONTENT_TYPE, constant("application/xml"))
>                         .enrich("http://dummyhost", new AggregationStrategy() {
>                                                     public Exchange aggregate(Exchange
original, Exchange resource) {
>                                                         Integer code =
> resource.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class);
>                                                         if(code.intValue()==405){
>                                                                 logUtils.log(LoggingLevel.DEBUG,
"erreur
> 405",runInDebugMode);
>                                                         }
>                                                         return resource;
>                                                     }
>                                                 }).to("mock:result");
>
>
> An another way I tried before reading the doc:
>
>   from("direct:in")
>                         .process(fillInBodyWithHttpPostData)
>                         .setHeader(Exchange.HTTP_METHOD, constant("POST"))
>                         .setHeader(Exchange.HTTP_URI, constant("http://www.google.fr/ju"))
//
> error 405
>                         .setHeader(Exchange.HTTP_QUERY,
> constant("throwExceptionOnFailure=false"))
>                         .setHeader(Exchange.CONTENT_TYPE, constant("application/xml"))
>                         .enrich("http://dummyhost")
>                         .process(processHttpReturnCode);
>
>
>      // with processorCode
>    // ...
>                         final Message in = exchange.getIn();
>                         int responseCode = in.getHeader(Exchange.HTTP_RESPONSE_CODE,
> Integer.class);
>                         switch(responseCode){
>                         case HttpStatus.SC_ACCEPTED :
>                         case HttpStatus.SC_CREATED :
>                                 logUtils.log(LoggingLevel.DEBUG,"Return Code ok  : "
+
> Integer.toString(responseCode),runInDebugMode);break;
>                           default :
>                                 logUtils.log(LoggingLevel.ERROR,"Return code KO : " +
> Integer.toString(responseCode),runInDebugMode);break;
>                         }
>
>    // ...
>
> If any of you have a tip here, or could point out my mistake, she/he is
> welcome!
>
> Thanks in advance
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-http-keeps-throwing-exception-regardless-of-throwExceptionOnFailure-value-tp5739143.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Mime
View raw message