Java – create route on camel using domain

I'm running an instance of Apache camel to proxy requests to another server (depending on the URI) The server camel is running many different domains (e.g. app1.server.com, app2.server.com)

Using jetty and http4, I can proxy requests by doing the following:

from("jetty://http://app.server.com:8080/app1?matchOnUriPrefix=true").to("http4://app1host:8080?bridgeEndpoint=true&throwExceptionOnFailure=false");

from("jetty://http://app.server.com:8080/app2?matchOnUriPrefix=true").to("http4://app2host:8080?bridgeEndpoint=true&throwExceptionOnFailure=false");

Is there any way to create a route based on the domain name? Something like this:

from("jetty://http://app1.server.com:8080?matchOnUriPrefix=true").to("http4://app1host:8080?bridgeEndpoint=true&throwExceptionOnFailure=false");

from("jetty://http://app2.server.com:8080?matchOnUriPrefix=true").to("http4://app2host:8080?bridgeEndpoint=true&throwExceptionOnFailure=false");

thank you very much.

Solution

You can create a content-based router like this( http://camel.apache.org/content-based-router.html )

from("jetty://http://0.0.0.0:8080")
    .choice()
        .when(header("host").contains("app1.server.com"))
            .log("app1.server.com").to(...)
        .when(header("host").contains("app2.server.com"))
            .log("app2.server.com").to(...);
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
分享
二维码
< <上一篇
下一篇>>