Solved

Java and Websphere MQ

Posted on 2008-10-23
9
700 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I previously wrote an article addressing the use of UBCD4WIN and SARDU. All are great, but I have always been an advocate of SARDU. Recently it was suggested that I go back and take a look at Easy2Boot in comparison.
Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
The viewer will learn how to create multiple layers to apply various filters and how to delete areas from each layer’s filter.
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

760 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

16 Experts available now in Live!

Get 1:1 Help Now