Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
Posts: 8
Registered: ‎09-01-2010
My Device: Not Specified
Accepted Solution

cp1252 encoding

Hi,

 

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.

 

 

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: cp1252 encoding

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.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
New Contributor
Posts: 8
Registered: ‎09-01-2010
My Device: Not Specified

Re: cp1252 encoding

Hi Ted,

 

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

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: cp1252 encoding

You can try adding the header "x-rim-transcode-content" with value "none" to both the request and the response. That might help.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
New Contributor
Posts: 8
Registered: ‎09-01-2010
My Device: Not Specified

Re: cp1252 encoding

Hi Ted,

 

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!

 

 

 

 

Highlighted
Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: cp1252 encoding

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.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.