1

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

我的目标如下:

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

问题:

如何逐步进行并使 ws1 和 ws2 进行通信(我认为是通过代理)?因为我尝试了很多 tuto,但没有一个是为了我的详细原因,我真的是 ESB 的初学者。

非常感谢。

4

3 回答 3

1

是的。您可以一步完成。我之前在一个项目中做过这个:这是您可以遵循的步骤:

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.

请注意,您可能需要包括异常(故障序列)处理。

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>

于 2013-01-04T05:33:33.697 回答
0

您需要做的是,调用 ws1,获取响应,从响应中提取值,然后创建要发送到 ws2 的有效负载并调用 ws2。该网络研讨会展示了如何执行类似的场景。

于 2013-01-03T05:30:40.833 回答
0

我将尝试解释所有后续步骤:


网页服务

  1. wsOne 部署在 wso2as 中:接受参数:wsOne (input1, size) 并返回一个包含 3 个字符串 (t1, t2, output1) 的表,
  2. ws2One 部署在 wso2as 中:接受参数:wsTwo(output1) 并返回字符串:“Hello output1”。

wsOne:

EndPoint (In wso2as): http://localhost:9765/services/wsOne

WSDL (In wso2as): http://localhost:9765/services/wsOne?wsdl

ws二:

EndPoint (In wso2as): http://localhost:9765/services/wsTwo

WSDL (In wso2as): http://localhost:9765/services/wsTwo?wsdl


  1. 现在我在 wso2esb 中,我必须在代理之前创建一个序列,因为我将为每个 ws 调用代理内部的序列:

序列

ServiceBus -> 序列 -> 定义的序列 -> 添加序列。

ws1ResultSequence

我不知道必须包含什么原因当我尝试创建有效负载时出现错误..

ws1InSequence

<sequence xmlns="http://ws.apache.org/ns/synapse"><in>
  <filter>
     <then>
        <send receive="ws1ResultSequence">
           <endpoint>
              <address uri="http://localhost:9765/services/wsOne"/>
           </endpoint>
        </send>
       </then>
     <else/>
    </filter>
  </in>
</sequence>

ws2序列

<sequence xmlns="http://ws.apache.org/ns/synapse" name="conf:/ws2Sequence">
   <out>
      <send/>
   </out>
</sequence>

代理

ws1Proxy

添加->代理服务->自定义代理->名称:ws1proxy,发布wsdl:否,下一步->定义InSequence->从注册表中挑选->ws1InSequence。

ws2Proxy

Add->Proxy Service ->Custom Proxy-> Name: ws2proxy, publishing wsdl: No, Next -> Define InSequence-> Pick from Registry -> ws2Sequence.


Is My steps correct or not ? I know that I did Many mistakes following as it's my first interaction with SOA, ESB, ... What Must the Client execute to launch the chaining and obtain the required result (ws1Proxy) or an other?

Thanks a lot for your time.

于 2013-01-04T17:15:25.203 回答