java - 带有可选键的Web服务,带有 Camel 的值映射?

标签 java web-services dictionary apache-camel

拥有 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&amp;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/

相关文章:

android - 使用按钮刷新数据与定期更新同时发生

javascript - 尝试在 javascript 中使用该库时无法找到模块 'collections/dict'

c++ - 将代码从 map<char, T> 重构为 vector<T>

java - 为什么 java.lang.Object 不是抽象的?

java - 打包在 EAR 中时 Web 服务不可用

c# - 如何在 C# 中通过 DropBoxRest API 获取 Dropbox 文件?

c - 如何在 C 中存储我的 map ?

java - 无法在 Android Studio 中加载 Android 支持库

java - 用于高延迟连接的 sslsocket session 机制

web-services - Chrome是否本身会超时进行网络服务调用?