09-01-2010 12:19 PM
I'm developing an application using JDE 4.2.1. The app communicates with http Post sending an XML content encoded with ISO-8859-1 and receives another XML encoded with cp1252 (windows-1252 encoding). I can't change the encoding in the response so I need to "recode" it to ISO-8859-1 to parse it.
I found that the conversion between these encodings has a problem with some characters, including '<' and '>', so I can't parse it properly.
I receive the information in a InputStream which I read with InputStream.available and write each byte in a ByteArrayOutputStream. Then I transform transform it into String this way:
String xmlFile = new String(out.toByteArray(), "cp1252");
If I print it in the console those conflicting characters are not well printed, so I'm starting to think that the "cp1252" encoding is not supported by default. Am I right?
Is there any way to transform an String containing the xmlFIle encoded with cp1252 to another String encoded with ISO-8859-1?
Thanks in advance.
Solved! Go to Solution.
09-01-2010 01:33 PM
ISO-8859-1 and windows-1252 are identical except for the byte ranges 0x7F through 0x9F. Both of them (and UTF-8, for that matter) encode '<' as 0x2C and '>' as 0x2E. I'm surprised that you are having trouble with those two characters.
Can you provide an example of a byte stream that is giving problems?
One way to deal with this is to implement your own InputStream subclass that wraps the original stream and transforms the bytes that are in the problem range. It's not too difficult, but it is a nuisance.
09-08-2010 02:58 AM
Althought I've not solved the problem yet, I've found that it's not related with the encoding of the String.
The byte stream starts like this:
text/html???? ????J????kunde laguntzaileak egindako diru sarreraren ziurtagiriaren bidez
The problem lies in the http response, encoded with a Content-Type: text/html, and we identified that the BES treats it as an HTML response and transforms it into those weird bytes.
We also found that the 'transcoded' response from the BES has a smaller size than the original response.
Thanks for your reply
09-08-2010 03:04 AM
You can try adding the header "x-rim-transcode-content" with value "none" to both the request and the response. That might help.
09-08-2010 07:55 AM
Adding the header solved the problem and now I can parse the xml correctly.
This behavior of transcoding the text/html messages can be forced in a BES so it ignores the header? Or adding the header will make it work in 100% of requests?
Thanks a lot!
09-08-2010 09:06 AM
As I understand it, it should always work for transcoding done by BES. Carriers sometimes do their own transcoding, though, and the RIM-specific header won't have any effect on that. But it sounds like that's not your issue now.