Solved

Java and Websphere MQ

Posted on 2008-10-23
9
708 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Healthcare organizations in the United States must adhere to the guidance of both the HIPAA (Health Insurance Portability and Accountability Act) and HITECH (Health Information Technology for Economic and Clinical Health Act) for securing and protec…
This video will demonstrate how to find the puppet warp tool from the edit menu and where to put the points to edit.
Using Adobe Premiere Pro, the viewer will learn how to set up a sequence with proper settings, importing pictures, rendering, and exporting the finished product.

730 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