2 Replies Latest reply on Feb 27, 2013 2:20 AM by haithamnor

    How to connect to remote queue?

    haithamnor

      Hi
      i'm trying to run JMS Java Application(Jboss4.2.3) on Remote server that grant permission to me so I wrote the following code:

          package test;
          import java.io.IOException;
          import java.util.Properties;
          import javax.jms.DeliveryMode;
          import javax.jms.JMSException;
          import javax.jms.MapMessage;
          import javax.jms.Queue;
          import javax.jms.QueueConnection;
          import javax.jms.QueueConnectionFactory;
          import javax.jms.QueueSender;
          import javax.jms.QueueSession;
          import javax.jms.TextMessage;
          import javax.naming.Context;
          import javax.naming.InitialContext;
          import javax.naming.NamingException;
          import java.net.UnknownHostException;
          public class QueueProduce {
          public static void main(String[] args)throws JMSException,NamingException
          {
               try
          {
              System.out.println(">>>>>>> Begain Producer ..... >>>>>>>>");
               Context context =QueueProduce.getInitialContext();
               QueueConnectionFactory queueconnectionfactory = (QueueConnectionFactory) context.lookup   ("ConnectionFactory");
               Queue queue =(Queue) context.lookup("queue/D");
               queueConnection queueconnection = queueconnectionfactory.createQueueConnection("un","pwd");
               QueueSession queuesession =  queueconnection.createQueueSession(false,QueueSession.AUTO_ACKNOWLEDGE);
               queueconnection.start();
               QueueProduce queueproducer =new QueueProduce();
               queueproducer.sendmessage(".this message send for from queue testing " ,queuesession,queue);
               System.out.println(">>>>>>Testing Message has been sent >>>>>>>>>");
          }
          catch (JMSException e)
          {
               e.printStackTrace();
          }
          }
        this method to send message:

          public void sendmessage (String text,QueueSession queuesession ,Queue queue)throws JMSException
          {
               QueueSender queuesender = queuesession.createSender(queue);
               TextMessage textmessage = queuesession.createTextMessage(text);
               queuesender.setDeliveryMode(DeliveryMode.PERSISTENT);
               queuesender.send(textmessage  );
               queuesender.close();
          }
          public static Context getInitialContext () throws JMSException,NamingException
          {
               Properties prop = new Properties();
               prop.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
               prop.setProperty("java.naming.factory.url.pkgs", "org.jnp.interfaces");
               prop.setProperty("java.naming.provider.url", "jnp://192.150.50.20:1099");
               Context context = new InitialContext(prop);
          return context;
          }
          }

       

       

      But I got this exception:
        Exception in thread "main" javax.naming.communicationException
        [root java.lang.ClassNotfoundException:org.jboss.jms.client.jbossconnection
        <no security manager:RMI class loader disable>]
        at org.jnp.interfaces.NamingContext.lookup
        coused by: java.lang.ClassNotFoundException: org.jboss.jms.client.jbossconnectionFactory<no security manager:RMI class loader disable>
        at sun.rmi,security.loaderhandler.loadclass
        at java.io.ObjectInputStream.readnoproxydesc
        at java.io.ObjectInputStream.readclassDesc
        at org.jnp.interfacesmarshalledvaluepair.get

       

      So any help?