Camel作为REST服务的HTTP代理-如何路由路径和参数?

Camel作为REST服务的HTTP代理-如何路由路径和参数?,rest,servlets,proxy,apache-camel,Rest,Servlets,Proxy,Apache Camel,我尝试使用Apache CAMEL作为一个HTTP代理到一个REST服务,在中间执行一些AUTH,并且有一个看起来像这样的路由(AUTH被删除用于测试目的): 访问Camel Servlet路径时,如下所示: http://CAMELHOST/apiwrapper/node http://CAMELHOST/apiwrapper/node/stuff/blah?etc=t 等等。。。我想将这些信息传递到: http://HOST/BASEPATH/node http://HOST/BASEPA

我尝试使用Apache CAMEL作为一个HTTP代理到一个REST服务,在中间执行一些AUTH,并且有一个看起来像这样的路由(AUTH被删除用于测试目的):

访问Camel Servlet路径时,如下所示:

http://CAMELHOST/apiwrapper/node
http://CAMELHOST/apiwrapper/node/stuff/blah?etc=t
等等。。。我想将这些信息传递到:

http://HOST/BASEPATH/node
http://HOST/BASEPATH/node/stuff/blah?etc=t
但我当前的路由配置只是将请求发送到

http://HOST/BASEPATH
不附加任何我需要附加的path/url参数。如果我关闭bridgeEndpoint,那么当路由到达.to(HTTP)部分时就会抛出错误


如何配置此路由以映射这些路由?

最后,我无法在配置中找到一种简单的方法,因此我在http端点的输入和路由末尾之间添加了一个bean,该端点进行了一些转换并添加了基本身份验证,如下所示:

  // Get all of the request path, including url params, after the context path of this camel app
  HttpServletRequest request = exchange.getIn().getHeader(Exchange.HTTP_SERVLET_REQUEST, HttpServletRequest.class);
  // Use the code below to get the request path instead of .getPathInfo(), as getPathInfo ignores url params
  String path = request.getRequestURI().substring(request.getContextPath().length());

  // Override the dummy host with the wrapped host
  exchange.getIn().setHeader(Exchange.HTTP_URI, "http://baseurl");
  // Override the path that was in the exchange before
  exchange.getIn().setHeader(Exchange.HTTP_PATH, path);
  // Finally override the request params
  exchange.getIn().setHeader(Exchange.HTTP_QUERY, request.getQueryString());

  // Set basic auth headers
  String basicAuth = String.format("%s:%s", "USERNAME", "PASSWORD");
  StringBuilder authHeader = new StringBuilder("Basic ");
  authHeader.append(Base64.encodeBase64String(basicAuth.getBytes(Charsets.UTF_8)));
  exchange.getIn().setHeader("Authorization", authHeader.toString());
我的路线是这样的,有一个dummyhost和参数:

from("servlet:apiwrapper?matchOnUriPrefix=true")
.to("bean:httpHeaderSetter?method=setHttpHeaders")
.to("http://HOST/BASEPATH?throwExceptionOnFailure=false&httpClient.authenticationPreemptive=true");
from("servlet:apiwrapper?matchOnUriPrefix=true")
.to("bean:httpHeaderSetter?method=setHttpHeaders")
.to("http://HOST/BASEPATH?throwExceptionOnFailure=false&httpClient.authenticationPreemptive=true");