Chapter 40. Proxying a Web Service
40.1. Proxying with HTTP
Figure 40.1. Proxy Route with Message in HTTP Format
Alternatives for the consumer endpoint
- Jetty endpoint—is a lightweight Web server. You can use Jetty to handle messages for any HTTP-based protocol, including the commonly-used Web service SOAP/HTTP protocol.
- Camel CXF endpoint in MESSAGE mode—when a Camel CXF endpoint is used in MESSAGE mode, the body of the exchange message is the raw message received from the transport layer (which is HTTP). In other words, the Camel CXF endpoint in MESSAGE mode is equivalent to a Jetty endpoint in the case of HTTP-based protocols.
Consumer endpoint for HTTP
jetty:HttpAddress. To configure the Jetty endpoint to be a proxy for a Web service, use a
HttpAddressvalue that is almost identical to the HTTP address the client connects to, except that Jetty's version of
HttpAddressuses the special hostname,
0.0.0.0(which matches all of the network interfaces on the current machine).
<route> <from uri="jetty:http://0.0.0.0:9093/Customers?matchOnUriPrefix=true"/> ... </route>
http://localhost:9093/Customerswould be accepted, but a request sent to
http://localhost:9093/Customers/Foowould be rejected. By setting
true, however, you enable a kind of wildcarding on the context path, so that any context path prefixed by
Alternatives for the producer endpoint
- Jetty HTTP client endpoint—(recommended) the Jetty library implements a HTTP client. In particular, the Jetty HTTP client features support for
HttpClientthread pools, which means that the Jetty implementation scales particularly well.
- HTTP endpoint—the HTTP endpoint implements a HTTP client based on the
- HTTP4 endpoint—the HTTP endpoint implements a HTTP client based on the
Producer endpoint for HTTP
uriattribute of the
toelement at the end of the route to be the address of the remote Web service, as follows:
<route> ... <to uri="jetty:http://localhost:8083/Customers?bridgeEndpoint=true&throwExceptionOnFailure=false"/> </route>
bridgeEndpointoption, which you can enable on a HTTP producer endpoint to configure the endpoint appropriately for operating in a HTTP-to-HTTP bridge (as is the case in this demonstration). In particular, when
bridgeEndpoint=true, the HTTP endpoint ignores the value of the
Exchange.HTTP_URIheader, using the HTTP address from the endpoint URI instead.
falseensures that any HTTP exceptions are relayed back to the original WS client, instead of being thrown within the route.
Handling message headers
CamelHttp*headers set by the consumer endpoint at the start of the route can affect the behavior of the producer endpoint. For this reason, in a bridge application it is advisable to remove the
CamelHttp*headers before the message reaches the producer endpoint, as follows:
<route> <from uri="jetty:http:..."/> ... <removeHeaders pattern="CamelHttp*"/> <to uri="jetty:http:..."/> </route>
Outgoing HTTP headers
Camelwill be converted into HTTP headers and sent out over the wire by the HTTP producer endpoint. This could have adverse consequences on the behavior of your application, so it is important to be aware of any headers that are set in the exchange object and to remove them, if necessary.