Question

This is using Camel 2.5.0

The route is pretty simple. The starting point is a jetty://.../web/service/path and the end of the route is an http://real-webservice-host/web/service/path. The problem I'm having is that while the remote web service gets called, it doesn't get called correctly.

Specifically, the Content-Type header does not get set when I use the bridgeEndpoint=true option on the http component. This results in my remote JAX-RS service reporting a Error 415 Unsupported Media Type. If I do not set the bridgeEndpoint option on the http component, then I have to go and set up the host header to point to the host that I've already declared in the http endpoint URI.

What I'd like to be able to do would be:

from("jetty://host/path?matchOnUriPrefix=true").to("http://jaxrs-host/path")

And to have the HTTP method, headers, and body proxied to the remote endpoint.

I have a workaround for this using a CXFRS bean that proxies the request:

@Path("/api/address")
class AddressServiceProxy {

  @BeanProperty
  var targetUrl : String = _

  @POST
  @Consumes(Array("application/xml"))
  @Produces(Array("application/xml"))
  @Path("/validation")
  def validate(in: InputStream) = {
    WebClient.create(targetUrl).post(in, classOf[String])
  }

}

And in the spring config:

<bean id="addressServiceProxy" class="beans.AddressServiceProxy">
    <property name="targetUrl" 
              value="http://localhost:9000/api/address/validation"/>
</bean>

And in the route:

from("jetty://http://0.0.0.0:8080/api/address?matchOnUriPrefix=true")
.to("cxfbean:addressServiceProxy")

This approach works, but requires me to duplicate the JAX-RS endpoint to which I am proxying. Is this the best way to go about it, or is there a better approach?

Was it helpful?

Solution

It's a bug of camel-http, I just created a JIRA for it and will commit a quick fix for it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top