Solved

Java and Websphere MQ

Posted on 2008-10-23
9
701 Views
Last Modified: 2013-11-15
The code below does file transfer. I am successful in putting a file into a queue. I can also grab the file from the queue. However in the GET FILE section I am getting the error saying that the path does not exist. The problem is with the retrievedMessage.putApplicationName specified in the path. How do I solve the problem?.

PUT FILE

qMgr = new MQQueueManager(qManager);
int openOptions = MQC.MQOO_OUTPUT ;
MQQueue MQ1_RQSTIN = qMgr.accessQueue("QM1.RQSTIN",openOptions);
MQMessage hello_world = new MQMessage();
hello_world.putApplicationName = "src_mqsample.txt";

File file = new File("C:\\Documents and Settings\\JCreatorLE\\src_mqsample.txt");
StringBuffer contents = new StringBuffer();
BufferedReader reader = null;
reader = new BufferedReader(new FileReader(file));
String text = null;

while((text = reader.readLine())!= null)
{
contents.append(text).append(System.getProperty("line.separator"));
}

MQPutMessageOptions pmo = new MQPutMessageOptions();
MQ1_RQSTIN.put(hello_world,pmo);

hello_world.writeObject(contents);
MQPutMessageOptions pmo = new MQPutMessageOptions();
MQ1_RQSTIN.put(hello_world,pmo);

MQ1_RQSTIN.close();
qMgr.disconnect();

GET FILE

qMgr = new MQQueueManager("QM5");
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF ;
MQQueue MQ1_RQSTIN = qMgr.accessQueue("QM1.RQSTIN",openOptions);
MQMessage retrievedMessage = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
MQ1_RQSTIN.get(retrievedMessage,gmo);

StringBuffer msg = (StringBuffer) retrievedMessage.readObject();
FileWriter fn = new FileWriter("C:\\Documents and Settings\\JCreator LE\\MyProjects\\" + "'" + retrievedMessage.putApplicationName + "'");
fn.write(msg.toString(),0,msg.toString().length());
fn.flush();
fn.close();

MQ1_RQSTIN.close();
qMgr.disconnect();
0
Comment
Question by:eugene007
  • 5
  • 4
9 Comments
 
LVL 5

Expert Comment

by:lgacs
ID: 22796157
If your code snippet is correct, compare the
C:\\Documents and Settings\\JCreatorLE with
C:\\Documents and Settings\\JCreator LE

There is an extra space in the later.
0
 

Author Comment

by:eugene007
ID: 22796385
C:\\Documents and Settings\\JCreator LE
Is the correct one. But the result is the same.
0
 
LVL 5

Expert Comment

by:lgacs
ID: 22797423
Your code works for me however the put application name is
overwritten by MQ with 'WebSphere MQ Client for Java' - in case of client connection,
but the file is created with this name having the correct content.

The file name should be transferred in a RFH2 header or with a little hack
in the MessageID (or CorrelId), if you can ensure its length fits in it.
0
 

Author Comment

by:eugene007
ID: 22798690
But the filename should be src_mqsample.txt at the receiving end.
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Comment

by:eugene007
ID: 22798704
also take note im using websphere mq :)
0
 
LVL 5

Accepted Solution

by:
lgacs earned 120 total points
ID: 22799826
Put the file name into MessegeId on the put side:

                  hello_world.messageId = "src_mqsample.txt".getBytes();

And get from it on the get side:

                  FileWriter fn = new FileWriter("C:\\Documents and Settings\\JCreator LE\\MyProjects\\" + new String (retrievedMessage.messageId) );

It works if the file name is not longer, then 24 bytes.
0
 

Author Comment

by:eugene007
ID: 22801437
ok this works. however just a small clarification, since the messageid is changed, do you think that the correlationid must be changed too. Because the correlationid is a copy of the messageid.
0
 

Author Comment

by:eugene007
ID: 22801557
Also to overcome the limitation in the filename length, I came up with the idea to use a database.
0
 
LVL 5

Expert Comment

by:lgacs
ID: 22802522
You can set MessagId and CorrelId independently.
File name can be carried inside the message using either of them.
Database can be used storing long file names associating with an unique MessageId.
 
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Skype is a P2P (Peer to Peer) instant messaging and VOIP (Voice over IP) service – as well as a whole lot more.
All of the resources available today make learning a new digital media easier than ever-- if you know where to begin. This is a clear, simple guide to a few of the basic digital art mediums and how to begin learning them on your own.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now