activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joe <fischauto...@yahoo.de>
Subject BlobMessage,ftp and exception
Date Tue, 16 Mar 2010 08:00:12 GMT
Hi,

I am trying to send a file via BlobMessage, but it doesn't work.
Whats wrong with the code?

- ActiveMQ 5.3.0
- commons-net-ftp-2.0


package de.test.jmsproducer;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Properties;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.apache.activemq.ActiveMQSession;
import org.apache.activemq.BlobMessage;

public class Sender
{
   private ConnectionFactory connectionFactory;
   private Connection connection;
   private Session session;
   private Destination destination;
   private MessageProducer producer;

   public Sender() throws JMSException
   {
     try
     {
       Properties jndiParameters = new Properties();
       jndiParameters.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
       jndiParameters.put(Context.PROVIDER_URL,
"tcp://localhost:61616?jms.blobTransferPolicy.uploadUrl=ftp://user:pass@myhost");
       jndiParameters.put("queue.fileQ", "example.fileQ");
       InitialContext ic = new InitialContext(jndiParameters);

       connectionFactory = (ConnectionFactory)
ic.lookup("ConnectionFactory");

       connection = (Connection) connectionFactory.createConnection();
       connection.start();
       destination = (Destination) ic.lookup("fileQ");
       session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
       producer = session.createProducer(destination);
     }
     catch (NamingException e)
     {
       e.printStackTrace();
     }

   }

   public void sendFile() throws JMSException
   {
     BlobMessage blobMessage;
     try
     {
       blobMessage = ((ActiveMQSession) session).createBlobMessage(new
FileInputStream("c:\\test\\a.file"));
       producer.send(blobMessage);
     }
     catch (FileNotFoundException e)
     {
       e.printStackTrace();
     }
   }

   public static void main(String[] args) throws JMSException
   {
     Sender mmp = new Sender();
     mmp.sendFile();
   }

}

i got:

Exception in thread "main" java.lang.StringIndexOutOfBoundsException:
String index out of range: -1
	at java.lang.String.substring(Unknown Source)
	at
org.apache.activemq.blob.FTPBlobUploadStrategy.uploadStream(FTPBlobUploadStrategy.java:71)
	at org.apache.activemq.blob.BlobUploader.upload(BlobUploader.java:53)
	at
org.apache.activemq.command.ActiveMQBlobMessage.onSend(ActiveMQBlobMessage.java:173)
	at org.apache.activemq.ActiveMQSession.send(ActiveMQSession.java:1674)
	at
org.apache.activemq.ActiveMQMessageProducer.send(ActiveMQMessageProducer.java:231)
	at
org.apache.activemq.ActiveMQMessageProducerSupport.send(ActiveMQMessageProducerSupport.java:241)
	at de.novastor.jmsproducer.Sender.sendFileMessage(Sender.java:70)
	at de.novastor.jmsproducer.Sender.main(Sender.java:81)

Mime
View raw message