Question

I have a REST Service running in Tomcat server. I created this REST Service using Spring RESTTemplate. So is there a component in CAMEL to use this exposed Web service?

i have used http component. i am aware that we cannot use http component to expose a service. So please let me know which component to use.Here is a detailed description of the problem.

Service created in rest Template runs in a server which you can see in from part of camel code

i use camel to expose this service to another http service and the response of this service is the response from the other service.

so my camel code looks like this:

    from("http://localhost:8080/rest/emp/dummy").to(http://anotherweservice.com")

I get this error.

Failed to create route route1: Route(route1)[[From[]] -> [process[com.routes..... because of uri must be specified and not empty

Was it helpful?

Solution

Have a look at http://camel.apache.org/how-to-use-camel-as-a-http-proxy-between-a-client-and-server.html.

Using the Jetty component, this looks as follows:

from("jetty:http://0.0.0.0:8080/myapp?matchOnUriPrefix=true")
    .log("myapp: httpPath = ${header.CamelHttpPath}")
    .to("jetty:http://localhost:8082/remoteapp?bridgeEndpoint=true&throwExceptionOnFailure=false")

In this example, the request is forwarded to another Jetty Camel endpoint:

from("jetty:http://0.0.0.0:8082/remoteapp?matchOnUriPrefix=true")
     .log("remoteapp: httpPath = ${header.CamelHttpPath}")
     .setBody(simple("${header.CamelHttpPath}"));

The HTTP path /hello/world is transfered to the endpoint, as can be seen when the service is invoked with http://localhost:8080/myapp/hello/world. In this case the body /hello/world is returned. And in the log it says:

INFO  myapp: httpPath = /hello/world
INFO  remoteapp: httpPath = /hello/world
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top