cancel
Showing results for 
Search instead for 
Did you mean: 

unable to parse special characters in Java Mapping

former_member200339
Participant
0 Kudos

Dear All,

I have developed a Java Mapping where I am parsing the payload of an incoming IDOC, generating a mail and sending it to the desired customer via the Mail Adapter. This scenario is working successfully but fails when there is a special character in the IDOC payload. I have modified the program so that the InputStream is converted to UTF-8 then I parse it to create the document object.

It works well when I test it from the Component Monitoring using a saved IDOC but fails when the same IDOC is triggered from the R/3.

The code I used to modify the InputStream is as follows:

InputStream ins = inputObj.getInputPayload().getInputStream();

Reader reader = new InputStreamReader(ins,"UTF-8");

InputSource is = new InputSource(reader);

is.setEncoding("UTF-8");

........

Document doc = dbuilder.parse(is);

Any suggestions

Thanks and Regards,

Rana Brata De

Accepted Solutions (1)

Accepted Solutions (1)

javier_alcubilla
Contributor
0 Kudos

Hi Rana

Try this in the output

.getOutputStream().write(output.getBytes("UTF-8"));

Regards

Javi

Answers (2)

Answers (2)

nabendu_sen
Active Contributor
0 Kudos

Hi Rana,

Please provide the error description.

Regards,

Nabendu.

former_member200339
Participant
0 Kudos

Hi Nabendu,

In the Payloads for Request Message Mapping (sxi_monitor), I found the following messages -

The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

An invalid character was found in text content. Error processing resource 'file:///C:/Users/rde/AppData/Local/Temp/16e93350...

and as a result the following error messages in the AE - Delivery of the message to the application using connection Mail_http://sap.com/xi/XI/System failed, due to: com.sap.engine.interfaces.messaging.api.exception.MessagingException: com.sap.aii.af.sdk.xi.srt.BubbleException: Failed to call the endpoint [null "null"]; nested exception caused by: com.sap.aii.af.sdk.xi.util.XMLScanException: Can't parse the document; nested exception caused by: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.

markangelo_dihiansan
Active Contributor
0 Kudos

Hello Rana,

Can you right-click the payload and then select view source? You should be able to find the invalid character.

Regards,

Mark

former_member200339
Participant
0 Kudos

Hi Mark,

I have found the characters which are causing the failure : 0xA0 and Ø (0xD8) .

They are from the following two data in the xml :

<TDLINE>HEAD CON. ROD MALE Ø 6MM -RH 2508808081 (2508808052)</TDLINE> and

<TDLINE>GASKET GACO OR3181 (2.62X45.69)  2513102062</TDLINE>

But I am unable to convert them to UTF-8 character.

Rana..

markangelo_dihiansan
Active Contributor
0 Kudos

Hello Rana,

What is the original encoding? You need to do byte conversions when transforming one encoding to another e.g ISO-8859 to UTF-8.

Regards,

Mark

ambrish_mishra
Active Contributor
0 Kudos

Hi Rana,

Did you check the RFC unicode ? Try to sort such data issues at the source(ECC).

Ambrish

ambrish_mishra
Active Contributor
0 Kudos

Hi Rana,

Did you check the RFC unicode ? Try to sort such data issues at the source(ECC).

Ambrish

anupam_ghosh2
Active Contributor
0 Kudos

Hi Rana Brata,

                         Please ask the source system to stop sending these characters.

If the source system continues sending the characters then in the java mapping itself, before parsing you need to remove those. What is the version of PI you are working with. If possible could you upload the faulty source XML file.

Regards

Anupam

ambrish_mishra
Active Contributor
0 Kudos

Hi,

please check if the RFC (T code Sm59) in ECC has Unicode checked.

Its an ABAP connection of Type 3 used to communicare with PI.

Ambrish

`