?
Solved

Java and Websphere MQ

Posted on 2008-10-23
9
Medium Priority
?
723 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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 480 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Invest in your employees with these five simple steps to improve employee engagement and retention.
In this article I discuss my selections of the Top Four free Outlook OST File Viewers available. Open, view and read even damaged OST files by using these tools. They all provide a clear preview of all data such as emails, notes, tasks, calendars, e…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

801 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