2013-01-03 14 views
1

尊敬的各位,在第一个新年快乐。wso2esb&wso2as - 链接或编排两个Web服务

我的目标是如下:

我有两个Axis2的web服务(WS1,WS2)部署在wso2as。客户端通过wso2esb必须为ws1提供参数,并且返回的值必须作为将最终值返回给客户端的参数提供给ws2。所以客户做出的,只是给ws1提供参数并从ws2接收最终响应。

问:

如何让循序渐进,使WS1和WS2沟通(我认为这是通过代理服务器)?因为我尝试了很多tuto,没有人为我详细的原因,我真的与ESB合作。

非常感谢。

回答

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. 

注意,你可能需要包括异常(faultSequence)处理。

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

UPDATE:您可以使用此示例作为示例。注意,这可能不是您需要的完整代码,您可能需要添加异常处理。

<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> 

+0


谢谢唐先生您的回应。
也许我理解错误(由于我的经验不足):
1.我必须为ws1和ws2创建代理。
2.和所有序列(ws1InSequence,ws1ResultSequence),
3. element1和element2是ws2参数的名称还是由wso2给出的静态名称?
4.这,,是否在代理 - >定义序列中创建?
非常感谢您的回复
Yanni

+0

我试过但我很困惑。我不知道每个序列中必须创建多少个和每个介体。以及每个调解员的不同论点。请您给我请每个序列的代码视图。 – Yanni

+1

@Yanni该项目是在我的专业工作,很抱歉,我不能给你任何实际的代码视图。你如何发布你的一些代码,然后我们可以从那里谈谈。 – Don

0

你需要做的是,调用ws1,获取响应,从响应中提取值,然后创建负载发送到ws2并调用ws2。 This webinar显示了如何做类似的情况。

+0

感谢您的回答。是的,我想制作像Healthcare这样的示例,但是我无法理解所完成的步骤,特别是在创建代理的属性声明步骤中(如何获取XPATH和获取...的方法?) – Yanni

0

我会尽量解释所有遵循以下步骤:


的WebServices

  1. wsOne部署在wso2as:作为参数:wsOne(输入1,大小)并返回3个字符串表(t1,t2,output1),
  2. 在wso2as中部署的ws2One:作为参数:wsTwo(output1)并返回String:“Hello output1”。

wsOne:

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

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

wsTwo:

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

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


  1. 现在我在wso2esb,我必须创建序列和代理之前,因为我会打电话给代理的内部序列每个WS:

序列

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

ws1ResultSequence

我不knwo正是必须包含的原因当我试图创建有效载荷的错误。我有

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> 

ws2Sequence

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

代理

ws1Proxy

添加 - >代理服务 - >自定义的Proxy->名称:ws1proxy,出版WSDL:没有,下一步 - >定义InSequence->从注册表选择 - > ws1InSequence。

ws2Proxy

添加 - >代理服务 - >自定义的Proxy->名称:ws2proxy,出版WSDL:没有,下一步 - >定义InSequence->从注册表选择 - > ws2Sequence。


是我的步骤正确与否?我知道我做了下面,因为它是我与SOA,ESB, 第一交互失误很多......什么是必须执行的客户端启动链接和获取所需的结果(ws1Proxy)或其他?

非常感谢您的时间。

+1

我认为你在正确的轨道上。现在最重要的部分是“ws1ResultSequence”。另外,在你的“ws1InSequence”中,如果你不需要验证邮件内容,那么你不需要使用 Don

+1

你可以看到我更新的答案为“ws1ResultSequence” – Don

+0

非常感谢Don先生,我会尝试按照你的答案,如果它工作与否,我会给你结果。谢谢。 – Yanni