Uploaded image for project: 'ActiveMQ Classic'
  1. ActiveMQ Classic
  2. AMQ-2548

Downloading Blob messages via FTP fails for files larger than 64KB

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 5.3.0
    • 5.3.1, 5.4.0
    • None
    • None
    • OS: Windows XP

    Description

      The following code will only download 64 KB of any uploaded file greater than 64 KB.
      The test file (ca. 15 MB) was completly uploaded to the FTP-Server.

          File file = new File(directoryName+fileName);
          
          ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(URI);
          Connection connection = factory.createQueueConnection(); 
      
          connection.start();
          
          ActiveMQSession session = (ActiveMQSession) connection.createSession(
                                      false, Session.AUTO_ACKNOWLEDGE);
          Destination destination = session.createQueue("MyQ");
          MessageProducer producer = session.createProducer(destination);
          MessageConsumer consumer = session.createConsumer(destination);
          BlobMessage message = session.createBlobMessage(file);
            
          producer.send(message);
      
          System.out.println("Sent: " + message);
          
          Thread.sleep(1000);
            
          // check message sent
          Message msg = consumer.receive();
          
          BlobDownloadStrategy strategy = new FTPBlobDownloadStrategy();
            
          InputStream input = strategy.getInputStream((ActiveMQBlobMessage)msg);
      
          File f=new File(fileName);
          OutputStream out=new FileOutputStream(f);
          byte buf[]=new byte[1024];
          int len;
          
          while((len=input.read(buf))>0){
            out.write(buf,0,len);
          }
          out.close();
          input.close(); 
      
          System.out.println("Received: " + message);
          
      

      After examining org.apache.activemq.blob.FTPBlobDownloadStrategy it seemed suspicious that the FTPClient connection was destroyed before the input stream is processed.

      public InputStream getInputStream(ActiveMQBlobMessage message) throws IOException, JMSException {
              URL url = message.getURL();
              
              setUserInformation(url.getUserInfo());
              String connectUrl = url.getHost();
              int port = url.getPort() < 1 ? 21 : url.getPort();
      
              FTPClient ftp = new FTPClient();
              try {
              	ftp.connect(connectUrl, port);
              } catch(ConnectException e) {
              	throw new JMSException("Problem connecting the FTP-server");
              }
              
              if(!ftp.login(ftpUser, ftpPass)) {
              	ftp.quit();
                  ftp.disconnect();
                  throw new JMSException("Cant Authentificate to FTP-Server");
              }
              String path = url.getPath();
              String workingDir = path.substring(0, path.lastIndexOf("/"));
              String file = path.substring(path.lastIndexOf("/")+1);
              
              ftp.changeWorkingDirectory(workingDir);
              ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
              InputStream input = ftp.retrieveFileStream(file);
      
              ftp.quit(); // really?
              ftp.disconnect(); // really?
              
              return input;
          }
      

      After commenting those two last ftp calls, files larger than 64 KB were downloaded properly, but this should of course not be the final solution.
      Any suggestions?

      Cheers, Toni

      Attachments

        Activity

          People

            tabish Timothy A. Bish
            pea Antun Pendo
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: