拥有 WSDL:
<definitions targetNamespace="http://MyWebService/" name="MyWebService">
<types>
<xsd:schema>
<xsd:import namespace="http://MyWebService/" schemaLocation="http://localhost:8081/MyWebService?xsd=1"/>
</xsd:schema>
</types>
<message name="doIt">
<part name="Word" type="xsd:string"/>
<part name="SomeParameters" type="tns:MapWrapper"/>
</message>
<message name="doItResponse">
<part name="return" type="xsd:string"/>
</message>
<portType name="MyWebService">
<operation name="doIt" parameterOrder="Word SomeParameters">
<input message="tns:doIt"/>
<output message="tns:doItResponse"/>
</operation>
</portType>
...
</definitions>
以及关联的 xsd:
<xs:schema version="1.0" targetNamespace="http://MyWebService/">
<xs:complexType name="MapWrapper">
<xs:sequence>
<xs:element name="map">
<xs:complexType>
<xs:sequence>
<xs:element name="entry" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="key" minOccurs="0" type="xs:string"/>
<xs:element name="value" minOccurs="0" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
为了获取要使用的 WS 的输入参数,发布此 WebService 的最佳/最简单方法是什么。路由应如下所示:(1) WS -> (2) InputParameters -> (3) 使用 inputParameters 的一些处理步骤 -> (4) 取决于 (2) 中的参数的内容。
我尝试从camel-example-cxf获取知识;但在我看来,有很多东西混合在一起,很难理解。
一些 Java DSL 代码片段会很好。
最佳答案
最简单的方法是使用 Spring
创建 Camel 路由。例如:如果您要创建自定义 bean 并希望在将消息路由到实际端点之前修改消息,您可以执行以下操作:
public class CustomProcessor {
public void processDoIt(Exchange exchange) {
DoIt smth = exchange.getIn().getBody(DoIt.class); //Your message's body
}
}
使用 Spring 的 Camel 路线:
<bean id="processor" class="your.custom.CustomProcessor"/>
<camel:camelContext trace="true" id="camelContext" >
<camel:route id="camelRoute">
<camel:from uri="cxf:bean:yourWebServiceListenerEndpoint?dataFormat=POJO&synchronous=true" />
<camel:choice>
<camel:when>
<camel:simple>${headers.operationName} == 'doIt'</camel:simple>
<camel:bean ref="processor" method="processDoIt"/>
</camel:when>
</camel:choice>
<camel:to uri="cxf:bean:yourWebServiceTargetEndpoint"/>
</camel:route>
</camel:camelContext>
根据操作名称,camel 会将消息路由到相应的处理器。您也可以将消息路由到其他地方。它是由你决定。这只是一个如何完成的示例。
另请参阅:
关于java - 带有可选键的Web服务,带有 Camel 的值映射?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14896690/