jboss 4 jms client

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
LVL 1
kerznerAsked:
Who is Participating?
 
TimYatesCommented:
and which line doesn't return the correct object? (ie: throws the exception)

That looks ok at first glance :-)
0
 
TimYatesCommented:
Can you post your connection code?
0
 
kerznerAuthor Commented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
kerznerAuthor Commented:
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
 
TimYatesCommented:
What happens if you change:

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

to

            props.put(Context.PROVIDER_URL, "jnp://" + JNDIContext.getJBossJmsUrl() + ":1099");
0
 
kerznerAuthor Commented:
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
 
TimYatesCommented:
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
 
kerznerAuthor Commented:
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
 
kerznerAuthor Commented:
No answer so far, I am back to JBoss 3.5
0
 
kerznerAuthor Commented:
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
 
TimYatesCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.