Java – how to pass jax-rs proxy using Apache camel implementation?

This is using camel 2.5 0

The route is simple The starting point is a wharf: / /... / Web / service / path, and the end of the route is http://real-webservice-host/web/service/path. The problem I encounter is that when a remote web service is called, it will not be called correctly

Specifically, when I use the bridgeendpoint = true option on the HTTP component, the content type header will not be set This caused my remote Jax - RS service to report error 415 unsupported media types If I do not set the bridgeendpoint option on the HTTP component, I must set the host header to point to the host I have declared in the HTTP endpoint URI

What I hope to do is:

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

And make HTTP method, header and body proxy to remote endpoint

I have a solution to use the cxfrs bean requested by the proxy:

@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 configured in spring:

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

And on the route:

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

This method works, but requires me to copy my proxy Jax - RS endpoint Is this the best way, or is there a better way?

Solution

This is a bug in camel http. I just created a JIRA for it and will fix it quickly

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>