add a trailing slash to the ftp upload url, think that is what the strategy is looking for to determine a working directory in the ftp server.
jndiParameters.put(Context.PROVIDER_URL, "tcp://localhost:61616?jms.blobTransferPolicy.uploadUrl=ftp://user:p...@myhost /"); On 16 March 2010 08:00, joe <[email protected]> wrote: > 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:p...@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) > -- http://blog.garytully.com Open Source Integration http://fusesource.com
