65.15. 路由中的端点映射
使用 XML 配置原位,您现在可以使用 Camel 的 DSL 定义端点处理哪些 Web 服务请求:
以下路由接收 http://example.com/
命名空间中具有名为"GetFoo"的根元素的所有 Web 服务请求。
from("spring-ws:rootqname:{http://example.com/}GetFoo?endpointMapping=#endpointMapping") .convertBodyTo(String.class).to(mock:example)
以下路由接收包含 http://example.com/GetFoo
SOAP 操作的 Web 服务请求。
from("spring-ws:soapaction:http://example.com/GetFoo?endpointMapping=#endpointMapping") .convertBodyTo(String.class).to(mock:example)
以下路由接收发送到 http://example.com/foobar
的所有请求。
from("spring-ws:uri:http://example.com/foobar?endpointMapping=#endpointMapping") .convertBodyTo(String.class).to(mock:example)
以下路由收到包含消息(和默认命名空间) 中的元素 <foobar>abc
</foobar> 的请求。
from("spring-ws:xpathresult:abc?expression=//foobar&endpointMapping=#endpointMapping") .convertBodyTo(String.class).to(mock:example)
65.15.1. 备用配置,使用现有端点映射
对于带有 mapping-type beanname
一个类型为 CamelEndpointDispatcher
的端点,Registry/ApplicationContext 中需要带有对应名称的 bean。此 bean 充当 Camel 端点和现有 端点映射 之间的桥接,如 PayloadRootQNameEndpointMapping
。
beanname
mapping-type 的使用主要用于(传统)您已使用 Spring-WS 并在 Spring XML 文件中定义端点映射。beanname
mapping-type 允许您将 Camel 路由放入现有的端点映射中。从开始开始时,您必须将端点映射定义为 Camel URI (如上图所示),因为它需要较少的配置,且更加表达。您还可以在注解中使用 vanilla Spring-WS。
使用 beanname
的路由示例:
<camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="spring-ws:beanname:QuoteEndpointDispatcher" /> <to uri="mock:example" /> </route> </camelContext> <bean id="legacyEndpointMapping" class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping"> <property name="mappings"> <props> <prop key="{http://example.com/}GetFuture">FutureEndpointDispatcher</prop> <prop key="{http://example.com/}GetQuote">QuoteEndpointDispatcher</prop> </props> </property> </bean> <bean id="QuoteEndpointDispatcher" class="org.apache.camel.component.spring.ws.bean.CamelEndpointDispatcher" /> <bean id="FutureEndpointDispatcher" class="org.apache.camel.component.spring.ws.bean.CamelEndpointDispatcher" />