Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.

How to use Camel as a HTTP proxy between a client and server

You may have an existing HTTP service, which you want to use Camel in between as a proxy, between the client and the server.

This can be done using the Jetty component as follows:

  <route>
    <from uri="jetty:http://0.0.0.0:8080/myapp?matchOnUriPrefix=true"/>
    <to uri="jetty:http://realserverhostname:8090/myapp?bridgeEndpoint=true&amp;throwExceptionOnFailure=false"/>
  </route>

In the example above, we expose a HTTP service on localhost (0.0.0.0 means to expose on all network interfaces) port 8080, and using context path "myapp".
The option matchOnUriPrefix is set to true, to match any wildcards in the "myapp" context path. See more details here How do I let Jetty match wildcards.

Then we route to the <to> which is also a jetty endpoint, which sends the requests to the real HTTP server. The bridgeEndpoint option is set to true, to tell Camel that its a bridging from an incoming Jetty service (ie. to act as a HTTP adapter/proxy). The option throwExceptionOnFailure is set to false, to rely back any errors communicating with the real HTTP server directly to the client, without using any Camel Error Handling (ie. no exception is raised from Camel).

You can also use Servlet instead of Jetty, for example:

  <route>
    <from uri="servlet:myapp?matchOnUriPrefix=true"/>
    <to uri="http://realserverhostname:8090/myapp?bridgeEndpoint=true&amp;throwExceptionOnFailure=false"/>
  </route>

More control of url mappings

From Camel 2.11 onwards you can use a custom url rewriter which gives you control of the url mappings. Such as handling situations where the mapping is not identical 1:1 mapping. See more details at the urlRewrite option on HTTP, HTTP4, and Jetty components, and in particular read this page UrlRewrite about the camel-urlrewrite component.

© 2004-2015 The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram