Solved

jboss 4 jms client

Posted on 2004-10-29
488 Views
Last Modified: 2012-06-27
Hi,

I am using JBoss 4, and I do not know how to write a client to connect to it..

in previous version, 3.2.5, I used this:

"http://localhost:8080/invoker/JNDIFactory"

(also from experts-exchange), but now this does not return the right object.

Thank you.
Mark
0
Question by:kerzner
    11 Comments
     
    LVL 35

    Expert Comment

    by:TimYates
    Can you post your connection code?
    0
     
    LVL 1

    Author Comment

    by:kerzner
    Well, here is what I use (did not want to bother you with reading many lines, but you asked).

        public void initJBoss() {
            logger.fine("Preparing to listen for messages on " + JNDIContext.getJBossJmsUrl());
            //  JNDIContext.getJBossJmsUrl()) resolves to "localhost"
            TopicConnectionFactory  topicConnectionFactory = null;
            TopicConnection         topicConnection = null;
            TopicSession            topicSession = null;
            Topic                   topic = null;
            TopicSubscriber         topicSubscriber = null;
            TopicMessageListener    topicListener = null;
           
            try {
                Hashtable <String, String> props = new Hashtable <String, String> ();
                props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.HttpNamingContextFactory");            
                props.put(Context.PROVIDER_URL, JNDIContext.getJBossJmsUrl());
                props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
                ctx = new InitialContext(props);        

                topicConnectionFactory =
                (TopicConnectionFactory) ctx.lookup("ConnectionFactory");
                topicConnection = topicConnectionFactory.createTopicConnection();
                topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
                topic = (Topic) ctx.lookup("topic/testTopic");
                topicConnection.start();
               
                topicSubscriber = topicSession.createSubscriber(topic);
                topicListener = new TopicMessageListener();
                topicSubscriber.setMessageListener(topicListener);
                topicConnection.start();
                logger.fine("connected");
            } catch (Exception e) {
                Util.getLogger().fine("Connection problem: " + e.toString());
                e.printStackTrace();
                if (topicConnection != null) {
                    try {
                        topicConnection.close();
                    } catch (JMSException ee) {}
                }
            }        
        }    
    0
     
    LVL 35

    Accepted Solution

    by:
    and which line doesn't return the correct object? (ie: throws the exception)

    That looks ok at first glance :-)
    0
     
    LVL 1

    Author Comment

    by:kerzner
    InitialContext gives error

    FINE: Connection problem: javax.naming.NamingException: Failed to retrieve Naming interface [Root exception is java.io.FileNotFoundException: http://localhost:8080/invoker/JNDIFactory]
    javax.naming.NamingException: Failed to retrieve Naming interface [Root exception is java.io.FileNotFoundException: http://localhost:8080/invoker/JNDIFactory]
            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 com.lateral.control.model.TopicMessageListener.initJBoss(TopicMessageListener.java:193)
            at com.lateral.control.model.TopicMessageListener.run(TopicMessageListener.java:82)
    Caused by: java.io.FileNotFoundException: http://localhost:8080/invoker/JNDIFactory
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
            at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1111)
            at java.security.AccessController.doPrivileged(Native Method)
            at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1105)
            at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:813)
            at org.jboss.naming.HttpNamingContextFactory.getNamingServer(HttpNamingContextFactory.java:117)
            at org.jboss.naming.HttpNamingContextFactory.getInitialContext(HttpNamingContextFactory.java:65)
            ... 6 more
    Caused by: java.io.FileNotFoundException: http://localhost:8080/invoker/JNDIFactory
            at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1064)
            at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:1773)
            at java.net.URLConnection.getHeaderFieldInt(URLConnection.java:573)
            at java.net.URLConnection.getContentLength(URLConnection.java:468)
            at org.jboss.naming.HttpNamingContextFactory.getNamingServer(HttpNamingContextFactory.java:112)
            ... 7 more
    0
     
    LVL 35

    Expert Comment

    by:TimYates
    What happens if you change:

                props.put(Context.PROVIDER_URL, JNDIContext.getJBossJmsUrl());

    to

                props.put(Context.PROVIDER_URL, "jnp://" + JNDIContext.getJBossJmsUrl() + ":1099");
    0
     
    LVL 1

    Author Comment

    by:kerzner
    then I get this,

    FINE: Connection problem: javax.naming.NamingException: Failed to retrieve Naming interface [Root exception is java.lang.ClassCastException: java.rmi.MarshalledObject]
    javax.naming.NamingException: Failed to retrieve Naming interface [Root exception is java.lang.ClassCastException: 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 com.lateral.control.model.TopicMessageListener.initJBoss(TopicMessageListener.java:194)
            at com.lateral.control.model.TopicMessageListener.run(TopicMessageListener.java:82)
    Caused by: java.lang.ClassCastException: java.rmi.MarshalledObject
            at org.jboss.naming.HttpNamingContextFactory.getNamingServer(HttpNamingContextFactory.java:119)
            at org.jboss.naming.HttpNamingContextFactory.getInitialContext(HttpNamingContextFactory.java:65)
            ... 6 more
    0
     
    LVL 35

    Expert Comment

    by:TimYates
    And if you change:

        props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.HttpNamingContextFactory");            

    to

        props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

    ?

    Hmmm... I will search the web to get a definitive answer...  I think there has been some Jboss refactoring, so classes have changed package...
    0
     
    LVL 1

    Author Comment

    by:kerzner
    I forgot to say, that I really talk to

    "http://localhost:8080/invoker/JNDIFactory";

    But let me try to see what class I get
    0
     
    LVL 1

    Author Comment

    by:kerzner
    No answer so far, I am back to JBoss 3.5
    0
     
    LVL 1

    Author Comment

    by:kerzner
    Dear Tim:

    Thank you, the discussion was helpful. I had to go back to JBoss 3.5, in the rush of the moment, but I will keep these notes.

    All the best,
    Mark
    0
     
    LVL 35

    Expert Comment

    by:TimYates
    Good luck with it all!  Hope you have more success next try...

    I'm on 3.2.5 for pretty much the same reason...I just need a few days open to try out 4...

    But there's always work to do :-(

    Good luck!

    Tim
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    The Complete Ruby on Rails Developer Course

    Ruby on Rails is one of the most popular web development frameworks, and a useful tool used by both startups and more established companies to build strong graphic user interfaces, and responsive websites and apps.

    RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
    I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now