Java with MQ file transfer


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Java with MQ file transfer

  1. #1
    Join Date
    Jul 2005
    Posts
    20

    Java with MQ file transfer

    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?.
    Code:
    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();
    Last edited by Hack; 10-24-2008 at 12:00 PM. Reason: Added Code Tags

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Is the retrievedMessage.putApplicationName path coming from the "src_mqsample.txt" file?

    If so, is the path in this file correct?

  3. #3
    Join Date
    Jul 2005
    Posts
    20
    String m = retrievedMessage.putApplicationName;
    System.out.println(m);

    Result: ava\jdk1.6.0_10\bin\java.exe

    Expected Result: src_mqsample.txt

  4. #4
    Join Date
    Jul 2005
    Posts
    20
    I found a solution which is to alter the messageid with condition that the filename should be within 24 bytes.

  5. #5
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Thank you for posting your solution. Hopefully it will help someone else with the same or similiar problem.

Similar Threads

  1. Replies: 8
    Last Post: 11-27-2008, 03:13 AM
  2. Replies: 2
    Last Post: 04-08-2008, 09:29 AM
  3. Java File IO
    By emoos in forum Java
    Replies: 2
    Last Post: 11-03-2005, 08:24 AM
  4. Java vs. .Net. A questionnaire
    By Basil in forum .NET
    Replies: 1
    Last Post: 05-13-2005, 07:46 AM
  5. Java Security in File access
    By TA in forum Java
    Replies: 0
    Last Post: 09-01-2000, 09:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center