| Author | 
		  Message
		 | 
		
		  | Murali Gopal | 
		  
		    
			  
				 Posted: Mon Aug 21, 2006 8:00 pm    Post subject: How to read and write MQRFH2 Header coming from MQMessage | 
				     | 
			   
			 
		   | 
		
		
		   Newbie
 
 Joined: 21 Aug 2006 Posts: 6
  
  | 
		  
		    
			  
				Hi friends
 
 
             I  am having one requirement to parse MQRFH2 header coming from IBM Message broker  created by ESQL.  I have to parse the MQRFH2 header and get the <usr> <mcd>  and <psc> folders  in MQRFH2 header.
 
 
I have not found any classes for this in MQ Message. In JMS message there is some options to do that using setJMSType ( for mcd Folder ) and setProperty methods for <usr> folder . But i have not supposed to use that. Because Message Broker not supports JMS Message .
 
 
 
But it is not showing how to get the varibale portions of MQRFH2 Headers like <usr> <mcd> .
 
 
Can any one help me regarding this.
 
 
Thanks & Regards
 
K.Murali gopal
 
Tata Consultancy Services. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Vitor | 
		  
		    
			  
				 Posted: Tue Aug 22, 2006 12:10 am    Post subject: Re: How to read and write MQRFH2 Header coming from MQMessag | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA 
  | 
		  
		    
			  
				
   
	| Murali Gopal wrote: | 
   
  
	 Because Message Broker not supports JMS Message .
 
 | 
   
 
 
 
Yes it does - the MQMD & RFH2 map onto the JMS header. Check the "Using Java" manual.    
 
 
Happy Reading    _________________ Honesty is the best policy.
 
Insanity is the best defence. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Murali Gopal | 
		  
		    
			  
				 Posted: Tue Aug 22, 2006 1:31 am    Post subject: How to read and write MQRFH2 Header coming from MQMessage | 
				     | 
			   
			 
		   | 
		
		
		   Newbie
 
 Joined: 21 Aug 2006 Posts: 6
  
  | 
		  
		    
			  
				Hi Vitor
 
 
         My requirement is , i am receiving the MQMessage generated by ESQL. I have to parse RFH2 header and then put the header information into another MQMessage not JMSMessage.
 
 
I am not supposed to use JMSMessage. I found one link similar to this in the MQ forum.
 
The link is 
 
 
http://mqseries.net/phpBB2/viewtopic.php?p=37597&sid=1a239a6d47053286cf1f0210178b43c0
 
 
But there is not mentioned how to get the variable portion of MQRFH2 header. (<usr> <mcd> Folders). In the code , it is reading like a byte by byte.
 
 
 
Can you help me regarding this.
 
 
Thanks& Regards
 
K.Murali gopal. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Vitor | 
		  
		    
			  
				 Posted: Tue Aug 22, 2006 1:42 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA 
  | 
		  
		    
			  
				Ok, before we start the standard disclaimer - I write "Hello World" level Java programs. Bear this in mind.    
 
 
An MQ message (in the context I think you're using the term) is a JMS message with no header (TargClient = 1). So that sorts that out.
 
 
As to the variable portion of the RFH2, the header contains a length but it is part of the message payload. Hence it's the responsibility of the application code (AFAIK) to read it. Where I've seen it done, it's been done as you suggest byte by byte in a kind of poor man's parser (it's never very long so the efficientcy is not a problem) or it's been fed to a commercial (or freebe downloaded) XML parser. I'm not aware of an inbuilt class that handles it. _________________ Honesty is the best policy.
 
Insanity is the best defence. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | jefflowrey | 
		  
		    
			  
				 Posted: Tue Aug 22, 2006 2:29 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Grand Poobah
 
 Joined: 16 Oct 2002 Posts: 19981
  
  | 
		  
		    
			  
				Also, Message Broker does support JMS Messages - in that it can fully and automatically process any message with an MQRFH2 header.
 
 
It's been able to do that since at least MQSI 2.1.
 
 
So go ahead and use JMS.
 
 
In v6 of message broker, you can also use the JMSInput/JMSOutput nodes to process JMS messages more "natively".  But it's kind of silly to use those for MQ when you've got the MQInput/MQOutput nodes that provide native support. _________________ I am *not* the model of the modern major general. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Vitor | 
		  
		    
			  
				 Posted: Tue Aug 22, 2006 2:33 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA 
  | 
		  
		    
			  
				
   
	| Vitor wrote: | 
   
  
	
 
 
   
	| Murali Gopal wrote: | 
   
  
	| Because Message Broker not supports JMS Message | 
   
 
 
 
Yes it does | 
   
 
 
 
   
	| jefflowrey wrote: | 
   
  
	| Also, Message Broker does support JMS Messages - in that it can fully and automatically process any message with an MQRFH2 header. | 
   
 
 
 
There is definately an echo in here.....    _________________ Honesty is the best policy.
 
Insanity is the best defence. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | fjb_saper | 
		  
		    
			  
				 Posted: Tue Aug 22, 2006 2:34 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 18 Nov 2003 Posts: 20768 Location: LI,NY 
  | 
		  
		    
			  
				Depending on your application needs you can have following happen:
 
 
- Preferred: Have the broker strip the RFH header from the message  before sending...
 
 - Write a little application (JMS)that picks up any message from that queue and writes it to another queue defined with the addendum("?targetClient=1")
 
 - Use the XMS support pack to read the messages
 
 - Strip the RFH header by discarding the number of bytes as defined in the header length field from the message
  
 
 
Enjoy    _________________ MQ & Broker admin | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Murali Gopal | 
		  
		    
			  
				 Posted: Tue Aug 22, 2006 3:17 am    Post subject: How to read and write MQRFH2 Header coming from MQMessage | 
				     | 
			   
			 
		   | 
		
		
		   Newbie
 
 Joined: 21 Aug 2006 Posts: 6
  
  | 
		  
		    
			  
				Hi
 
 
     My requirement is to Strip the RFH header by discarding the number of bytes as defined in the header length field from the MQ message.
 
 
I have to do this using the Class MQMessage (com.ibm.mq jar file ) in MQ 5.1.
 
 
I am not supposed to use JMS. I have to use only core java and MQ.
 
 
 
I have to strip the <usr> <mcd> folders in MQRFH2 which has been set by ESQL. 
 
 
The RFH2 header is not part of the XML Payload so , i cant use any parser like jdom.
 
 
Can any one send me a code for strip down the RFH2 header using java.
 
 
 
Thanks & Regards
 
K.Murali gopal | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | jefflowrey | 
		  
		    
			  
				 Posted: Tue Aug 22, 2006 4:09 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Grand Poobah
 
 Joined: 16 Oct 2002 Posts: 19981
  
  | 
		  
		    
			  
				Please re-read the MQ API specification.  It's very easy to read a certain number of bytes past the start of the message. _________________ I am *not* the model of the modern major general. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | bower5932 | 
		  
		    
			  
				 Posted: Tue Aug 22, 2006 6:39 am    Post subject: Re: How to read and write MQRFH2 Header coming from MQMessag | 
				     | 
			   
			 
		   | 
		
		
		    Jedi Knight
 
 Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA 
  | 
		  
		    
			  
				
   
	| Murali Gopal wrote: | 
   
  
	| I have to do this using the Class MQMessage (com.ibm.mq jar file ) in MQ 5.1. | 
   
 
 
 
If you are really using MQ 5.1, I'd suggest that you move forward to at least 5.3 and probably 6.0. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Murali Gopal | 
		  
		    
			  
				 Posted: Sun Aug 27, 2006 8:05 pm    Post subject: How to attach MQRFH2 header to an XML MQ Message | 
				     | 
			   
			 
		   | 
		
		
		   Newbie
 
 Joined: 21 Aug 2006 Posts: 6
  
  | 
		  
		    
			  
				Hi
 
 
   I am parsing RFH2 Header by reading a byte message coming as a MQ mesage attached with XML.
 
 
I have to post another XML to the MQ with the same parsed RFH2 header.
 
 
I am writing the Header to XML Like,
 
 
 mqMessage.format = MQC.MQFMT_RF_HEADER_2;    // Msg Format
 
 mqMessage.writeString(MQC.MQRFH_STRUC_ID);    // StrucId
 
 mqMessage.writeInt4(MQC.MQRFH_VERSION_2);    // Version
 
 mqMessage.writeInt4(MQC.MQRFH_STRUC_LENGTH_FIXED_2 +      rfh2Header.length() * 4 );   // StrucLength
 
 mqMessage.writeInt4(MQC.MQENC_NATIVE);        // Encoding
 
 mqMessage.writeInt4(MQC.MQCCSI_DEFAULT);    // CodedCharacterSetId
 
mqMessage.writeString(MQC.MQFMT_NONE);        // Format (content)
 
mqMessage.writeInt4(MQC.MQRFH_NO_FLAGS);    // Flags
 
mqMessage.writeInt4(1208);    // NameValueCCSID = UTF-8
 
 //now write folders and their content
 
 mqMessage.writeString(rfh2Header);
 
 mqMessage.writeBytes(responseMessage);
 
               
 
 mqQueue.put(mqMessage, aMQPutMessageOptions);  
 
 
But the the another part that is , the Message Broker application is not understanding or unable to parse the RFh2 header as Mq Message. 
 
 
Here RFH2Header is created by string concatenation.
 
 
 
can any one post how to write this RFH2 header as a header to  XML ?
 
 
Thanks & Regards
 
K.Murali gopal | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | fjb_saper | 
		  
		    
			  
				 Posted: Sun Aug 27, 2006 8:27 pm    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 18 Nov 2003 Posts: 20768 Location: LI,NY 
  | 
		  
		    
			  
				The MQRHF structure (1 and 2) is defined in the documentation. Like all (additional) headers it is just a number of bytes at the start of the message before the actual payload. If you need to move it to an xml structure I would have thought to keep it as CDATA but his is entirely up to you.
 
 
Remember the rules. If you suppress the header you have to adjust the previous header for format, ccsid and encoding....
 
 
Enjoy    _________________ MQ & Broker admin | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Murali Gopal | 
		  
		    
			  
				 Posted: Mon Aug 28, 2006 12:07 am    Post subject: How to write RFH2 header in the XML MQ message | 
				     | 
			   
			 
		   | 
		
		
		   Newbie
 
 Joined: 21 Aug 2006 Posts: 6
  
  | 
		  
		    
			  
				Hi
 
   i am posting XML message with RFH2 header to the MQ using RFHUtil in message broker .  Then I am reading it as a Byte message and then parsing it and writhing to the another Queue with the Different XML and Same RHH2 header .
 
 
But my stub application  is adding RFH2 header as part of XML . RFH2Util  is displaying header  , above the XML message when reading it.
 
 
Can u post how to separate RFH2 header information in XML as the Real header information
 
 
Regards
 
K.Murali gopal. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | fjb_saper | 
		  
		    
			  
				 Posted: Mon Aug 28, 2006 2:31 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand High Poobah
 
 Joined: 18 Nov 2003 Posts: 20768 Location: LI,NY 
  | 
		  
		    
			  
				Define stub application?    _________________ MQ & Broker admin | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | Murali Gopal | 
		  
		    
			  
				 Posted: Mon Aug 28, 2006 3:23 am    Post subject: How to write/attach RFH2 Header to XML MQ message | 
				     | 
			   
			 
		   | 
		
		
		   Newbie
 
 Joined: 21 Aug 2006 Posts: 6
  
  | 
		  
		    
			  
				Hi
 
 
 
   The stub is a java application which is constantly looking in to one queue. Whatever message with RFH2 header is coming inside a queue  it will pick the message and parse the RFH2 header and post the another message which contains the another static XML with the above parsed RFH2 header string.
 
 
I am  reading MQ Message from  the Request queue and getting a byte message and converting it to string and parsing the RFH2 header using IndexOf Function in java.  
 
 
I am using the following code to write the String RFH2 header and Static String XML message.
 
 
ByteArrayOutputStream bstream = new ByteArrayOutputStream();
 
                DataOutputStream ostream = new DataOutputStream (bstream);
 
                
 
                String strVariableData = rfh2Header;
 
                int iStrucLength = MQC.MQRFH_STRUC_LENGTH_FIXED_2 +
 
                strVariableData.getBytes().length;
 
                while(iStrucLength % 4 != 0)
 
                {
 
                strVariableData = strVariableData + " ";
 
                iStrucLength = MQC.MQRFH_STRUC_LENGTH_FIXED_2 +
 
                strVariableData.getBytes().length;
 
                }
 
                
 
                ostream.writeChars(MQC.MQFMT_RF_HEADER_2);//RFH2 header
 
                ostream.writeChars(MQC.MQRFH_STRUC_ID);//StrucID
 
                ostream.writeInt(MQC.MQRFH_VERSION_2);//Version
 
                ostream.writeInt(iStrucLength );//StrucLength
 
                ostream.writeInt(MQC.MQENC_NATIVE);//Encoding
 
                ostream.writeInt(MQC.MQCCSI_DEFAULT);//CodedCharSetID
 
                ostream.writeChars("MQSTR");//Format
 
                ostream.writeInt(MQC.MQRFH_NO_FLAGS);//Flags
 
                ostream.writeInt(1208);//NameValueCCSID
 
                ostream.writeInt(strVariableData.getBytes().length);//NameValueLength
 
                ostream.writeChars(strVariableData ); //NameValueData
 
                ostream.flush();
 
                byte[] bArr = bstream.toByteArray();
 
                            
 
                mqMessage.write(bArr);
 
                
 
                mqMessage.writeString(responseMessage.trim());
 
               
 
                mqQueue.put(mqMessage, aMQPutMessageOptions);  
 
 
 
I am  getting the Result as RFH2 header is appended above the XML message. RFH2UTIL  is not able to seperate the RFH2 header.
 
 
 
Regards
 
K.Murali gopal | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | 
		    
		   |