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 » RFH2 Header using java

Post new topic  Reply to topic
 RFH2 Header using java « View previous topic :: View next topic » 
Author Message
raja_no_1
PostPosted: Thu Nov 20, 2008 2:23 am    Post subject: RFH2 Header using java Reply with quote

Apprentice

Joined: 05 Sep 2005
Posts: 34

Hello there!

I am trying to write RHF2 Header using java on a given message.. Having searched this forum I found some snippents of code which should work but unfortunately it doesnt.

I am trying this on windows XP. Can someone please guide me as to where I am going wrong.

I am getting the error => Completeion code 2 Reason code 2334

Which translates to =>
2334 0x0000091e MQRC_RFH_ERROR


============== CODE ===================


import com.ibm.mq.*;
import java.io.*;

public class SimplePut {

private static MQQueueManager qMgr;

public SimplePut() {
super();
}

public static void main(String args[]) {
try {
// create a new instance of the sample program
SimplePut mSender = new SimplePut();

//Queue Maneger name

qMgr = new MQQueueManager("TEST_QUEUEMANAGER");
//Queue Name
String queueName = "INPUT_QUEUE";

int openOptions =MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING | MQC.MQOO_SET | MQC.MQOO_INPUT_AS_Q_DEF ;
MQQueue q = qMgr.accessQueue(queueName,
openOptions, null, null, null);

// call method to send messages
mSender.mPut(qMgr, q);
System.out.println("Message Sent");

// clean up connection
q.close();
qMgr.disconnect();
// }


} catch (MQException ex) {
System.out.println("MQ exception occurred : Completeion code "
+ ex.completionCode + " Reason code " + ex.reasonCode);
}
}
/**
* This method was created in VisualAge.
*
* @param qMgr - a MQ QueueManager object
* @param q - a MQ Queue object
*
*/

public void mPut( MQQueueManager qMgr, MQQueue q) {
try {

// Define a MQ message buffer

MQMessage outMsg = new MQMessage();
outMsg.format = MQC.MQFMT_STRING ;
try {
//outMsg.writeString("message");
buildRFH2Header(outMsg);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

// create message options
MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept defaults
pmo.options = MQC.MQPMO_NONE; // use defaults

q.put(outMsg, pmo); // put the message out on the queue

} catch (MQException ex) {
System.out.println("MQ exception occurred : Completeion code " +
ex.completionCode + " Reason code " +
ex.reasonCode);
}

}

/**
* @param msg
* @return
* @throws IOException
*/
public MQMessage buildRFH2Header(MQMessage msg) throws IOException {

String pubCommand = new String();

pubCommand = "<psc><Command>Publish</Command><Topic>Stock</Topic>" +

"<QMgrName>QFLEXT1</QMgrName><QName>QFLEXT1.A</QName></psc>";

int folderLength = pubCommand.length();

MQMessage theMsg = msg;

theMsg.format = MQC.MQFMT_RF_HEADER_2; // Msg Format

theMsg.writeString(MQC.MQRFH_STRUC_ID); // StrucId

theMsg.writeInt4(MQC.MQRFH_VERSION_2); // Version

theMsg.writeInt4(MQC.MQRFH_STRUC_LENGTH_FIXED_2 + folderLength * 4);

theMsg.writeInt4(MQC.MQENC_NATIVE); // Encoding

theMsg.writeInt4(MQC.MQCCSI_DEFAULT); // CodedCharacterSetId

theMsg.writeString(MQC.MQFMT_NONE); // Format (content)

theMsg.writeInt4(MQC.MQRFH_NO_FLAGS); // Flags

theMsg.writeInt4(1208); // NameValueCCSID = UTF-8

theMsg.writeInt4(folderLength);

theMsg.writeString(pubCommand);

theMsg.writeString("begin payload");

return theMsg;

}

}
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Nov 20, 2008 2:28 am    Post subject: Re: RFH2 Header using java Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

raja_no_1 wrote:
Can someone please guide me as to where I am going wrong.


1. You're not using the JMS libraries which will build the RFH2 automatically
2. You're trying to do pub/sub without using the JMS libraries
3. There's a bug in your code - check the Java manual & the APR, especially the positioning of the RFH2 fields.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Nov 20, 2008 2:29 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Moved to Java section
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
raja_no_1
PostPosted: Thu Nov 20, 2008 2:41 am    Post subject: Reply with quote

Apprentice

Joined: 05 Sep 2005
Posts: 34

I do not want to use JMS..because the rest of my code uses MQ base classes..

Can someone guide me whats wrong with the positioning of the rfh fields?
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Nov 20, 2008 2:44 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

raja_no_1 wrote:
I do not want to use JMS..because the rest of my code uses MQ base classes..


Why?
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
raja_no_1
PostPosted: Thu Nov 20, 2008 2:51 am    Post subject: Reply with quote

Apprentice

Joined: 05 Sep 2005
Posts: 34

I dont think you are being very helpful..

I have some more java classes which is using base MQ classes.. and setting of the MQ header is going to be a small part of the existing code which I dont want to change.

Is there a way out using the Base MQ classes?
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Nov 20, 2008 3:31 am    Post subject: Reply with quote

Grand High Poobah

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

If you are not using JMS you are obviously not in a J2EE Applicaton server...
So send your message in base to a specific queue, have it picked up by a JMS program and published... Or do the reverse, subscribe as JMS and send the received topic to a non JMS queue. This will correctly strip the RFH header...

You might also want to do a search on targetClient and look at queue definition through JNDI and URIs

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
JLRowe
PostPosted: Thu Nov 20, 2008 5:27 am    Post subject: Reply with quote

Yatiri

Joined: 25 May 2002
Posts: 664
Location: South East London

raja_no_1 wrote:

Can someone guide me whats wrong with the positioning of the rfh fields?


NO ... go through the code yourself, it's all thoroughly documented, has been asked before many many times, or get hold of some test messages and examine their RFH2 headers.

If you are incapable of a simple task like this, then you are simply in the wrong job
Back to top
View user's profile Send private message Send e-mail
manicminer
PostPosted: Thu Nov 20, 2008 7:09 am    Post subject: Reply with quote

Disciple

Joined: 11 Jul 2007
Posts: 177

Or upgrade to MQ7, then use the java classes to do pub/sub with MQ rather than trying to create the RFH2 header.
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 » RFH2 Header using java
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.