Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Name

Default Value

Description

throwException

true

Camel 2.0: Option to disable throwing the HttpOperationFailedException in case of failed responses from the remote server. This allows you to get all responses regardles of the HTTP status code.

httpBindingRef

null

Reference to a org.apache.camel.component.http.HttpBinding in the Registry.

username

null

Username for basic http authentication.

password

null

Password for basic http authentication.

httpClientConfigurerRef

null

Reference to a org.apache.camel.component.http.HttpClientConfigurer in the Registry.

httpClient.XXX

null

Setting options on the HttpClientParams. For instance httpClient.soTimeout(5000) will set the SO_TIMEOUT to 5 seconds.

...

  • response code is between 100..299 then Camel regard it as a success response
  • response code is between 300..399 then Camel regard it as a redirection was returned and will throw a HttpOperationFailedException with the information
  • response code is 400+ then Camel regard it as a external server failure and will throw a HttpOperationFailedException with the information
Tip
titlethrowException

The option throwException can be set to false to prevent the HttpOperationFailedException to be thrown for failed response codes. This allows you to get any response from the remote server.
There is a sample below demonstrating this.

HttpOperationFailedException

...

Code Block
java
java
   Exchange exchange = template.send("http://www.google.com/search", new Processor() {
            public void process(Exchange exchange) throws Exception {
                exchange.getIn().setHeader(HttpProducer.QUERY, constant("hl=en&q=activemq"));
            }
   });
   Message out = exchange.getOut();
   int responseCode = out.getHeader(HttpProducer.HTTP_RESPONSE_CODE, Integer.class);

Using throwException=false to get any response back

Available as of Camel 2.0
In the route below we want to route a message that we enrich with data returned from a remote HTTP call. As we want any response from the remote server we set the throwException option to false so we get any response in the AggregationStrategy. As the code is based on an unit test that simulates a http status code 404, there is some assertion code etc.

Wiki Markup
{snippet:id=e1|lang=java|url=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettySimplifiedHandle404Test.java}

Advanced Usage

If you need more control over the http producer you should use the HttpComponent where you can set various classes to give you custom behavior.

...