【发布时间】:2016-01-27 16:57:39
【问题描述】:
我目前正在做一个项目,我使用 Apache Camel、CXF 来实现我的 WebService。最重要的是,我使用 Spring Boot(嵌入了 tomcat)。
我为每个 Web 服务版本开发了不同的 CXF 端点,可以通过以下方式访问它们
http://myserver.com/service/V1或http://myserver.com/service/V2。这一切都很好,除非我需要让这些服务在一个 url http://myserver.com/service/CommonVersion 下工作并基于 xpath 将其路由到特定版本。
我真的不知道如何配置,然后将 Web 服务请求从公共入口点发送到特定于版本的入口点。
我想为我的应用程序提供一些设置: cxf-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring" xmlns:cxf="http://camel.apache.org/schema/cxf" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd">
<cxf:cxfEndpoint id="serviceV1"
address="/service/V1" serviceName="s:Service" serviceClass="com.myservice.v1.service" xmlns:s="http://com.myservice/ServiceV1">
<cxf:properties>
<entry key="allowStreaming" value="false" />
</cxf:properties>
</cxf:cxfEndpoint>
<cxf:cxfEndpoint id="serviceV2" address="/service/V2" serviceName="s:Service" serviceClass="com.myservice.v2.service" xmlns:s="http://com.myservice/ServiceV2">
<cxf:properties>
<entry key="allowStreaming" value="false" />
</cxf:properties>
</cxf:cxfEndpoint>
</beans>
为我的 cxf 端点定义的示例路由
@Component
public class ServiceV1 extends SpringRouteBuilder {
public void configure() throws Exception {
from("cxf:bean:serviceV1").to("mock:processFurther")
}
}
我的应用配置如下:
@SpringBootApplication
@ImportResource({ "/cxf-context.xml" })
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(
SpringApplicationBuilder application) {
return super.configure(application).sources(Application.class);
}
@Bean
public ServletRegistrationBean servletRegistrationBean() {
CXFServlet servlet = new CXFServlet();
return new ServletRegistrationBean(servlet, "/*");
}
}
【问题讨论】:
-
我发现了一篇关于类似问题的博客文章:waterback.github.io/blog/2012/03/02/… 但是提出的解决方案依赖于码头,它打开了两个端口。问题描述很相似
-
我相信 serviceCommon 端点不必是 cxf。它可能是一个 netty-http 端点......
标签: web-services spring-boot apache-camel cxf