Announcement Announcement Module
Collapse
No announcement yet.
File Tranfer Issue Using JMS Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • File Tranfer Issue Using 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.apach e.activemq.jndi.ActiveMQInitialContextFactory");
    env.put(Context.PROVIDER_URL, "tcp://localhost:61616?jms.prefetchPolicy.all=100&jms.red eliveryPolicy.maximumRedeliveries=5");
    env.put(Context.SECURITY_PRINCIPAL, "system");
    env.put(Context.SECURITY_CREDENTIALS, "manager");
    env.put("topic.myTopic","org.apache.geronimo.confi gs/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("ftp://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
Working...
X