You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by roger_rabbit <ro...@gmx.fr> on 2013/09/11 15:00:09 UTC

camel-http keeps throwing exception regardless of throwExceptionOnFailure value

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.

Re: camel-http keeps throwing exception regardless of throwExceptionOnFailure value

Posted by roger_rabbit <ro...@gmx.fr>.
Yes, that was the right one!

Now I understand my whole problem... such a subtle but important point!

Thanks a lot, Claus!



--
View this message in context: http://camel.465427.n5.nabble.com/camel-http-keeps-throwing-exception-regardless-of-throwExceptionOnFailure-value-tp5739143p5739173.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-http keeps throwing exception regardless of throwExceptionOnFailure value

Posted by Claus Ibsen <cl...@gmail.com>.
Ah you need to set it on the *real* endpoint

    .enrich("http://dummyhost?throwExceptionOnFailure=false")

As this options is only applicable there, and not possible to set
using those HTTP headers.

On Wed, Sep 11, 2013 at 4:08 PM, roger_rabbit <ro...@gmx.fr> wrote:
> Claus,
>
> thanks for the tip; which sounded very like the right one until I tried
> it... and it didn't work
>
> ..
>                         // .setHeader(Exchange.HTTP_QUERY,
> constant("throwExceptionOnFailure=false"))
>                         .setHeader(Exchange.HTTP_URI,
> constant("http://www.google.fr/xv?throwExceptionOnFailure=false"))
> ...
>
> But I still receive an exception...
>
> caught: org.apache.camel.component.http.HttpOperationFailedException: HTTP
> operation failed invoking
> http://www.google.fr/xv?throwExceptionOnFailure=false with statusCode: 404
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-http-keeps-throwing-exception-regardless-of-throwExceptionOnFailure-value-tp5739143p5739153.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

Re: camel-http keeps throwing exception regardless of throwExceptionOnFailure value

Posted by roger_rabbit <ro...@gmx.fr>.
Claus,

thanks for the tip; which sounded very like the right one until I tried
it... and it didn't work

..
                        // .setHeader(Exchange.HTTP_QUERY,
constant("throwExceptionOnFailure=false"))
                        .setHeader(Exchange.HTTP_URI,
constant("http://www.google.fr/xv?throwExceptionOnFailure=false"))
...

But I still receive an exception...

caught: org.apache.camel.component.http.HttpOperationFailedException: HTTP
operation failed invoking
http://www.google.fr/xv?throwExceptionOnFailure=false with statusCode: 404





--
View this message in context: http://camel.465427.n5.nabble.com/camel-http-keeps-throwing-exception-regardless-of-throwExceptionOnFailure-value-tp5739143p5739153.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel-http keeps throwing exception regardless of throwExceptionOnFailure value

Posted by Claus Ibsen <cl...@gmail.com>.
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 <ro...@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