java - 使用 apache camel 将 url 路由到外部 rest 控制器
问题描述
有没有办法将所有请求路由到特定的 URI 到另一个项目的休息控制器?考虑下面的代码:
@Component
public class CamelSportsRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
restConfiguration()
.component("servlet")
.bindingMode(RestBindingMode.auto);
rest().path("/hello").get().route()
.toD("localhost:9080/hello");
}
}
我想将所有请求路由/hello
到另一个项目休息控制器端点:localhost:9080/hello
但没有 XML 就不可能。
解决方案
请参阅 jetty 和 undertown 组件的 matchOnUriPrefix 和 HTTP 组件的 bridgeEndpoint 选项。
这就是你需要的:
from("undertow:http://localhost:8080/hello?matchOnUriPrefix=true")
.to("http4://localhost:8081/hello?bridgeEndpoint=true");
另请参阅有关更多详细信息的另一个答案https://stackoverflow.com/a/67893371/11052487
推荐阅读
- python - TypeError:不支持的操作数类型
- java - Java Logic 根据收到的代码更新字符串
- c++ - 初始化 Eigen::Map 的 std::array
- javascript - “debug = require('debug')('api:server')”是什么意思
- azure - 天蓝色 ARM 模板。参数 LinuxFxVersion 的值无效
- c# - ASP.NET MVC TempData 的间歇性结果 - 有时它会失去它的价值
- c - 使用lldb调试我的代码时如何输入值
- docker - GCP:无法从 ubuntu/debian VM 实例上的 GCP 私有容器注册表中提取 docker 映像
- typescript - 为什么从两个打字稿文件访问相同的类数据会在打字稿中产生不同的结果?如何解决?
- javascript - 在运行时动态更新 jQuery timepicker minTime