Forum Stats

  • 3,875,115 Users
  • 2,266,806 Discussions
  • 7,912,086 Comments

Discussions

File Tranfer Issue Using JMS

908647
908647 Member Posts: 2
edited Jan 4, 2012 2:15AM in Java Message Service (JMS)
Hello everybody,

I am new to JMS and trying to develop a chat application using Swing and JMS. TextMessaging is working fine but i am unable to configure FileTranfer.

Configurations are stated below:
Apache Geronimo 2.2 (as JMS provider server).
ActiveMQ (for connecting to JMS server).
Java Swing.

Establishing Connection:

Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
env.put(Context.PROVIDER_URL, "tcp://localhost:61616?jms.prefetchPolicy.all=100&jms.redeliveryPolicy.maximumRedeliveries=5");
env.put(Context.SECURITY_PRINCIPAL, "system");
env.put(Context.SECURITY_CREDENTIALS, "manager");
env.put("topic.myTopic","org.apache.geronimo.configs/activemq-ra/JCAAdminObject/myTopic");
// create publisher and subscriber
InitialContext ctx = new InitialContext(env);
ActiveMQConnectionFactory factory = (ActiveMQConnectionFactory) ctx.lookup("TopicConnectionFactory");
final Topic topic = (Topic) ctx.lookup("myTopic");
ActiveMQConnection conn = (ActiveMQConnection)factory.createTopicConnection();

// Downloaded Apache FtpServer1.0.6 and started the server from bin folder ftpd.bat.
conn.getBlobTransferPolicy().setUploadUrl("http://localhost:2121/fileserver/");

final ActiveMQSession session = (ActiveMQSession)conn.createSession(false,Session.AUTO_ACKNOWLEDGE);
final TopicPublisher publisher = session.createPublisher(topic);
subscriber = session.createSubscriber(topic);


Sending BlobMessage

String filePath = fileChooser.getSelectedFile().getAbsolutePath();
File file = new File(filePath);
BlobMessage msg = session.createBlobMessage(file);
String sender = System.getProperty("user.name");
msg.setStringProperty("sender", sender);
msg.setStringProperty("filename", file.getName());
publisher.publish(msg);


Receiving BlobMessage

public void onMessage(Message m) {
try {
String sender = m.getStringProperty("sender");
if(m instanceof TextMessage){
TextMessage msg = (TextMessage) m;
incoming.append(sender + "> " + msg.getText() + "\n");
} else if (m instanceof BlobMessage) {
String filename = m.getStringProperty("filename");
JOptionPane.showMessageDialog(null, "You have recieved a file "+filename+" from "+sender+" !!!");
BlobMessage blobMessage = (BlobMessage) m;
InputStream inputStream = blobMessage.getInputStream();
if (inputStream != null) {
try {
OutputStream os = new FileOutputStream(new File("C://"+filename));
try {
byte[] buffer = new byte[4096];
for (int n; (n = inputStream.read(buffer)) != -1; )
os.write(buffer, 0, n);
}catch(Exception e){
e.printStackTrace();
}
finally { os.close(); }
}catch(Exception e){
e.printStackTrace();
}
finally { inputStream.close(); }

}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}


I downloaded Apache FtpServer1.0.6 and started the server from bin folder ftpd.bat as I found this step after googling for sometime.
I am getting the Recieved File alert in OnMessage method but the inputstream is null. No data is coming to the reciever. I am unable to figure out the actual issue.

Please help me out.

Many Thanks
Rupal Chatterjee
Tagged:

Answers

  • jtahlborn
    jtahlborn Member Posts: 2,040
    i doubt your ftp server is going to service http requests, e.g.: "http://localhost:2121/fileserver/"
  • 908647
    908647 Member Posts: 2
    edited Jan 4, 2012 2:15AM
    Hi jtahlborn,

    Thanks for ur time.

    I changed it to "conn.getBlobTransferPolicy().setUploadUrl("*ftp://localhost:2121/fileserver/*");" but still it is not working.

    InputStream at the reciever's end is null.

    I noticed one thing, when i comment out the entire above setUploadUrl statement ie "//conn.getBlobTransferPolicy().setUploadUrl("*ftp://localhost:2121/fileserver/*");", still there is no effect on the result. Means I am not getting any errors if i remove this statement. I am not sure whether this working.

    Please help.

    Thanks
    Rupal Chatterjee

    Edited by: Rupal on 03-Jan-2012 23:15
This discussion has been closed.