首页 > 解决方案 > 使用 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();
    }

这是路由传入请求的正确方法吗?还是有更好的变种?

标签: javaspring-bootapache-camelcxfrs

解决方案


推荐阅读