简体   繁体   English

WSO2有效负载工厂从xml响应保留标签

[英]WSO2 Payload Factory preserving tag from xml response

In my proxy i call a remote rest service which responses me with a message like this one: 在我的代理中,我呼叫了一个远程休息服务,该服务以如下消息响应我:

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

I need to filter some data from this message and build a custom message having this structure: 我需要从此消息中过滤一些数据并构建具有以下结构的自定义消息:

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

Where $1, perhaps using payload factory? $ 1,也许使用有效负载工厂? should be filled with some leaves extracted frome the previous response message, for example like this: 应该填充从先前响应消息中提取的一些叶子,例如:

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

Have i to use payload factory using a particular xpath expression in the arqs declaration (what expression? ). 我是否可以在arqs声明(什么表达式?)中使用特定的xpath表达式来使用有效负载工厂。 Or should i have to use another mediator? 还是我必须使用其他调解人? Which one? 哪一个? Can you give me and example please? 你能给我例子吗?

You need to specify them as arguments. 您需要将它们指定为参数。 Let me extract a code from the original documentation as an example. 让我以原始文档中的代码为例。 Here the expression means the xpath expression. 这里的表达式表示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>

Firstly ,in your outSequence (after you've gotten response) you would need to extract the xml tags/field's from the that response , and store them in properties so we can use them later... 首先,在outSequence中(获得响应后),您需要从该响应中提取xml标签/字段,并将其存储在属性中,以便我们稍后使用...

For example (using xpath): 例如(使用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" /> 

etc etc , if that xpath doesn't work see (see http://www.w3schools.com/xpath/xpath_syntax.asp ) 等等,如果该xpath不起作用,请参阅(请参阅http://www.w3schools.com/xpath/xpath_syntax.asp

You can print these properties to the log to see if they are setting correctly : 您可以将这些属性打印到日志中,以查看它们的设置是否正确:

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

Then in your payload factory, you can set these properties as the parameters of your final response to the client : 然后在您的有效负载工厂中,可以将这些属性设置为对客户端的最终响应的参数:

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

thanks to all of you. 感谢大家。 I found a better method using the xslt mediator. 我发现使用xslt介体的更好方法。 I wrote my xsl file and simply by adding this in my proxy: 我编写了xsl文件,只需将其添加到代理中即可:

<xslt key="myXSL" />

i processed the xml in a more efficient way... the mediator provides me more flexibility. 我以更有效的方式处理了xml ...中介者为我提供了更大的灵活性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM