4 Replies Latest reply on Mar 25, 2005 1:46 PM by gberish

    No Hope - JMS over HTTP 4.0.1

    gberish

      I would sure apprecitate someone running the code below and giving me a hint as to why I am getting the error I do.

      Getting started 4.0 and everything else I found says it is easy to send JMS messages over HTTP, but I cannot.

      The code is a client that cycles through 2 attempts to send and retreive a message from queue/A [which comes with the default server].

      Please see ScreenPrint Output beneath code.
      1. Regular JMS. Works great.
      2. Over HTTP. Fails miserably.

      import java.lang.reflect.Method;
      import java.util.Hashtable;
      import javax.jms.JMSException;
      import javax.jms.Message;
      import javax.jms.Queue;
      import javax.jms.QueueConnection;
      import javax.jms.ConnectionFactory;
      import javax.jms.QueueConnectionFactory;
      import javax.jms.QueueReceiver;
      import javax.jms.QueueSession;
      import javax.jms.QueueSender;
      import javax.jms.Session;
      import javax.jms.TextMessage;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      
      public class MessageTest {
      
       public static void main (String[] args) {
       MessageTest mb = new MessageTest ();
       for (int i = REG; i <= HTTP; i++) {
       mb.doMessage (i);
       }
       }
      
       // method
       public void doMessage (int type) {
       System.out.println ("\n\nType = " + TYPE [type]);
       try {
       // get initial context
       Hashtable<String, String> env= new Hashtable<String, String> ();
       switch (type) {
       case REG:
       env.put(Context.INITIAL_CONTEXT_FACTORY,
       "org.jnp.interfaces.NamingContextFactory");
       env.put(Context.PROVIDER_URL,
       "jnp://localhost:1099");
       env.put(Context.URL_PKG_PREFIXES,
       "org.jnp.interfaces");
       break;
       case HTTP:
       env.put(Context.INITIAL_CONTEXT_FACTORY,
       "org.jboss.naming.HttpNamingContextFactory");
       env.put(Context.PROVIDER_URL,
       "http://localHost:1099/invoker/JMXInvokerServlet");
       env.put(javax.naming.Context.URL_PKG_PREFIXES,
       "org.jboss.naming:org.jnp.interfaces");
       break;
       }
      
       System.out.println ("Calling InitialContext");
       ctx = new InitialContext(env);
       System.out.println ("InitialContext Found");
      
       // lookup connection factory
       factory = (QueueConnectionFactory)ctx.lookup("ConnectionFactory");
       System.out.println ("Connection Factory instantiated");
      
       // lookup destination
       destination = (Queue)ctx.lookup("queue/A");
       System.out.println ("Destination instantiated");
      
       // create connection
       connection = factory.createQueueConnection();
       System.out.println ("Connection instantiated");
      
       // create session
       session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
       System.out.println ("Session instantiated");
      
       // create sender
       sender = session.createSender(destination);
       System.out.println ("Sender instantiated");
      
       // create receiver
       receiver = session.createReceiver(destination);
       System.out.println ("Receiver instantiated");
      
       // create message w/text & selector property
       String m = "Success";
       message = session.createTextMessage(m);
       System.out.println ("Message instantiated w/ text = \"" + m + "\"");
      
       message.setStringProperty ("Player", "Great");
       System.out.println ("Message Property \"Player\" set to \"Great\"");
      
       // starting connection
       connection.start ();
       System.out.println ("Connection Started");
      
       // send message
       sender.send(message);
       System.out.println ("Message Sent:");
      
       // receive message
       message = (TextMessage) receiver.receive ();
       System.out.println ("Message Received:");
       System.out.println ("Message text = \"" + message.getText () + "\"");
       System.out.println ("Message Property \"Player\" = \"" + message.getStringProperty ("Player")+ "\"");
      
       } catch (NamingException e) {
       System.out.println ("Naming Exception");
       e.printStackTrace ();
       } catch (JMSException e) {
       System.out.println ("JMS Execption");
       e.printStackTrace ();
       } finally {
       if (connection != null) {
       try {
       connection.stop ();
       connection.close();
       } catch (JMSException e) {
       }
       }
       }
       System.out.println("main () End:");
       }
      
       // members
       static final int REG = 0;
       static final int HTTP = 1;
       static final String[] TYPE = {"Regular JMS Message", "JMS Message Over HTTP"};
       int type;
       Context ctx;
       Queue destination;
       QueueConnection connection;
       QueueConnectionFactory factory;
       QueueReceiver receiver;
       QueueSession session;
       QueueSender sender;
       TextMessage message;
      }
      Screen Print Output
      
      Type = Regular JMS Message
      Calling InitialContext
      InitialContext Found
      Connection Factory instantiated
      Destination instantiated
      Connection instantiated
      Session instantiated
      Sender instantiated
      Receiver instantiated
      Message instantiated w/ text = "Success"
      Message Property "Player" set to "Great"
      Connection Started
      Message Sent:
      Message Received:
      Message text = "Success"
      Message Property "Player" = "Great"
      main () End:
      
      
      Type = JMS Message Over HTTP
      Calling InitialContext
      Naming Exception
      javax.naming.NamingException: Failed to retrieve Naming interface [Root exception is java.lang.Class
      CastException: java.rmi.MarshalledObject]
       at org.jboss.naming.HttpNamingContextFactory.getInitialContext(HttpNamingContextFactory.java
      :69)
       at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
       at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
       at javax.naming.InitialContext.init(InitialContext.java:223)
       at javax.naming.InitialContext.<init>(InitialContext.java:197)
       at MessageTest.doMessage(MessageTest.java:53)
       at MessageTest.main(MessageTest.java:23)
      Caused by: java.lang.ClassCastException: java.rmi.MarshalledObject
       at org.jboss.naming.HttpNamingContextFactory.getNamingServer(HttpNamingContextFactory.java:1
      20)
       at org.jboss.naming.HttpNamingContextFactory.getInitialContext(HttpNamingContextFactory.java
      :65)
       ... 6 more
      main () End:
      Press any key to continue . . .

      THNAX!




        • 1. Re: No Hope - JMS over HTTP 4.0.1

           

          "gberish" wrote:
          case HTTP:
          env.put(Context.INITIAL_CONTEXT_FACTORY,
          "org.jboss.naming.HttpNamingContextFactory");
          env.put(Context.PROVIDER_URL,
          "http://localHost:1099/invoker/JMXInvokerServlet");
          env.put(javax.naming.Context.URL_PKG_PREFIXES,
          "org.jboss.naming:org.jnp.interfaces");
          break;
          }


          Reread the documentation, this *is* gibberish :-)

          • 2. Re: No Hope - JMS over HTTP 4.0.1
            gberish

            In case there is someone willing to offer a useful suggestion, I tired to follow the documentation below that comes from from:

            http://docs.jboss.org/jbossas/jboss4guide/r1/html/ch3.chapter.html
            Obviously I am missing something big when reading it.

            3.2.1.2. The HTTP InitialContext Factory Implementation
            The JNDI naming service can be accessed over HTTP...

            To access JNDI over HTTP you use the org.jboss.naming.HttpNamingContextFactory as the factory implementation. The complete set of support InitialContext environment properties for this factory are:

            java.naming.factory.initial: ...must be org.jboss.naming.HttpNamingContextFactory.
            MyCode has:
            env.put(Context.INITIAL_CONTEXT_FACTORY,
            "org.jboss.naming.HttpNamingContextFactory");


            java.naming.provider.url (or Context.PROVIDER_URL): ... the default setup places the JMX invoker servlet under /invoker/JMXInvokerServlet.
            ...full HTTP URL Examples include:
            http://www.jboss.org:8080/invoker/JMXInvokerServlet
            http://www.jboss.org/invoker/JMXInvokerServlet
            https://www.jboss.org/invoker/JMXInvokerServlet

            The first example accesses the servlet using the port 8080. The second uses the standard HTTP port 80, and the third uses an SSL encrypted connection to the standard HTTPS port 443.
            MyCode Failed (even after correcting localHost to localhost) with:
            env.putContext.PROVIDER_URL,"http://localhost:8080/invoker/JMXInvokerServlet");
            env.putContext.PROVIDER_URL,"http://localhost/invoker/JMXInvokerServlet"); and
            env.putContext.PROVIDER_URL,"http://localhost:1099/invoker/JMXInvokerServlet");


            java.naming.factory.url.pkgs: must be: ... org.jboss.naming:org.jnp.interfaces.
            MyCode used:
            env.put(javax.naming.Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");


            ... If the JBoss web server is sitting behind one or more firewalls or proxies ...
            It is not.

            There must be more to it.
            Thanx.


            • 3. Re: No Hope - JMS over HTTP 4.0.1

              Ok, now I see where you got that gibberish from,
              the documenation is wrong.
              I've raised a bug report for this;
              http://jira.jboss.com/jira/browse/JBDOCS-45
              It should be

              http://localhost:8080/invoker/JNDIFactory
              


              • 4. Re: No Hope - JMS over HTTP 4.0.1
                gberish

                Thanks.

                If anyone else hits this question and is using a JBoss server, please note that the other problem was that I did not have jbossall-client.xml in my classpathwhen I ran the client.