java - 使用 apache camel cxf-rs 路由请求的正确方法是什么?
问题描述
我已经为 JAXRSServerFactoryBean 配置了两个 api 接口:
@Bean("rsServer")
public JAXRSServerFactoryBean sfBean(String address){
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setBus(bus);
sf.setAddress(address); // http://localhost:8080/some/path
sf.setProvider(jsonProvider);
List<Object> apiBeans = new ArrayList<>();
// first service
apiBeans.add(applicationContext.getBean(FirstApi.class));
// second service
apiBeans.add(applicationContext.getBean(SecondApi.class));
sf.setServiceBeans(apiBeans);
return sf;
}
在每个 Api 类中都有一个端点:-) 用于 FirstApi.class
-)
用于SecondApi.class/api-one/get-something
/api-two/get-something
我有这些东西的路由器,我应该以某种方式路由传入的请求。
来的请求http://localhost:8080/some/path/api-one/get-something
应该是“第一”服务中的处理。http://localhost:8080/some/path/api-two/get-something
并在“第二”服务中处理来的请求:
@Override
public void configure() {
from("cxfrs:bean:rsServer?bindingStyle=SimpleConsumer")
.choice()
.when(exchange -> exchange.getIn().getHeader(CxfConstants.OPERATION_NAME, String.class)
.equals("firstServiceOperation"))
.bean(firstService, firstServiceOperation)
.when(exchange -> exchange.getIn().getHeader(CxfConstants.OPERATION_NAME, String.class)
.equals("secondServiceOperation"))
.bean(secondService, secondServiceOperation)
.endChoice()
.end();
}
这是路由传入请求的正确方法吗?还是有更好的变种?
解决方案
推荐阅读
- python - 如何根据熊猫中的特定字符串选择实际行及以上?
- webpack - 为什么 Create-React-App 的任何输出构建文件都不包含 __webpack_require__ 函数
- karate - 空手道 - 如何根据特定 json 数组中的多个属性值获取特定属性的值
- javascript - 在反应中显示悬停在特定卡上
- microsoft-graph-api - 在 Graph Explorer 中请求列出根子节点返回空
- sql - 试图列出在西雅图某物业工作的员工的员工姓名和 ID
- python - 为什么 PyOpenGL 生成的位图图像中会出现额外的 RGB 颜色?
- php - PHP SQL数组在foreach循环中重复每个ID而不是一次一个ID
- javascript - 跨文件的打字稿全局变量
- android-studio - 我只输出整数但字符串不输出