Solved

JMS Client for JBoss

Posted on 2004-09-08
8
1,680 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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

838 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