【问题标题】:Switching OutSequence in WSO2 ESB Proxy Service based oh SOAP response在基于 SOAP 响应的 WSO2 ESB 代理服务中切换 OutSequence
【发布时间】:2015-09-14 10:13:22
【问题描述】:

我在 WSO2 ESB 中部署了一个代理服务,用于从 SOAP WS 检索数据集,并且我有一个基于调用模板的序列的 OutSequence。

我必须根据不同的请求来引导各种 WS 响应,将它们路由到由 vfs 传输写入的不同文件上。

实际顺序如下:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="seq_prova_con_template">
   <call-template target="file">
      <with-param name="filename" value="IstatAllDataflow-template.xml"></with-param>
   </call-template>
</sequence>

我想到了一个 switch-case 调解器,但我想了解如何“捕捉”信息以选择正确的案例。在示例中:

`<switch source="//m0:getQuote/m0:request/m0:symbol"     xmlns:m0="http://services.samples/xsd">
      <case regex="IBM">
           <!-- the property mediator sets a local property on the *current*     message -->
          <property name="symbol" value="Great stock - IBM"/>
      </case>
      <case regex="MSFT">
          <property name="symbol" value="Are you sure? - MSFT"/>
      </case>
      <default>
          <!-- it is possible to assign the result of an XPath or JSON Path     expression as well -->
      <property name="symbol"
            expression="fn:concat('Normal Stock - ', //m0:getQuote/m0:request/m0:symbol)"
            xmlns:m0="http://services.samples/xsd"/>
  </default>

`

我问自己如何设置开关盒的源参数,我想知道是否有人已经实施了这样的解决方案,以便使用单个代理服务来区分来自 WS 的各种答案。 我的顺序如下:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="seq_template_switch">
   <switch xmlns:ns="http://org.apache.synapse/xsd" xmlns:m0="http://services.samples" source="??????">
      <case regex="QueryStructure">
         <call-template target="file">
            <with-param name="filename" value="IstatAllDataflow-template.xml"></with-param>
         </call-template>
      </case>
      <case regex="GetCompactData">
         <call-template target="file">
            <with-param name="filename" value="GetCompactData-template.xml"></with-param>
         </call-template>
      </case>
   </switch>
</sequence>

我需要在我的请求消息的请求中从 che 方法中捕获 switch case 的选择,以便在我要求某种答案时写入某个文件,并在我要求时写入另一个名称不同的文件寻求另一种答案。

[编辑] 日志文件有这个:

TID: [0] [ESB] [2015-09-18 10:33:09,125]  INFO {org.apache.synapse.mediators.builtin.LogMediator} -  To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:7cc540d3-2893-4b0e-8a24-ab4538236d45, Direction: response, Envelope: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><QueryStructureResponse xmlns="http://ec.europa.eu/eurostat/sri/service/2.0"><QueryStructureResult><RegistryInterface xmlns="http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message"><Header><ID>IT1001</ID><Test>true</Test><Name xml:lang="en">ISTAT_JD_237</Name><Prepared>2001-03-11T15:30:47+01:00</Prepared><Sender id="ISTAT"><Name xml:lang="en">Italian Statistical Institute</Name><Contact>

选择关于标签&lt;QueryStructureResponse&gt; 的开关/案例调解器会很有用。例如,我可以用&lt;GetCompactData&gt; 代替这个标签。我想创建一个由这两个标签之一驱动的开关/案例调解器。这将是了解如何使用 XPath 位置和使用单个序列通过 vfs 传输区分不同文件中的 SOAP 答案的良好开端。要写入的文件的选择将由 WS 的答案类型决定。

【问题讨论】:

  • 您希望根据 SOAP 响应中的内容调用不同的序列。如果我的理解有误,请纠正我。请同时提供您的 SOAP 响应以回答您的问题。
  • 我认为基于我的 SOAP 请求中的内容更有用:我可以将此序列放在计划任务中或使用带有代理服务的请求,我想根据到请求。如果我想根据请求消息中的一些关键字选择目的地,我不知道在切换序列的源中放入什么。我希望我已经清楚了,非常感谢。
  • 你需要在源码中使用Xpath。

标签: proxy sequence wso2esb switching mediator


【解决方案1】:

以下内容应该适合您。它正在检查 SOAP xml 中是否存在 QueryStructureResponse。如果可用,它将调用 IstatAllDataflow-template.xml 模板,否则它将调用 GetCompactData-template.xml 模板。

<switch source="boolean($body//*[local-name() = 'QueryStructureResponse'])">
        <case regex="true">
           <call-template target="file">
        <with-param name="filename" value="IstatAllDataflow-template.xml"></with-param>
     </call-template>
        </case>
        <case regex="false">
           <call-template target="file">
        <with-param name="filename" value="GetCompactData-template.xml"></with-param>
     </call-template>
        </case>
     </switch>

在 WSO2 esb 中使用过滤器的另一种解决方案。

<filter source="boolean($body//*[local-name() = 'QueryStructureResponse'])" regex="true">
   <then>
      <log>
         <property name="======================== TRUE =========================" value="true"/>
      </log>
      <call-template target="file">
         <with-param name="filename" value="IstatAllDataflow-template.xml"/>
      </call-template>
   </then>
   <else>
      <log>
         <property name="==================== FALSE =========================" value="false"/>
      </log>
      <call-template target="file">
         <with-param name="filename" value="GetCompactData-template.xml"/>
      </call-template>
   </else>
</filter>

【讨论】:

  • 谢谢,现在我必须选择从通过代理服务的 che 请求 XML 消息中捕获我的源的确切路径(使用计划任务或简单的 SOAP UI 消息......这可能吗? ?)。关于我在哪里可以找到消息来源以准确驱动开关的想法?我可以知道如何使用 Xpath 在消息中导航,但我不知道如何将我的 Xpath 引用到请求消息...我希望我正确地解释了我的问题。
  • 能否根据您要调用的序列提供您的 XML 和关键字。
  • 我尝试过使用 source="$body/*",但它不起作用。我在 conf 文件中启用了 synapse.xpath.dom.failover.enabled=true。
  • 请放置一个日志中介并尝试打印 $body 并提供该 XML。
  • 抱歉,我找不到 SOAP 响应。您已提供序列。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-08
  • 2012-12-08
  • 2012-06-15
  • 1970-01-01
  • 2013-02-07
相关资源
最近更新 更多