5

JMS special characters Issue

 1 year ago
source link: https://blogs.sap.com/2022/07/06/jms-special-characters-issue/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
July 6, 2022 2 minute read

JMS special characters Issue

Recently I have worked in JMS(MQ) to Proxy scenario, in which I was facing special characters issue. Basically all umlaut chars such as ä,ö,ü are not displayed correct. I was not using any mapping as this is a pass through scenario.

2022-06-23-16_22_39-Window-1.png

When I download the file into my local machine and open with browser, still same issue exists.

Tried to open with notepad++ and changed encode to ANSI, now chars are displayed correct, saved the file and opened again with browser, now char is getting displayed correctly.

notepad-1.png
note-pad_01.png

then checking hex code of ü in notepad++. with utf-8

Hex_code_01.png

changing encoding to ANSI.

hex_code.png

Changing the file encoding to ANSI, creates correct HEX code.

c3 bc is the correct hex code for char ü .https://www.utf8-zeichentabelle.de/unicode-utf8-table.pl?names=-&unicodeinhtml=hex

I have tried all adapter module beans, as mentioned in below blogs.

https://blogs.sap.com/2015/02/22/handling-code-page-character-encoding-in-sap-pi-po/

https://blogs.sap.com/2014/10/09/character-encoding-handled-the-right-way/

I have tried TextCodepageConversionBean also, which did not work. It could be due to that this is meant for text file not xml file.

Then I have seen this code in stack overflow, This is exactly what is happening in my case.

https://stackoverflow.com/questions/652161/how-do-i-convert-between-iso-8859-1-and-utf-8-in-java

String encodedWithISO88591 = "üzüm baÄları";
String decodedToUTF8 = new String(encodedWithISO88591.getBytes("ISO-8859-1"), "UTF-8");
//Result, decodedToUTF8 --> "üzüm bağları"

I have tried to convert my downloaded xml using java code and it worked fine. I did not convert the encoding, just download the file from monitor and used it in the java code.

package com.java.special.chars;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

public class Readfile {

	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		
		InputStream is = new FileInputStream("data/esm.xml");
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(is,StandardCharsets.UTF_8));
		StringBuilder out = new StringBuilder();
		String line;
		while ((line = reader.readLine()) != null) {
			
			byte[] b = line.getBytes(StandardCharsets.ISO_8859_1);
		 
			System.out.println(new String(b, StandardCharsets.UTF_8));

		}

	}

}

Now the question is, how to achieve the same using module configuration instead of writing java map.

Since my payload is an xml, I had to use anonymizer bean with Message Transform bean. This has solved the issue, chars are getting displayed correct now.

Adapter_Module.png

Xml payload

Correct_chars.png

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK