我在Apache REST API之前使用Apache Camel,就像智能HTTP代理一樣。我有一個配置文件,可以配置路由並且工作得很好。通過Apache Camel保持請求主機端點
爲了避免複雜性,我將summerize代碼:
camelContext.addRoutes(new RouteBuilder(){
@Override
public void configure() throws Exception {
from("servlet:///v1.3?matchOnUriPrefix=true")
.to("http4://localhost:8080/my-rest-api-v1.3.0?bridgeEndpoint=true&throwExceptionOnFailure=false");
from("servlet:///v1.2?matchOnUriPrefix=true")
.to("http4://localhost:8080/my-rest-api-v1.2.1?bridgeEndpoint=true&throwExceptionOnFailure=false");
}
});
我的問題是端點服務器上。當我從我的HttpServletRequest中檢索請求URL時,它給了我一個「http://localhost:8080/my-rest-api-v1.3.0/resources/companies/」而不是「http://my.site.com/my-rest-api」(這是我的代理的URL)。
如何將請求的主機名傳輸到我的端點?
我不知道如何用Apache Camel做到這一點。
好的。它似乎在這裏工作。我在Java工作。你在Groovy工作,還是由Camel指定? –
尼古拉斯,你是對的。簡單的語言不適用於(..)。要構建URI,您必須使用recipientList模式:http://camel.apache.org/how-do-i-use-dynamic-uri-in-to.html。我已經更新了我的答案。 –