WSO2 ——(9)ESB功能:数据转换

这篇文章介绍如何通过WSO2 ESB实现数据转换的功能:如改变消息值,“0”转换为“律师投诉”,“1”转换为“公证员投诉”;改变消息标签,添加消息属性等。

场景一:投诉管理
描述:改变消息值,“0”转换为“L”,“1”转换为“N”
1 创建法律援助服务

参见代码FayuanService,打包为FayuanService_1.0.0.aar服务发布。

2、创建代理服务

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="FayuanProxy"
       transports="https,http"
       statistics="enable"
       trace="enable"
       startOnLoad="true">
   <target>
      <inSequence>
         <send>
            <endpoint key="FayuanEndpoint"/>
         </send>
      </inSequence>
      <outSequence>
         <log level="full">
            <property name="before" value="beforeTransform"/>
         </log>
         <xslt key="fyResponse.xslt"/>
         <log level="full">
            <property name="after" value="afterTransform"/>
         </log>
         <send/>
      </outSequence>
   </target>
   <publishWSDL uri="file:repository/samples/resources/proxy/FayuanService.wsdl"/>
   <description/>
</proxy>
                                

3 创建本地项 fyResponse.xslt

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
                xmlns:ns="http://fayuanservice.wso2.org"
				xmlns:ax23="http://fayuanservice.wso2.org/xsd"
                exclude-result-prefixes="fn ns ax23">
    <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>

    <xsl:template match="/">
        <xsl:apply-templates select="//ns:return"/>
    </xsl:template>

    <xsl:template match="ns:return">

        <ns:createFYComplainRecordResponse  xmlns:ns="http://fayuanservice.wso2.org">
		<ns:return  xmlns:ax231="http://fayuanservice.wso2.org/xsd">
               <ax231:complainant><xsl:value-of select="ax23:complainant"/></ax231:complainant>
			   <ax231:respondent><xsl:value-of select="ax23:respondent"/></ax231:respondent>
			   <ax231:info><xsl:value-of select="ax23:info"/></ax231:info>
			   <ax231:recordTime><xsl:value-of select="ax23:recordTime"/></ax231:recordTime>								 
			   <ax231:recordType><xsl:value-of select="translate(ax23:recordType,'01','LN')"/></ax231:recordType>
		</ns:return>
        </ns:createFYComplainRecordResponse>

    </xsl:template>
</xsl:stylesheet>

4 测试

输入0,转换为L


输入1,转换为N


场景二:律师信息转换
描述:改变律师信息服务的响应消息标签,添加删除消息属性等。

1 创建查看律师信息服务

参见代码lawyerAxis2Service,打包为lawyerAxis2Service_1.0.0.aar服务发布。

2、创建代理服务

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="DataTransformProxy"
       transports="https,http"
       statistics="enable"
       trace="enable"
       startOnLoad="true">
   <target>
      <inSequence>
         <send>
            <endpoint key="LawyerInfoEndpoint"/>
         </send>
      </inSequence>
      <outSequence>
         <log level="full">
            <property name="before" value="beforeTransform"/>
         </log>
         <xslt key="dataTransform.xslt"/>
         <log level="full">
            <property name="after" value="afterTransform"/>
         </log>
         <send/>
      </outSequence>
   </target>
   <publishWSDL uri="http://192.168.100.169:9763/services/LayerInfoService?wsdl"/>
   <description/>
</proxy>
                                

3 创建本地项 dataTransform.xslt

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
                xmlns:ns="http://lawyer.wso2.org"
				xmlns:ax219="http://lawyer.wso2.org/xsd"
                exclude-result-prefixes="fn ns ax219">
    <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>

    <xsl:template match="/">
        <xsl:apply-templates select="//ns:return"/>
    </xsl:template>

    <xsl:template match="ns:return">

        <m:getLawyerInfoResponse xmlns:m="http://lawyer.wso2.org/xsd">
               <m:lAWYERLEVEL><xsl:value-of select="ax219:lawyerLevel"/></m:lAWYERLEVEL>
			   <m:lAWYERNAME><xsl:value-of select="ax219:lawyerName"/></m:lAWYERNAME>
			   <m:LAWYEROFFICE><xsl:value-of select="ax219:lawyerOffice"/></m:LAWYEROFFICE>
			   <m:LAWYERORIGIN><xsl:value-of select="ax219:lawyerOrigin"/></m:LAWYERORIGIN>
			   <m:LAWYERSEX><xsl:value-of select="ax219:lawyerSex"/></m:LAWYERSEX>
        </m:getLawyerInfoResponse>

    </xsl:template>
</xsl:stylesheet>
4 测试

直接调用律师信息服务结果为:


转换后律师信息服务结果为:



具体参考http://download.csdn.net/detail/szh1124/8448063
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值