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.