You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by koritoss <ko...@gmail.com> on 2014/06/17 00:43:29 UTC
Disable auto redirect
Using camel 2.12.1.
I am using timer component to send head request to a server uri as below.
RouteBuilder builder = new RouteBuilder() {
@Override
public void configure() {
from("timer://" + serverUrl + "?fixedRate=true&delay=0&period=" +
period).routeId(routeId)
.onException(HttpOperationFailedException.class)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
LOGGER.log(Level.INFO, "HttpOperationFailedException
thrown);
}
})
.end()
.setHeader(Exchange.HTTP_METHOD, constant("HEAD"))
.to(serverUrl + "?httpClient.soTimeout=" + httpReadTimeOut +
"&throwExceptionOnFailure=true")
.process(new StatusProcessor(serverUrl, facadeMonitorDao));
}
};
According to http://camel.apache.org/http.html,
- Response code is in the range 100..299, Camel regards it as a success
response.
- Response code is in the range 300..399, Camel regards it as a redirection
response and will throw a HttpOperationFailedException with the information.
- Response code is 400+, Camel regards it as an external server failure and
will throw a HttpOperationFailedException with the information.
Tracing the route,
- I see HEAD request is sent to server,
- Server responds with 302 response code which is "Moved Temporarily"
- However, the HttpOperationFailedException is not thrown even when i set
the throwExceptionOnFailure=true
- Another HEAD request is set to redirect location
See below log trace message:
22:17:40,594 DEBUG [org.apache.camel.component.http.HttpProducer] thread #2
- timer://https://myserver.org/myserver) Executing http HEAD method
22:17:40,673 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
"HEAD /myserver HTTP/1.1[\r][\n]"
22:17:40,673 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
"user-agent: GIS ServerManager-PingService[\r][\n]"
22:17:40,674 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
"firedTime: Mon Jun 16 22:17:40 UTC 2014[\r][\n]"
22:17:40,674 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
"breadcrumbId: ID-nites-gis-dev-net-48451-1402955026229-3-9[\r][\n]"
22:17:40,674 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
"Host: myserver.org[\r][\n]"
22:17:40,675 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
"[\r][\n]"
22:17:41,724 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
"HTTP/1.1 302 Moved Temporarily[\r][\n]"
22:17:41,724 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
"HTTP/1.1 302 Moved Temporarily[\r][\n]"
22:17:41,725 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
"Date: Mon, 16 Jun 2014 22:17:47 GMT[\r][\n]"
22:17:41,725 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
"Location: /myserver/index.html[\r][\n]"
22:17:41,725 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
"Connection: close[\r][\n]"
22:17:41,725 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
"Content-Type: text/plain; charset=UTF-8[\r][\n]"
22:17:41,726 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
"[\r][\n]"
22:17:41,804 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
"HEAD /myserver/index.html HTTP/1.1[\r][\n]"
22:17:41,804 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
"user-agent: GIS ServerManager-PingService[\r][\n]"
22:17:41,804 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
"firedTime: Mon Jun 16 22:17:40 UTC 2014[\r][\n]"
22:17:41,804 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
"breadcrumbId: ID-nites-gis-dev-net-48451-1402955026229-3-9[\r][\n]"
22:17:41,804 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
"Host: myserver.org[\r][\n]"
22:17:41,805 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
"[\r][\n]"
22:17:42,475 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
"HTTP/1.1 200 OK[\r][\n]"
22:17:42,475 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
"HTTP/1.1 200 OK[\r][\n]"
22:17:42,476 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
"Date: Mon, 16 Jun 2014 22:17:48 GMT[\r][\n]"
22:17:42,476 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
"Last-Modified: Thu, 19 Sep 2013 03:42:20 GMT[\r][\n]"
22:17:42,476 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
"Content-Type: text/html;charset=UTF-8[\r][\n]"
22:17:42,476 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
"Content-Length: 697[\r][\n]"
22:17:42,476 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
"Connection: close[\r][\n]"
22:17:42,476 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
"[\r][\n]"
22:17:42,477 DEBUG [org.apache.camel.component.http.HttpProducer] thread #2
- timer://https://myserver.org/myserver) Http responseCode: 200
What I would like to do is, prevent this auto redirect behavior by catching
the exception but it fails to catch that HttpOperationFailedException.
Please help.
--
View this message in context: http://camel.465427.n5.nabble.com/Disable-auto-redirect-tp5752391.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Disable auto redirect
Posted by "kraythe ." <kr...@gmail.com>.
Looking at the route the exception will be caught but you haven't marked it
as handled so after it runs your onException call, the exception will be
propagated back to the caller, which is a timer component. Im not sure what
the timer component will do with an exception. Id have to check the
documentation. If you want to mask it then add .handled(true) after the
onException() and before the processor.
*Robert Simmons Jr. MSc. - Lead Java Architect @ EA*
*Author of: Hardcore Java (2003) and Maintainable Java (2012)*
*LinkedIn: **http://www.linkedin.com/pub/robert-simmons/40/852/a39
<http://www.linkedin.com/pub/robert-simmons/40/852/a39>*
On Mon, Jun 16, 2014 at 5:43 PM, koritoss <ko...@gmail.com> wrote:
> Using camel 2.12.1.
>
> I am using timer component to send head request to a server uri as below.
>
> RouteBuilder builder = new RouteBuilder() {
> @Override
> public void configure() {
> from("timer://" + serverUrl + "?fixedRate=true&delay=0&period=" +
> period).routeId(routeId)
> .onException(HttpOperationFailedException.class)
> .process(new Processor() {
> public void process(Exchange exchange) throws Exception {
> LOGGER.log(Level.INFO, "HttpOperationFailedException
> thrown);
> }
> })
> .end()
> .setHeader(Exchange.HTTP_METHOD, constant("HEAD"))
> .to(serverUrl + "?httpClient.soTimeout=" + httpReadTimeOut +
> "&throwExceptionOnFailure=true")
> .process(new StatusProcessor(serverUrl, facadeMonitorDao));
> }
> };
>
> According to http://camel.apache.org/http.html,
> - Response code is in the range 100..299, Camel regards it as a success
> response.
> - Response code is in the range 300..399, Camel regards it as a redirection
> response and will throw a HttpOperationFailedException with the
> information.
> - Response code is 400+, Camel regards it as an external server failure and
> will throw a HttpOperationFailedException with the information.
>
> Tracing the route,
> - I see HEAD request is sent to server,
> - Server responds with 302 response code which is "Moved Temporarily"
> - However, the HttpOperationFailedException is not thrown even when i set
> the throwExceptionOnFailure=true
> - Another HEAD request is set to redirect location
>
> See below log trace message:
>
> 22:17:40,594 DEBUG [org.apache.camel.component.http.HttpProducer] thread #2
> - timer://https://myserver.org/myserver) Executing http HEAD method
> 22:17:40,673 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
> "HEAD /myserver HTTP/1.1[\r][\n]"
> 22:17:40,673 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
> "user-agent: GIS ServerManager-PingService[\r][\n]"
> 22:17:40,674 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
> "firedTime: Mon Jun 16 22:17:40 UTC 2014[\r][\n]"
> 22:17:40,674 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
> "breadcrumbId: ID-nites-gis-dev-net-48451-1402955026229-3-9[\r][\n]"
> 22:17:40,674 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
> "Host: myserver.org[\r][\n]"
> 22:17:40,675 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
> "[\r][\n]"
>
> 22:17:41,724 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
> "HTTP/1.1 302 Moved Temporarily[\r][\n]"
> 22:17:41,724 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
> "HTTP/1.1 302 Moved Temporarily[\r][\n]"
> 22:17:41,725 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
> "Date: Mon, 16 Jun 2014 22:17:47 GMT[\r][\n]"
> 22:17:41,725 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
> "Location: /myserver/index.html[\r][\n]"
> 22:17:41,725 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
> "Connection: close[\r][\n]"
> 22:17:41,725 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
> "Content-Type: text/plain; charset=UTF-8[\r][\n]"
> 22:17:41,726 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
> "[\r][\n]"
>
> 22:17:41,804 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
> "HEAD /myserver/index.html HTTP/1.1[\r][\n]"
> 22:17:41,804 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
> "user-agent: GIS ServerManager-PingService[\r][\n]"
> 22:17:41,804 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
> "firedTime: Mon Jun 16 22:17:40 UTC 2014[\r][\n]"
> 22:17:41,804 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
> "breadcrumbId: ID-nites-gis-dev-net-48451-1402955026229-3-9[\r][\n]"
> 22:17:41,804 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
> "Host: myserver.org[\r][\n]"
> 22:17:41,805 DEBUG thread #2 - timer://https://myserver.org/myserver) >>
> "[\r][\n]"
>
> 22:17:42,475 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
> "HTTP/1.1 200 OK[\r][\n]"
> 22:17:42,475 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
> "HTTP/1.1 200 OK[\r][\n]"
> 22:17:42,476 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
> "Date: Mon, 16 Jun 2014 22:17:48 GMT[\r][\n]"
> 22:17:42,476 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
> "Last-Modified: Thu, 19 Sep 2013 03:42:20 GMT[\r][\n]"
> 22:17:42,476 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
> "Content-Type: text/html;charset=UTF-8[\r][\n]"
> 22:17:42,476 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
> "Content-Length: 697[\r][\n]"
> 22:17:42,476 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
> "Connection: close[\r][\n]"
> 22:17:42,476 DEBUG thread #2 - timer://https://myserver.org/myserver) <<
> "[\r][\n]"
> 22:17:42,477 DEBUG [org.apache.camel.component.http.HttpProducer] thread #2
> - timer://https://myserver.org/myserver) Http responseCode: 200
>
> What I would like to do is, prevent this auto redirect behavior by catching
> the exception but it fails to catch that HttpOperationFailedException.
> Please help.
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Disable-auto-redirect-tp5752391.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Re: Disable auto redirect
Posted by Willem Jiang <wi...@gmail.com>.
I just wrote a simple unit test[1] to verify the issue that you find, the test passed in camel master branch.
[1]http://git-wip-us.apache.org/repos/asf/camel/diff/b6a87991
--
Willem Jiang
Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang
Weibo: 姜宁willem
On June 18, 2014 at 12:37:34 AM, koritoss (koritoss@gmail.com) wrote:
> Thanks for the reply.
>
> I doubt the onException code is executed when 300~399 response code is
> returned since I do not see the log message below.
>
> .onException(HttpOperationFailedException.class)
> .process(new Processor() {
> public void process(Exchange exchange) throws Exception {
> LOGGER.log(Level.INFO, "HttpOperationFailedException
> thrown);
> }
> })
>
> One thing to note is that I do see the log messsage
> "HttpOperationFailedException thrown" when response code 400+ is returned.
>
> I believe handled(true) mask the exception to the caller but it should still
> catch the exception and print out that log message.
>
>
> Is there another way to prevent this auto redirect behavior?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Disable-auto-redirect-tp5752391p5752446.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Re: Disable auto redirect
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
The http client library has some options to turn on|off follow
redirects. Though I am not sure what it does by default.
On Tue, Jun 17, 2014 at 6:37 PM, koritoss <ko...@gmail.com> wrote:
> Thanks for the reply.
>
> I doubt the onException code is executed when 300~399 response code is
> returned since I do not see the log message below.
>
> .onException(HttpOperationFailedException.class)
> .process(new Processor() {
> public void process(Exchange exchange) throws Exception {
> LOGGER.log(Level.INFO, "HttpOperationFailedException
> thrown);
> }
> })
>
> One thing to note is that I do see the log messsage
> "HttpOperationFailedException thrown" when response code 400+ is returned.
>
> I believe handled(true) mask the exception to the caller but it should still
> catch the exception and print out that log message.
>
>
> Is there another way to prevent this auto redirect behavior?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Disable-auto-redirect-tp5752391p5752446.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
hawtio: http://hawt.io/
fabric8: http://fabric8.io/
Re: Disable auto redirect
Posted by koritoss <ko...@gmail.com>.
Thanks for the reply.
I doubt the onException code is executed when 300~399 response code is
returned since I do not see the log message below.
.onException(HttpOperationFailedException.class)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
LOGGER.log(Level.INFO, "HttpOperationFailedException
thrown);
}
})
One thing to note is that I do see the log messsage
"HttpOperationFailedException thrown" when response code 400+ is returned.
I believe handled(true) mask the exception to the caller but it should still
catch the exception and print out that log message.
Is there another way to prevent this auto redirect behavior?
--
View this message in context: http://camel.465427.n5.nabble.com/Disable-auto-redirect-tp5752391p5752446.html
Sent from the Camel - Users mailing list archive at Nabble.com.