WSO2 Payload Factory保留xml响应中的标记

时间:2015-05-19 21:11:27

标签: xml xpath wso2 wso2esb mediator

在我的代理服务器中,我拨打了一个远程休息服务,该服务通过以下消息回复我:

<omim version="1.0">
<entryList>
  <entry>
    <prefix>#</prefix>
    <mimNumber>230900</mimNumber>
    <status>live</status>
    <titles>
        <preferredTitle>GAUCHER DISEASE, TYPE II</preferredTitle>
        <alternativeTitles>GD II;;</alternativeTitles>
     </titles>
     <clinicalSynopsis>
         <inheritance>Autosomal recessive</inheritance>
         <growthWeight>Poor weight gain </growthWeight>
          <growthOther>Failure to thrive </growthOther>
          <headAndNeckEyes>Convergent squint</headAndNeckEyes>
          <headAndNeckMouth>Trismus </headAndNeckMouth>
          <respiratory>Apnea</respiratory>
          <respiratoryLarynx>Laryngeal spasms</respiratoryLarynx>
          <respiratoryLung>Recurrent aspiration pneumonia</respiratoryLung>
          <abdomenExternalFeatures>Protruberantabdomen</abdomenExternalFeatures>
          <abdomenLiver>Hepatomegaly</abdomenLiver>
          <abdomenSpleen>Splenomegaly</abdomenSpleen>
          <abdomenGastrointestinal>Dysphagia </abdomenGastrointestinal>
          <neurologicCentralNervousSystem>Progressive neurologic deterioration</neurologicCentralNervousSystem>
          <hematology>Thrombocytopenia</hematology>
          <laboratoryAbnormalities>Decreased acid beta galactosidase protein and activity</laboratoryAbnormalities>
          <miscellaneous>Onset between 3 and 6 months of age</miscellaneous>
          <molecularBasis>Caused by mutation in the acid beta-glucosidase gene</molecularBasis>
     </clinicalSynopsis>
    </entry>
  </entryList>
</omim>

我需要从此消息中过滤一些数据并构建具有以下结构的自定义消息:

<clinicalManifestation>
    <nonNeurological>
         $1
    </nonNeurological>
</clinicalManifestation>

哪里1美元,也许使用有效载荷工厂?应填充一些从前一个响应消息中提取的叶子,例如:

<clinicalManifestation>
    <nonNeurological>
         <growthWeight>Poor weight gain </growthWeight>
          <growthOther>Failure to thrive </growthOther>
          <headAndNeckEyes>Convergent squint</headAndNeckEyes>
          <headAndNeckMouth>Trismus </headAndNeckMouth>
          <respiratory>Apnea</respiratory>
          <respiratoryLarynx>Laryngeal spasms</respiratoryLarynx>
          <respiratoryLung>Recurrent aspiration pneumonia</respiratoryLung>
          <abdomenExternalFeatures>Protruberantabdomen</abdomenExternalFeatures>
          <abdomenLiver>Hepatomegaly</abdomenLiver>
          <abdomenSpleen>Splenomegaly</abdomenSpleen>
          <abdomenGastrointestinal>Dysphagia </abdomenGastrointestinal>
    </nonNeurological>
</clinicalManifestation>

我是否要在arqs声明中使用特定的xpath表达式使用有效负载工厂(什么表达式?)。或者我应该使用另一个调解员?哪一个?你能给我一个例子吗?

3 个答案:

答案 0 :(得分:0)

您需要将它们指定为参数。让我从原始documentation中提取代码作为示例。这里的表达式表示xpath表达式。

<payloadFactory>
      <format>
           <m:checkpriceresponse xmlns:m="http://services.samples/xsd">
               <m:code>$1</m:code>
               <m:price>$2</m:price>
           </m:checkpriceresponse>
      </format>
      <args>
           <arg expression="//m0:symbol" xmlns:m0="http://services.samples/xsd">
           <arg expression="//m0:last" xmlns:m0="http://services.samples/xsd">
      </arg></arg></args>
</payloadFactory>

答案 1 :(得分:0)

首先,在你的outSequence中(在得到回复之后)你需要从该响应中提取xml标签/字段,并将它们存储在属性中,以便我们以后可以使用它们......

例如(使用xpath):

<property name="growthWeight" expression="//omin/entryList/entry/clinincalSynopsis/growthWeight/text()" scope="default" type="STRING" />
<property name="growthOth" expression="//omin/entryList/entry/clinincalSynopsis/growthOther/text()" scope="default" type="STRING" /> 

等等,如果该xpath不起作用,请参阅(参见http://www.w3schools.com/xpath/xpath_syntax.asp

您可以将这些属性打印到日志中,以查看它们是否设置正确:

<log level="custom">
     <property xmlns:ns="http://org.apache.synapse/xsd" name="Extracted:  Growth weight= " expression="$ctx:growthWeight"/>
     <property xmlns:ns="http://org.apache.synapse/xsd" name="Extracted:  Growth other= " expression="$ctx:growthOth"/>
</log>

然后在您的有效负载工厂中,您可以将这些属性设置为对客户端的最终响应的参数:

<payloadFactory media-type="xml">
    <format>
        <clinicalManifestation>
            <nonNeurological>
                <growthWeight>$1</growthWeight>
                <growthOther>$2</growthOther>
                    :
                    :
                    :
            </nonNeurological>
        </clinicalManifestation>
    </format>
    <args>
        <arg evaluator="xml"  expression="$ctx:growthWeight" />
        <arg evaluator="xml"  expression="$ctx:growthOth" />
                    :
                    :
                    :
    </args>
</payloadFactory>

答案 2 :(得分:0)

谢谢你们所有人。 我找到了一个使用xslt介体的更好方法。我写了我的xsl文件,只需在我的代理中添加它:

C_ClfGtLabels

我以更有效的方式处理了xml ...介体为我提供了更大的灵活性。