简体   繁体   English

Mule中的Java组件不使用项目的UTF-8编码

[英]Java Component in Mule does not use project's UTF-8 encoding

I have a java component in Mule that is returning a String. 我在Mule中有一个Java组件正在返回一个字符串。 When I print that string from within the java component, it reads as UTF-8 just fine in the console. 当我从java组件中打印该字符串时,它在控制台中读为UTF-8就可以了。 However, when I return this as the payload, the subsequent logger and all downstream components can no longer read the UTF-8 characters. 但是,当我将其作为有效载荷返回时,后续的记录器和所有下游组件不再能够读取UTF-8字符。 I've confirmed that my project's encoding setting is set to 'UTF-8'. 我已经确认我的项目的编码设置设置为'UTF-8'。 I've also: 我也:

  1. Setting MULE_ENCODING=UTF-8 before and after the Java component, both as an outbound property and invocation property. 在Java组件之前和之后将MULE_ENCODING=UTF-8设置为出站属性和调用属性。
  2. Setting the encoding on the message in a mule expression, but that failed message.setEncoding('UTF-8') with an error stating it could not find the method setEncoding() 在m子表达式中设置消息的编码,但是该message.setEncoding('UTF-8')失败message.setEncoding('UTF-8')带有错误,指出无法找到方法setEncoding()
  3. Using the following in the java component: 在Java组件中使用以下代码:

     eventContext.getMessage().setPayload(myString); eventContext.getMessage().setEncoding("UTF-8"); return eventContext.getMessage().getPayload(); 
  4. Switching to a java transformer instead of a component, using the below config on the transformer, explicitly setting encoding to "UTF-8". 使用变压器上的以下配置,切换到Java变压器而不是组件,将编码明确设置为“ UTF-8”。

     <custom-transformer encoding="UTF-8" class="myDomain.myJavaTransformer" doc:name="Java"/> 

I'm not sure what else to try to ensure the payload coming out of the java component/transformer is not interpreted or converted to another encoding... 我不确定还有什么尝试可以确保从Java组件/变压器发出的有效载荷不会被解释或转换为其他编码...

The output should read: “Outstanding New Environmental Scientist” 输出应为:“杰出的​​新环境科学家”

The logger currently outputs is “Outstanding New Environmental Scientistâ€. 记录器当前输出的是“杰出新环境科学家”。 I've corrected this in other parts of the flow by adding encoding=UTF-8 to any VM endpoints, for example. 我已经在流程的其他部分纠正了此问题,例如,向任何VM端点添加了encoding = UTF-8。 I've also confirmed that this can print correctly in a logger elsewhere in the flow. 我也已经确认可以在流程中其他地方的记录器中正确打印。

There seems to be something happening after the String is returned from within the java class referenced by the java component and the subsequent mule logger... 从Java组件引用的java类和后续的Mule logger中返回String后,似乎发生了某些事情。

在您的Java组件之后尝试<object-to-string-transformer encoding="..." />

I had a problem with encoding too. 我也有编码问题。 It was not completely similar to your case but I took this action and it worked for me. 它与您的案件并不完全相似,但我采取了这项措施,对我来说很有用。 (Byte to array using java serialization) (使用Java序列化到数组的字节)

<set-property propertyName="MULE_ENCODING" value="UTF-8" doc:name="Property" />

<byte-array-to-string-transformer encoding="UTF-8" doc:name="Byte Array to String"/>

I used that when message is coming to my flow. 当消息传到我的流中时,我就使用了它。

Also there is properties in wrapper and you can set that as well. 包装器中也有属性,您也可以进行设置。

How are you reading the RSS feed? 您如何阅读RSS提要? If it is using an endpoint, try setting the 'encoding' attribute for that endpoint? 如果使用端点,请尝试为该端点设置'encoding'属性?

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

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