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 » General IBM MQ Support » issue : To set Filename alongwith MQRFH2 Header and msg data

Post new topic  Reply to topic
 issue : To set Filename alongwith MQRFH2 Header and msg data « View previous topic :: View next topic » 
Author Message
vinayanshul
PostPosted: Wed Mar 02, 2016 9:07 pm    Post subject: issue : To set Filename alongwith MQRFH2 Header and msg data Reply with quote

Newbie

Joined: 02 Mar 2016
Posts: 1

Hi All,

I have requirement to set "FileName" with RFh2 header and append with message data like below output, How to achieve this using Java MQ or JMS Programming? I can add the filename by setNameValueString , but it doesn't work at client side Error Msg is related with : rfhStructLength ,
We got error message at client side:
Failure in BridgeMQSeries.parseMQRFHMessage()rfhStructLength not large enough to handle fileName value

Output Should look like -->

RFH ......Γ▄..."   ■MQSTR .......╕...@ STMT_20151029150003_1169709901.pdf.................Γp%PDF-1.5

--------DATA OUTPUT---On MQ8 - Message Browser----------

00000 52 46 48 20 00 00 00 02--00 01 AC 8C 00 00 02 22 |RFH ......¼î..."|
00010 FF FF FF FE 4D 51 53 54--52 20 20 20 00 00 00 00 |   ■MQSTR ....|
00020 00 00 04 B8 00 00 00 30--53 54 4D 54 5F 32 30 31 |...╕...0STMT_201|
00030 36 30 31 33 30 30 39 31--32 32 31 5F 31 30 32 32 |60130091221_1022|
00040 34 35 30 31 30 31 2E 70--64 66 00 00 00 00 00 00 |450101.pdf......|
00050 00 00 00 00 00 00 00 00--00 01 AC 30 25 50 44 46 |..........¼0%PDF|
00060 2D 31 2E 35 0D 0A 25 B5--B5 B5 B5 0D 0A 31 20 30 |-1.5
.%╡╡╡╡
.1 0|
---------------------------------------------------------------------------
Tried 2 approached so far, but didn't get luck yet,
1) Using JMS Programming - use header.setNameValueString ..
String fName_without_dir = path.getFileName().toString(); // get File Name
while(fName_without_dir.getBytes().length % 4 != 0) { // for changing the file length with multiplication of 4
fName_without_dir += " ";
}
//+++++++++++++++++++++++++++++++++++++
// 1st way - Simply setting the MQRFH Header – with MQSTR format and File Name
MQRFH header = new MQRFH();
header.setFormat("MQSTR");
header.setNameValueString(fName_without_dir); // set the header name – as File Name
ByteArrayOutputStream out = new ByteArrayOutputStream ();
header.write (new DataOutputStream (out),MQConstants.MQENC_NATIVE, 819); // WMQConstants.WMQ_ENCODING_NATIVE, 819);
byte[] bytes = out.toByteArray ();
byteResponseMessage.writeBytes(bytes);

//byte[] fname = fName_without_dir.getBytes("UTF-8"); // may also add file name into session – bytemessage, if not setting file name above - heder.setNameValueString..
//byteResponseMessage.writeBytes(fname);
//+++++++++++++++++++++++++++++++++++++
// 2nd way - Setter of JMS message property, Format, Encoding, Char Set, etc..
byteResponseMessage.setStringProperty("JMS_IBM_Format", "MQSTR");
byteResponseMessage.setIntProperty("JMS_IBM_Encoding", MQConstants.MQENC_NATIVE); // Encoding - MQConstants.MQENC_REVERSED , value is 546
byteResponseMessage.setIntProperty("JMS_IBM_Character_Set", 1208); // Char Set – 437
byteResponseMessage.setIntProperty("JMS_IBM_PutApplType", 11);
// User setting – Can also set FileName with header, find the attached document
// byteResponseMessage.setStringProperty("FILENAME", fName_without_dir);
// write message into bytes bytemessage
byteResponseMessage.setJMSDeliveryMode(DeliveryMode.PERSISTENT); // for persistent message
byteResponseMessage.writeBytes(bArray);
log.debug("Printing IncomingMessage ::::::::::::::::::" + byteResponseMessage);
send.send(byteResponseMessage); // send byteResponseMessage to JMS Destination Q

2) Using WSMQ API
Path path = Paths.get(newFileName);
byte[] bArray = fileByteReader(path);
String fName_without_dir = path.getFileName().toString();
int filelength = fName_without_dir.length();
//byte[] s = fName_without_dir.getBytes("UTF-8");

while(fName_without_dir.getBytes().length % 4 != 0) { // for changing the file length with multiplication of 4
fName_without_dir += " ";
}
int rfhStrucLength;
rfhStrucLength =+ fName_without_dir.getBytes().length;

MQMessage mqsMsg = new MQMessage();
mqsMsg.format = MQConstants.MQFMT_STRING ;//"MQSTR";
// mqsMsg.format = MQC.MQFMT_RF_HEADER; // Msg Format
// mqsMsg.format = MQC.MQFMT_; // Msg Format
mqsMsg.feedback = MQC.MQFB_NONE;
mqsMsg.messageType = MQC.MQMT_DATAGRAM;
mqsMsg.writeString(MQC.MQRFH_STRUC_ID); // StrucId
mqsMsg.writeInt4(MQC.MQRFH_VERSION_1); // Version
// mqsMsg.writeLong(MQC.MQRFH_STRUC_LENGTH_FIXED_2 + filelength + 4); // MQRFH_STRUC_LENGTH_FIXED_2 – is 36 char fixed
mqsMsg.writeLong(rfhStructLenght);
mqsMsg.writeInt4(546); // Encoding - MQC.MQENC_NATIVE
mqsMsg.writeInt4(437); // CodedCharacterSetId - MQC.MQCCSI_DEFAULT
mqsMsg.writeString(MQC.MQFMT_STRING); // Format (content) – “MQSTR “
mqsMsg.writeInt4(MQC.MQRFH_NO_FLAGS); // Flags
mqsMsg.writeInt4(1208); // NameValueCCSID = UTF-8
mqsMsg.writeInt4(filelength);
mqsMsg.writeString(fName_without_dir);

mqsMsg.write(bArray, 0, bArray.length);
int len = mqsMsg.getMessageLength();
System.out.println("len of msg = " + len);
inputQ.put(mqsMsg, pmo);

And my output looks like, Where able to set the Header but somehow, Filename is not getting distinguish/read at client side, As I feel, here I require some ASCII char to separate Filename between header and Data ,
My Output -->
<RFH ..........."....>
<MQSTR ...........0>
<STMT_20160130091220_>
<1022456501.pdf >
<PDF-1.5>

Kindly suggest me where, Am I wrong with above code, while setting the FileName ?
Thanks in advance.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Mar 03, 2016 6:29 am    Post subject: Reply with quote

Grand High Poobah

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

Remember that the RFH requires a 4 byte alignment...
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
mqjeff
PostPosted: Thu Mar 03, 2016 6:33 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

http://www.ibm.com/support/knowledgecenter/SSFKSJ_8.0.0/com.ibm.mq.javadoc.doc/WMQJavaClasses/com/ibm/mq/headers/MQRFH2.html?lang=en


_________________
chmod -R ugo-wx /
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 » General IBM MQ Support » issue : To set Filename alongwith MQRFH2 Header and msg data
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.