MULE ESB 中文传参乱码问题解决

MULE ESB 中文传参乱码问题解决

<!--主流程 -->

<flow name="AllThird" doc:name="AllThird">

<!-- 监听入口 -->

<inbound-endpoint exchange-pattern="request-response"address="http://0.0.0.0:9999/third" doc:name="third">

<logger level="INFO" message="third interface Start" />

</inbound-endpoint>

<!-- logger日志 -->

<logger message="#[headers:INBOUND:*]" level="INFO" doc:name="LoggerHeaders" />

<!--选择器 -->  		

<choice doc:name="Choice">   		

<when expression="#[message.inboundProperties['http.request.path']=='/third/action/api/userLogin']">   	

		 <!-- 用户登录 请求第三方接口 -->    			

<http:outbound-endpoint exchange-pattern="request-response"    		

encoding="UTF-8" address="http://10.120.145.121:8080/information/userLogin.action"    			

	 method="POST" doc:name="userLogin">     		

	<!-- 原样传参 -->    			

 <logger message="原样传参:#[message.inboundProperties['http.query.params']]" level="INFO" />     	

		<set-payload value="#[message.inboundProperties['http.query.params']]" />     	

		<!-- 返回数据 -->     			

<response>      				

<!-- 返回XML数据 -->     				

 <transformer ref="setXmlContentType" />      	

			<transformer ref="Login" />      

				<logger level="INFO" message="third interface(userLogin)end" />     

			</response>    		

	</http:outbound-endpoint>  		

</when>

<otherwise></otherwise>

</choice>

</flow>
 

 

 
这个功能是完成HTTP代理的, 但是其中的问题就是中文乱码问题,找了一天找到2种可修改的方法:

一、  URL编码解码;

         用这种方式但是ESB得到的就会是中文(自动解码了),所以给第三方传的时候,第三方还是乱码。

        所以就想到了,在请求的时候,将中文编码2次,在ESB这自动解码一次,然后第三方再进行解码,就会得到汉字了!

二、在标签http:outbound-endpoint 中加属性 contentType="text/plain;charset=utf-8"

       这样,请求方只要编码一次即可,传的中文原样输出,但是第三方必须是用流的方式来接受参数才行!

至于用那种方式,就看你们的请求方和第三方那个更容易修改或者协调了!

如果有更好的方法请留言
<?xml version="1.0" encoding="UTF-8"?>
<!--主流程 -->

<flow name="AllThird" doc:name="AllThird">

<!-- 监听入口 -->

<inbound-endpoint exchange-pattern="request-response"address="http://0.0.0.0:9999/third" doc:name="third">
<logger level="INFO" message="third interface Start" />
</inbound-endpoint>
<!-- logger日志 -->
<logger message="#[headers:INBOUND:*]" level="INFO" doc:name="LoggerHeaders" />
<!--选择器 -->          
<choice doc:name="Choice">           
<when expression="#[message.inboundProperties['http.request.path']=='/third/action/api/userLogin']">       
         <!-- 用户登录 请求第三方接口 -->                
<http:outbound-endpoint exchange-pattern="request-response"            
encoding="UTF-8" address="http://10.120.145.121:8080/information/userLogin.action"                
     method="POST" doc:name="userLogin">             
    <!-- 原样传参 -->                
 <logger message="原样传参:#[message.inboundProperties['http.query.params']]" level="INFO" />         
        <set-payload value="#[message.inboundProperties['http.query.params']]" />         
        <!-- 返回数据 -->                 
<response>                      
<!-- 返回XML数据 -->                     
 <transformer ref="setXmlContentType" />          
            <transformer ref="Login" />      
                <logger level="INFO" message="third interface(userLogin)end" />     
            </response>            
    </http:outbound-endpoint>          
</when>
<otherwise></otherwise>
</choice>
</flow>
 

 
这个功能是完成HTTP代理的, 但是其中的问题就是中文乱码问题,找了一天找到2种可修改的方法:

一、  URL编码解码;

         用这种方式但是ESB得到的就会是中文(自动解码了),所以给第三方传的时候,第三方还是乱码。

        所以就想到了,在请求的时候,将中文编码2次,在ESB这自动解码一次,然后第三方再进行解码,就会得到汉字了!

二、在标签http:outbound-endpoint 中加属性 contentType="text/plain;charset=utf-8"

       这样,请求方只要编码一次即可,传的中文原样输出,但是第三方必须是用流的方式来接受参数才行!

至于用那种方式,就看你们的请求方和第三方那个更容易修改或者协调了!

如果有更好的方法请留言

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值