ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » UnsupportedEncodingException when converting NameValueData

Post new topic  Reply to topic
 UnsupportedEncodingException when converting NameValueData « View previous topic :: View next topic » 
Author Message
notoneword
PostPosted: Thu May 19, 2011 5:42 pm    Post subject: UnsupportedEncodingException when converting NameValueData Reply with quote

Apprentice

Joined: 17 May 2011
Posts: 37

Code:
MQRFH2 header ...

String nameValueData = Charsets.convert(header.getNameValueData(), header.getNameValueCCSID()));



I'm getting an UnsupportedEncodingException from this line in one of two cases. The only difference I can tell in the MQRFH2 headers, and the NameValueData itself is that the CodedCharSetId is EBCDIC (37) in the one that succeeds, and ASCII (437) in the one that fails:


Header that doesn't cause the exception when converting the bytes:
MQRFH2 (com.ibm.mq.headers.internal.store.MQMessageStore [encoding: 0x00000111, ccsid: 437])
Code:
MQCHAR4 StrucId: "RFH "
   MQLONG Version: 2 (0x00000002)
   MQLONG StrucLength: 376 (0x00000178)
   MQLONG Encoding: 546 (0x00000222)
   MQLONG CodedCharSetId: 37 (0x00000025)
   MQCHAR8 Format: "        "
   MQLONG Flags: 0 (0x00000000)
   MQLONG NameValueCCSID: 1208 (0x000004b8)
   MQBYTE[] NameValueData: 0x000001503c7573723e3c424f4f4c312064743d27626f6f6c65616e2720737570706f72743
d2730303030303030302720636f70793d276e6f6e65273e303c2f424f4f4c313e3c494e5438
312064743d2769312720737570706f72743d2730303030303030302720636f70793d276e6f
6e65273e33323c2f494e5438313e3c494e543634312064743d2769382720737570706f7274
3d2730303030303030302720636f70793d276e6f6e65273e3332303030303c2f494e543634
313e3c464c543634312064743d2772382720737570706f72743d2730303030303030302720
636f70793d276e6f6e65273e312e313233353637383839393939393939393c2f464c5436343
13e3c5354523120737570706f72743d2730303030303030302720636f70793d276e6f6e6527
3e6162646365713233667061716977736a65666173646661736466613c2f535452313e3c2f7573723e2020



Header that does throw the exception when converting the bytes:
MQRFH2 (com.ibm.mq.headers.internal.store.MQMessageStore [encoding: 0x00000111, ccsid: 437])
Code:
MQCHAR4 StrucId: "RFH "
   MQLONG Version: 2 (0x00000002)
   MQLONG StrucLength: 288 (0x00000120)
   MQLONG Encoding: 546 (0x00000222)
   MQLONG CodedCharSetId: 437 (0x000001b5)
   MQCHAR8 Format: "        "
   MQLONG Flags: 0 (0x00000000)
   MQLONG NameValueCCSID: 1208 (0x000004b8)
   MQBYTE[] NameValueData: 0x000000f83c7573723e3c5448495349534d5953545220737570706f72743d273030303030303030
2720636f70793d276e6f6e65273e4654573f213c2f5448495349534d595354523e3c5448495349534
d59425954455354522064743d2762696e2e6865782720737570706f72743d273030303030303030
2720636f70793d276e6f6e65273e3031303230333034303531463c2f5448495349534d5942595445
5354523e3c5448495349534d593634464c4f41542064743d2772382720737570706f72743d273030303030303030
2720636f70793d276e6f6e65273e3132332e3332313c2f5448495349534d593634464c4f41543e3c2f7573723e2020


So, in both cases the CCSID being passed to Charsets.convert is 1208.

? Any idea why the difference here, and/or what I should be doing to correctly convert these bytes?

thanks
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu May 19, 2011 7:00 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
Location: LI,NY

This is no unexpected thing. Which part of CCSID conversion did you not understand?

Why are you using a charsets.convert method when all you need is something like String(byte[], "UTF-8" ).

The code clearly states that the nameValueData is already in CCSID 1208.
There is no conversion required. In fact a conversion might hurt the data.

Now you need to ask yourself and verify on hand of the hex values if the data being passed is effectively UTF-8 or CCSID 1208 as specified in the RFH2 header... Maybe that is where the problem is.

By the way, which version of Java gives you the Charsets.convert(byte[], int) method? or did you mean to say String (byte[], String)?

Here is what the Java API tells us:

Quote:
String

public String(byte[] bytes,
String charsetName)
throws UnsupportedEncodingException

Constructs a new String by decoding the specified array of bytes using the specified charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the byte array.

The behavior of this constructor when the given bytes are not valid in the given charset is unspecified. The CharsetDecoder class should be used when more control over the decoding process is required.

Parameters:
bytes - The bytes to be decoded into characters
charsetName - The name of a supported charset
Throws:
UnsupportedEncodingException - If the named charset is not supported

Since:
JDK1.1



Are you passing 1208 instead of UTF-8 to some decoder?
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
rekarm01
PostPosted: Thu May 19, 2011 9:24 pm    Post subject: Re: UnsupportedEncodingException when converting NameValueDa Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 1415

notoneword wrote:
I'm getting an UnsupportedEncodingException from this line ...
Code:
String nameValueData = Charsets.convert(header.getNameValueData(), header.getNameValueCCSID()));

What evidence indicates that this line is the one throwing the UnsupportedEncodingException?

It might help to display the value of header.getNameValueCCSID() before calling the convert method.

The com.ibm.mq.headers.CCSID.getCCSIDs() returns an Enumeration of supported ccsids.

notoneword wrote:
Code:
MQBYTE[] NameValueData: 0x00000150...

Code:
MQBYTE[] NameValueData: 0x000000f8...

The first eight bytes displayed of are actually part of NameValueLength, not NameValueData[].

fjb_saper wrote:
By the way, which version of Java gives you the Charsets.convert(byte[], int) method?

That's probably com.ibm.mq.headers.Charsets.convert(byte[] bytes, int ccsid);
Back to top
View user's profile Send private message
notoneword
PostPosted: Fri May 20, 2011 4:40 am    Post subject: Reply with quote

Apprentice

Joined: 17 May 2011
Posts: 37

Quote:

That's probably com.ibm.mq.headers.Charsets.convert(byte[] bytes, int ccsid);


DING!DING!DING!:


Quote:
public static String convert(byte[] bytes,
int ccsid)
throws UnsupportedEncodingException

Converts byte array content in the specified CCSID into a Java String.



It's definitely that line throwing the exception, I put the try/catch around just that line and caught it.

As for whether the CCSID is supported or not, I can check, but 1208 does seem to work in one case, so I was assuming (I know) that it was supported.

Quote:
It might help to display the value of header.getNameValueCCSID() before calling the convert method.


Those printouts of the MQRFH2 instances are from right before the convert call, so I'm fairly certain that nameValueCCSID is 1208.

It's a hack, but to see if it worked, I simply caught the exception then passed the byte[] to a String constructor and it displayed fine.

Thanks for the replies and suggestions.
Back to top
View user's profile Send private message
notoneword
PostPosted: Fri May 20, 2011 5:47 am    Post subject: Reply with quote

Apprentice

Joined: 17 May 2011
Posts: 37

It would seem that the bytes that throw the exception contain characters that aren't supported in 1208, is that a reasonable assumption?

If it is, then I guess my main questions is why would the NameValueCCSID be 1208 in that case?
Back to top
View user's profile Send private message
rekarm01
PostPosted: Sun May 22, 2011 1:54 pm    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 1415

notoneword wrote:
It would seem that the bytes that throw the exception contain characters that aren't supported in 1208, is that a reasonable assumption?

Probably not. Java provides a different exception for that.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » UnsupportedEncodingException when converting NameValueData
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.