I am facing trouble in translating portuguese characters that is part of a field in XML String. I am using the transform Method and also encoded with iso-8859-1 and I ended up with the following error:
javax.xml.transform.TransformerException: com.sun.org.apache.xml.internal.utils.WrappedRuntimeException: Invalid byte 2 of 3-byte UTF-8 sequence.
Here is the code i am using.
String transformedMessage = "";
ByteArrayInputStream bais = null;
try {
bais = new ByteArrayInputStream(
inputMessage.getBytes("iso-8859-1"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
StreamSource xsltSource = new StreamSource(
new ByteArrayInputStream(xsltTemplate.getBytes()));
StreamSource source = new StreamSource(bais,"iso-8859-1");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
StreamResult result = new StreamResult(baos);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(xsltSource);
transformer.transform(source, result);
transformedMessage = baos.toString();
return transformedMessage;
inputMessage has the Name tag with the name "Olá" (Related Hex decimals : 4f 6c e1), whcih is in portuguese.
The same code is working if we send Chinese and Thai Characters. Can you please help me with this error?
Heres the sample XMl that i am using.
<?xml version="1.0" encoding="UTF-8"?><TransactionProcessor> <Request> <MessageData> <MessageType>Authorization</MessageType> <IPAddress>187.150.23.80</IPAddress> <IssueDate>20150715</IssueDate> <TravelAgencyName>Sindicato Olá</TravelAgencyName> <TravelDate>20150716</TravelDate> <IssuingCarrierCode>IJ</IssuingCarrierCode> </TransactionData> </Request> </TransactionProcessor>