|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
MQ V7 writeString converting Hex chars to 3F (Important) |
« View previous topic :: View next topic » |
Author |
Message
|
deepjyot |
Posted: Mon Mar 12, 2012 7:29 pm Post subject: MQ V7 writeString converting Hex chars to 3F (Important) |
|
|
Novice
Joined: 29 Jul 2009 Posts: 11
|
We were using writeBytes method with MQ V6, but now that it is deprecated we changed our code to use writeString with MQ V7.
Problem Statement - The writeString method is converting some international characters to 0x3F i.e. ?
For Example - Hex characters like A0, A1, etc. are getting converted to 3F
Please advice!
Code snippet -
mqMessage.encoding = MQConstants.MQENC_NATIVE;// 546
mqMessage.format = Constants.MQ_MESSAGE_FORMAT;
// mqMessage.characterSet = 437; //
mqMessage.writeString(RFH_STRING);
mqMessage.writeInt(2);
StringBuffer rfh2 = new StringBuffer(Constants.USR_TAG_START);
rfh2.append(messageVO.getRFH2()).append(Constants.USR_TAG_END);
StringBuffer padUsrRFH2 = usrPad(rfh2);
LoggingUtil.logMessage(log, "padUsrRFH2.toString()-->"
+ padUsrRFH2.toString(), LOG_LEVEL_DEBUG);
LoggingUtil.logMessage(log, "padUsrRFH2.length()-->"
+ padUsrRFH2.length(), LOG_LEVEL_DEBUG);
mqMessage.writeInt(40 + padUsrRFH2.length()); // struct
mqMessage.writeInt(MQConstants.MQENC_NATIVE); // encoding
mqMessage.writeInt(MQConstants.MQCCSI_INHERIT); // CodedCharSetId
mqMessage.writeString(" "); // format
mqMessage.writeInt(0); // flags
mqMessage.writeInt(1208); // valueCCID
mqMessage.writeInt(padUsrRFH2.length());
mqMessage.writeString(padUsrRFH2.toString());
Thanks,
DJ |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Mar 12, 2012 8:28 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Make the message CCSID 1208 and the content UTF-8! Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
deepjyot |
Posted: Mon Mar 12, 2012 8:59 pm Post subject: |
|
|
Novice
Joined: 29 Jul 2009 Posts: 11
|
Thanks for your reply!
I already have CCSID as 1208... can u suggest a change on the code snippet i have posted?
FYI, I also used mqMessage.characterSet = 1208; but that added 2 more hex characters. |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Mar 13, 2012 12:03 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
deepjyot wrote: |
Thanks for your reply!
I already have CCSID as 1208... can u suggest a change on the code snippet i have posted?
FYI, I also used mqMessage.characterSet = 1208; but that added 2 more hex characters. |
Well, looking at your code, your format is wrong... it should be something like MQC.MQFMT_RFH2... you'd have to check it against the new Constants class... and by the way why are you building the RFH from scratch? Use XMS as it comes with the product... or the V7 style properties as you are using V7 classes... (Constants.)...
And your message CCSID is not what you expect. Verify the meaning of
Code: |
mqMessage.writeInt(MQConstants.MQCCSI_INHERIT); // CodedCharSetId |
 _________________ MQ & Broker admin |
|
Back to top |
|
 |
deepjyot |
Posted: Tue Mar 13, 2012 12:15 am Post subject: |
|
|
Novice
Joined: 29 Jul 2009 Posts: 11
|
The format is set to MQC.MQFMT_RFH2 in the Constants class, hence this shouldn't be a problem.
We have been using this code since MQ V5 and we don't want to make major changes at this point for migrating to MQ V7.  |
|
Back to top |
|
 |
rekarm01 |
Posted: Tue Mar 13, 2012 1:42 am Post subject: Re: MQ V7 writeString converting Hex chars to 3F (Important) |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 1415
|
deepjyot wrote: |
Hex characters like A0, A1, etc. are getting converted to 3F |
A0 and A1 look like hex bytes, not hex characters. What are the actual characters, and for which ccsid?
If a character does not exist in a given ccsid's character set, then a converter can't map that character to bytes; it may substitute some other byte sequence instead (such as 3F).
For NameValueData, writeBytes() would not handle international characters correctly either. That's why it's deprecated.
deepjyot wrote: |
mqMessage.writeInt(40 + padUsrRFH2.length()); // struct |
padUsrRFH2.length() needs to calculate the byte length (after conversion), not the character length (before conversion).
deepjyot wrote: |
mqMessage.writeString(padUsrRFH2.toString()); |
writeString() uses mqMessage.characterSet to convert, not NameValueCCSID. If these are different, then writeString() won't work here.
The simplest thing to do at this point, (aside from using XMS or V7 properties) is to use an alternate method (such as java.lang.String.getBytes(String charsetName)) to convert the NameValueData, adjust the padding and length calculations as needed, then use MQMessage.write(byte[]) to write it. |
|
Back to top |
|
 |
Vitor |
Posted: Tue Mar 13, 2012 4:48 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
deepjyot wrote: |
We have been using this code since MQ V5 and we don't want to make major changes at this point for migrating to MQ V7.  |
Without taking anything away from the comments of my most worthy associates, can I also point out that a lot has changed between MQv5 & WMQv7? Not least the rebranding as part of Websphere?
While I fully understand your desire not to make unnecessary changes, there comes a point where you just have accept the passing of time. I offer into evidence the introduction of message properties in WMQv7 which heralds the end of the RFH2 as we know it.
At some point you're going to need to review this code. It might be better to do it sooner rather than later; imagine if you open the "What's New in WMQv8" and discover that the RFH2 has been removed? Isn't that a change you'd sooner make when the migration clock isn't ticking? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|