DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 5 of 5

Hybrid View

  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 11:00 AM. Reason: Added Code Tags

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

    If so, is the path in this file correct?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  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,649
    Thank you for posting your solution. Hopefully it will help someone else with the same or similiar problem.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Similar Threads

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

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links