1
votes

I have a java component in Mule that is returning a String. When I print that string from within the java component, it reads as UTF-8 just fine in the console. However, when I return this as the payload, the subsequent logger and all downstream components can no longer read the UTF-8 characters. I've confirmed that my project's encoding setting is set to '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.
  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()
  3. Using the following in the java component:

    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".

    <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...

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. 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...

3
what does the subsequent logger print? - Charu Khurana
The output is “Outstanding New Environmental Scientistâ€. I've corrected this in other parts of the flow by adding encoding=UTF-8 to any VM endpoints. I've also confirmed that this can print correctly in a logger elsewhere in the flow. - Gary Sharpe
how about you push content of java component to vm setting encoding as UTF-8 as you mentioned and try accessing there. Wondering if that works? - Charu Khurana
How the string “Outstanding New Environmental Scientist” is generated? - Sérgio Abreu
It is retrieved from an RSS feed earlier in the flow. The encoding on the feed is UTF-8. - Gary Sharpe

3 Answers

1
votes

try <object-to-string-transformer encoding="..." /> right after your java component

1
votes

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)

<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.

0
votes

How are you reading the RSS feed? If it is using an endpoint, try setting the 'encoding' attribute for that endpoint?