Solved

Java and Websphere MQ

Posted on 2008-10-23
9
703 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Comment

by:eugene007
ID: 22798690
But the filename should be src_mqsample.txt at the receiving end.
0
 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
print map entry 34 67
How to attach a folder from the desktop to an outgoing e-mail using Hotmail? 8 43
tomcat startup error 5 59
going to wrong jsp page 2 19
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
This video demonstrates how to use each tool, their shortcuts, where and when to use them, and how to use the keyboard to improve workflow.
Viewers will learn how to use the Hootsuite Dashboard.

785 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