136.16. 路由中的端点映射
通过 XML 配置,您现在可以使用 Camel 的 DSL 定义端点处理哪些 Web 服务请求:
以下路由接收 http://example.com/ 命名空间中名为 "GetFoo" 的 root 元素的所有 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)
以下路由接收在消息(和 default 命名空间)内包含元素 & lt;foobar>abc </foobar> 的请求。
from("spring-ws:xpathresult:abc?expression=//foobar&endpointMapping=#endpointMapping")
.convertBodyTo(String.class).to(mock:example)
136.16.1. 使用现有端点映射的替代配置 复制链接链接已复制到粘贴板!
对于带有 mapping-type beanname 的每个端点,Registry/ApplicationContext 中需要一个类型为 CamelEndpointDispatcher 的 bean。此 bean 充当 Camel 端点和现有 端点映射 (如 PayloadRootQNameEndpointMapping )之间的桥接。
使用 beanname mapping-type 主要用于(传统)您已使用 Spring-WS 的情况,并在 Spring XML 文件中定义端点映射。beanname mapping-type 允许您使 Camel 路由进入现有的端点映射。当您开始开始时,您必须将端点映射定义为 Camel URI (如上方带有 endpointMapping),因为它需要较少的配置,且更具表达性。您还可以在注解中使用 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" />