This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Websphere and the fly likes Connecting to MQ Series from a java app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "Connecting to MQ Series from a java app" Watch "Connecting to MQ Series from a java app" New topic
Author

Connecting to MQ Series from a java app

jeff mutonho
Ranch Hand

Joined: Apr 30, 2003
Posts: 271
Hi I have this simple java program (code shown below) to connect and get message from an mq series queue.When I run it I get the exception shown below .The message , however disappears from the queue which means the getting is working.I debugged and realize the code is failing on the line "System.out.println("Received message : "+ testRes.readLine()); "
java.io.UnsupportedEncodingException: Cp437
at sun.io.Converters.getConverterClass(Converters.java:121)
at sun.io.Converters.newConverter(Converters.java:152)
at sun.io.ByteToCharConverter.getConverter(ByteToCharConverter.java:81)
at java.io.InputStreamReader.<init>(InputStreamReader.java:93)
at com.ibm.mq.MQMessage.readConvertedLine(MQMessage.java:626)
at com.ibm.mq.MQMessage.readLine(MQMessage.java:475)
at SCVDirect.<init>(SCVDirect.java:52)
at Receiver.main(Receiver.java:18)

Here is the code :
import com.ibm.mq.*;
import java.io.*;
/**
* @author mutuj
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class Receiver {
private String qManager = "COFQM1";
private MQQueueManager qMgr;

public static void main(String[] args) {
new Receiver();
}
public Receiver() {
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
MQQueue qsres = null;
try {
//create connection to queue manager
qMgr = new MQQueueManager(qManager);
qsres = qMgr.accessQueue("QSRES", openOptions);
MQMessage testRes = new MQMessage();

while (true) {
qsres.get(testRes);
System.out.println("Received message : "+ testRes.readLine());
}
} catch (MQException mqex) {
System.out.println(
"A websphere error occured : Completion code "
+ mqex.completionCode
+ "Reason code "
+ mqex.reasonCode);
mqex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
qsres.close();
qMgr.disconnect();
} catch (MQException mqex) {
System.out.println(
"A websphere error occured : Completion code "
+ mqex.completionCode
+ "Reason code "
+ mqex.reasonCode);
mqex.printStackTrace();
} catch (Exception ex) {
}
}
}
}

jeff
jeff mutonho
Ranch Hand

Joined: Apr 30, 2003
Posts: 271
I just realized now that when I put more than one message I get the following error message
MQJE001: Completion Code 2, Reason 2033
A websphere error occured : Completion code 2Reason code 2033
com.ibm.mq.MQException: MQJE001: Completion Code 2, Reason 2033
at com.ibm.mq.MQQueue.get(MQQueue.java:822)
at com.ibm.mq.MQQueue.get(MQQueue.java:1006)
at SCVDirect.<init>(SCVDirect.java:51)
at Receiver.main(Receiver.java:18)
ubergeekcd
Greenhorn

Joined: Sep 07, 2003
Posts: 2
Hey, I tink you need to set the MQGetMessageOptions before doing the get.

Error code 2033 means the Queue is empty.

Try this
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options= MQC.MQGMO_NO_SYNCPOINT; //Set no sync point
gmo.options= MQC.MQGMO_CONVERT; //Handles ASCII/EBCDIC
gmo.options= MQC.MQGMO_WAIT;//Wait until message arrives
gmo.waitInterval= 30000;

this will allow you to wait for the queue.

Also you might want to put in a while(i<5) ie. loop for 5 times
and slap the readString inbetwn that...

Hope this helps....


SCJP SCEA
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connecting to MQ Series from a java app