亲爱的大家,在第一个新年快乐。

我的目标如下:

我在wso2as中部署了两个axis2 Web服务(ws1,ws2)。客户端必须通过wso2esb将参数提供给ws1,并且必须将返回的值提供给ws2作为将最终值返回给客户端的参数。因此,客户端所做的只是将参数提供给ws1,并从ws2接收最终响应。

题:

如何逐步执行该步骤,并使ws1和ws2进行通信(我认为这是通过代理进行的)?因为我尝试了许多tuto,但没人能详细说明我对ESB的初衷。

非常感谢。

最佳答案

是。您可以一步一步完成。我之前在一个项目中做到过:
您可以按照以下步骤操作:

1. ws1 and ws2 are both have "endpoints" defined in the ESB.
2. In the ws1 proxy, define a target inSequence to point to a "sequence"
   for example "ws1InSequence"
3. In the "ws1InSequence", you can use <filter> to make sure the value is exists.
   Then you can <send> to the ws1 <endpoint> with "receive" attribute point to
   a sequence for example "ws1ResultSequence"
4. In the ws1ResultSequence, you can again use the <filter> to make sure
   it has the parameter/value you need. Then you can use param/value to format a request message.
<payloadFactory>
    <format>
        <ns1: ws2Operation
            xmlns:ns1="ws2Namespace">
            <element1 xmlns="">$1</element1>
            <!-- Note $1 will have the //paramName value from the ws1 Result message -->
            <element2 xmlns="">$2</element2>
            <!-- Note $2 will have the //paramName2 value from the ws1 Result message -->
    </format>
    <args>
        <arg expression="//paramName" />
        <arg expression="//paramName2" />
    </args>
</payloadFactory>
5. Still in ws1ResultSequence, after you create the request message,
   you <send> it to the ws2 proxy. Then in the ws2 proxy, in the <outSequence>
   you can juse use <send/> to send the response to the client.


请注意,您可能需要包括exception(faultSequence)处理。

WSO2ESB使用Apache Synapse进行配置。您可以在其文档中找到大多数语法和示例用法:http://synapse.apache.org/userguide/config.html

更新:您可以以此为例。注意,这可能不是您需要的完整代码,并且可能需要添加异常处理。

   <sequence xmlns="http://ws.apache.org/ns/synapse" name="ws1ResultSequence"
trace="enable" onError="ws1ResultSequenceErrorHandler">
<log level="custom">
    <property name="sequence" value="INVOCATION START: ws1ResultSequence" />
</log>
<!-- record the original message for future reference -->
<enrich>
    <source clone="true" type="envelope" />
    <target action="replace" type="property" property="ORIGINAL" />
</enrich>

<!-- Check if the ws1 result message has the value -->
<property
    xmlns:ns1="ws1Namespace"
    name="valueExists" expression="//ns1:element1" />
    <!--Note here, element1 is the element name which has the value: output1 -->

<filter xpath="fn:boolean( get-property('valueExists') )">
    <then>
        <!-- create the request message to invoke ws2 -->
        <payloadFactory>
            <format>
                <ns1:ws2OperationName
                    xmlns:ns1="ws2Namespace">
                    <element2 xmlns="">$1</element2>
                </ns1:ws2OperationName>
            </format>
            <args>
                <arg expression="//ns1:element1" />
            </args>
        </payloadFactory>
        <log level="custom">
            <property name="inInvokeWS2" value="INVOCATION START: value from ws1 result exists" />
        </log>

        <send>
            <endpoint key="ws2Sequence" />
        </send>
        <drop/>
    </then>
</filter>
<!-- No result value found from the ws1 result message -->
<send>
    <endpoint key="DoSomethingElseOrThrowError" />
</send>

关于java - wso2esb&wso2as-两个Web服务的链接或编排,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14131335/

10-11 08:51