[英]WSO2 Payload Factory preserving tag from xml response
在我的代理中,我呼叫了一个远程休息服务,该服务以如下消息响应我:
<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表达式来使用有效负载工厂。 还是我必须使用其他调解人? 哪一个? 你能给我例子吗?
您需要将它们指定为参数。 让我以原始文档中的代码为例。 这里的表达式表示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>
首先,在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>
感谢大家。 我发现使用xslt介体的更好方法。 我编写了xsl文件,只需将其添加到代理中即可:
<xslt key="myXSL" />
我以更有效的方式处理了xml ...中介者为我提供了更大的灵活性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.