|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
create and populate message with MQRFH2 header from java |
« View previous topic :: View next topic » |
Author |
Message
|
datspats |
Posted: Fri Apr 13, 2007 5:10 am Post subject: create and populate message with MQRFH2 header from java |
|
|
Voyager
Joined: 12 Apr 2007 Posts: 80 Location: Mumbai
|
Hi all,
I want create and populate message with MQRFH2 header from java program and put on queue and I want to put any data e.g. filename into <usr> folder of the MQRFH2 header.
e.g. <usr><filename>abc.txt<filename><usr>
the piece code as below
byte[] strDatabytes = strRecord.getBytes();
//strRecord is actual payload
String s1 = "";
s1 = s1.concat("<mcd>");
s1 = s1.concat("</mcd>");
String s2 = "";
s2 = s2.concat("<jms>");
s2 = s2.concat("</jms>");
String s = "";
s = s.concat("<usr>");
s = s.concat("<filename>");
s = s.concat("abc.txt");
s = s.concat("</filename>");
s = s.concat("<fileDATE>");
s = s.concat("13-April-2007");
s = s.concat("</fileDATE>");
s = s.concat("</usr>");
int rfhStrucLength = 0;
rfhStrucLength += MQC.MQRFH_STRUC_LENGTH_FIXED_2;
while(s1.getBytes().length % 4 != 0) {
s1 += " ";
}
rfhStrucLength += s1.getBytes().length;
while(s2.getBytes().length % 4 != 0) {
s2 += " ";
}
rfhStrucLength += s2.getBytes().length;
while(s.getBytes().length % 4 != 0) {
s += " ";
}
rfhStrucLength += s.getBytes().length;
//rfhStrucLength += 12; //for storing namevalue length
rfhStrucLength += strDatabytes.length;
mymsg.format = MQC.MQFMT_RF_HEADER_2;
mymsg.writeString(MQC.MQRFH_STRUC_ID); //StrucID
mymsg.writeInt4(MQC.MQRFH_VERSION_2); //Version
mymsg.writeInt4(rfhStrucLength); //StrucLength
mymsg.writeInt4(MQC.MQENC_NATIVE); //Encoding
mymsg.writeInt4(MQC.MQCCSI_INHERIT); //CodedCharSetID
mymsg.writeString(MQC.MQFMT_NONE); //Format
mymsg.writeInt4(MQC.MQRFH_NO_FLAGS); //Flags
mymsg.writeInt4(1208); //NameValueCCSID*/
mymsg.writeInt4(s1.getBytes().length); //NameValueLength <mcd>
mymsg.writeString(s1); //NameValueData <mcd>
mymsg.writeInt4(s2.getBytes().length);//NameValueLength <jms>
mymsg.writeString(s2); //NameValueData <jms>
mymsg.writeInt4(s.getBytes().length);//NameValueLength <usr>
mymsg.writeString(s); //NameValueData
mymsg.write(strDatabytes); //Actual Message Data
myqueue.put(mymsg,pmo); //putting message on queue
Please let me know where I m going wrong as When I read the message from queue using "rfhutil" I don't get the require payload (actual) in the data section. I also get the warning message from rfhutil as invalid length rfh header area while reading the message from queue. But i can see <usr> folder populated with required details.
waiting for response.
Thanks & Regards |
|
Back to top |
|
 |
Vitor |
Posted: Fri Apr 13, 2007 5:19 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
It's considered somewhat rude to double post
http://www.mqseries.net/phpBB2/viewtopic.php?t=36302
Have you considered using JMS, which handles the RFH2 under the covers?
If not, have you considered searching the forum? There was a discussion about this a while back & IIRC someone posted some helper code that might act as a basis for what you're trying.
You might also want to take another look at your length calculation code. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
speediii |
Posted: Fri Apr 13, 2007 6:08 am Post subject: Solution! |
|
|
Novice
Joined: 11 Apr 2006 Posts: 19
|
Hi,
You found the same bug as I did later with my code after I had posted it
There's a mistake on this line:
rfhStrucLength += rfhDataBytes.length;
Comment this line out - I found out later that the struct length field does NOT contain the length of the trailing message data, i.e. the file you wish to place after the RFH2 Header, XML (mcd, usr etc) section...
Sorry about that!
Hope this helps... |
|
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
|
|
|
|