0

Is it possible to route all of request to another server directly? For example route all of this project specific rest endpoint localhost:8080/get-something to another project endpoint like this: someIp:8081/get-something2 . something like this:

from("localhost:8080/get-something")
.to("someIp:8081/get-something2")

or this:

rest()
            .path("/get-something")
            .get()
                .route()
.to("someIp:8081/get-something2")

I've tried too many ways but I cant!

primElite
  • 11
  • 2

2 Answers2

0

I think you want to use a WireTap, just going by your description.

So you’ll do something like

’’’ from("localhost:8080/get-something") . wiretap(“direct:endpoint1”) // will receive exchange . wiretap(“direct:endpoint2”) // will receive exchange .to(ACTUAL_DESTINATION); // will receive exchange … ;

’’’

Then

’’’ from(“direct:endpoint1”) .to(MY_SERVER1);

from(“direct:endpoint2”) .to(MY_SERVER2); ’’’

Something to note though, is that these are completely separate messages (think a carbon copy) only if you specify a custom processor via the onPrepareRef property

0

You could use a http based component (jetty or undertow) as consumer (from) with matchOnUriPrefix=true option and then send it to an http component using bridgeEndpoint=true option.

Example:

from("undertow:http://localhost:8080/?matchOnUriPrefix=true")
.to("http4://google.com/?bridgeEndpoint=true");

That way any request sent to localhost:8080/ will be forwarded to google.com/

Try http://localhost:8080/ in your browser and you will get google web page.

Try http://localhost:8080/search?q=camel in your browser and you will get response for "camel" search.

In your case you could do:

from("undertow:http://localhost:8080/?matchOnUriPrefix=true")
.to("http4://localhost:8081/?bridgeEndpoint=true");

Docs: