Solved

JMS Client for JBoss

Posted on 2004-09-08
8
1,685 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Containers and Docker for Everyone

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

724 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