Solved

JMS Client for JBoss

Posted on 2004-09-08
8
1,679 Views
Last Modified: 2013-11-24
Hi,

i am trying to write a client for JBoss JMS connection, and somehow it does not work. Here i what I have written so far

            Hashtable <String, String> props = new Hashtable <String, String> ();
            //props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
            props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.HttpNamingContextFactory");            
            props.put(Context.PROVIDER_URL, "http://localhost:1099");
            props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
           
            // Get the initial context with given properties
            ctx = new InitialContext(props);
            Object obj = ctx.lookup("ConnectionFactory");
            System.out.println(obj.getClass());
            // here I do not get the right object type
            topic = (Topic) ctx.lookup("topic/testTopic");
            // here it gives a ClassCastException

Thank you.
0
Comment
Question by:kerzner
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12012168
use the following to determine what class is actually returned:

System.out.println(ctx.lookup("topic/testTopic").getClass());
0
 
LVL 7

Expert Comment

by:lhankins
ID: 12012925
With JBoss, this is the pattern I typically follow (note: you typically use a different connection factory name if you're doing the lookup from inside the AppServer vs. from a remote client):

      boolean isServer = false;  // if you're doing this from inside the appserver, set this flag to true :

      String connectionFactoryName = isServer ? "java:ConnectionFactory" : "UIL2ConnectionFactory";
      TopicConnectionFactory factory = (TopicConnectionFactory) context.lookup(connectionFactoryName);

      TopicConnection topicConnection = factory.createTopicConnection();
      TopicSession topicSession = topicConnection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);

      Topic topic = (Topic) context.lookup("topic/testTopic");
      TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic);
     
      //--- "this" must implement the MessageListener
      topicSubscriber.setMessageListener(this);
      topicConnection.start();

0
 
LVL 18

Accepted Solution

by:
armoghan earned 500 total points
ID: 12013132
instead of this
props.put(Context.PROVIDER_URL, "http://localhost:1099");
try something like this, change the HTTP port accordingly
 props.put(Context.PROVIDER_URL,
                        "http://localhost:8080/invoker/JNDIFactory");
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 18

Expert Comment

by:armoghan
ID: 12013138
Also give the credentials if needed
props.put(Context.SECURITY_PRINCIPAL, "guest");
props.put(Context.SECURITY_CREDENTIALS, "guest");
0
 
LVL 1

Author Comment

by:kerzner
ID: 12017353
This advice

props.put(Context.PROVIDER_URL, "http://localhost:8080/invoker/JNDIFactory");

works better, it gets me a connection factory. however, the factory I get is this

class org.jboss.mq.SpyConnectionFactory

not the TopicConnectionFactory I would expect. So then, when I create a topic

topicConnectionFactory = (TopicConnectionFactory) ctx.lookup("ConnectionFactory");
topicConnection = topicConnectionFactory.createTopicConnection();

I get this error.

Exception in thread "main" java.lang.NoClassDefFoundError: EDU/oswego/cs/dl/util/concurrent/ThreadFactory

Thanks again.


0
 
LVL 7

Expert Comment

by:lhankins
ID: 12017532
>
> I get this error.

>  Exception in thread "main" java.lang.NoClassDefFoundError: EDU/oswego/cs/dl/util/concurrent/ThreadFactory
>

You need to add concurrent.jar to your client's classpath.   This jar (along with many other jboss client jars) are located under the <jboss-root>/client directory.
0
 
LVL 1

Author Comment

by:kerzner
ID: 12017591
Ok, maybe I should take my comment back. When I added the "concurrent.jar", I got this oswego resolved, and it seems to work now.
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12040843
thanks:)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

774 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