标签:wso2
这篇文章介绍如何通过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>
<?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>
输入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>
<?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 测试
直接调用律师信息服务结果为:
转换后律师信息服务结果为:
标签:wso2
原文地址:http://blog.csdn.net/szh1124/article/details/43834877