Solved

JMS Client for JBoss

Posted on 2004-09-08
8
1,673 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 18

Expert Comment

by:armoghan
Comment Utility
Also give the credentials if needed
props.put(Context.SECURITY_PRINCIPAL, "guest");
props.put(Context.SECURITY_CREDENTIALS, "guest");
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Author Comment

by:kerzner
Comment Utility
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
Comment Utility
>
> 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
Comment Utility
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
Comment Utility
thanks:)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumHeights  challenge 17 59
pairstar challenge 2 41
Eclipse Neon and jdk 1.8.0 11 63
Problem to start Neon 20 48
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now