?
Solved

JMS Client for JBoss

Posted on 2004-09-08
8
Medium Priority
?
1,686 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 2000 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
DFW AZURE MEETUP TONIGHT FRI 6PM

We will be discussing what Azure Stack is, how does it fit into the suit of offerings that Azure has currently, and where can it fit into your organizations technology stack. We will also be discussing limitations of the platform while covering various applicable scenarios.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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:
Suggested Courses
Course of the Month8 days, 18 hours left to enroll

764 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