aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes JMS and JNDI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JMS and JNDI" Watch "JMS and JNDI" New topic
Author

JMS and JNDI

Patrick ODonnell
Ranch Hand

Joined: Nov 28, 2001
Posts: 31
Hi all,
I am trying to connect to queues which may be on different MOM i.e. MQSeries, SonicMQ etc. I want to use a JNDI lookup to find queues.
I have read that InitialContext( ) can be created without properties (no-arg constructor) and in this case JNDI will read the vendor-specific JNDI properties from a special file in the classpath.
However no source code for this task was given, or what this 'special file' is(maybe properties file??).
Can anyone explain how this is done or even better show me some example code of how this is done?
Any help would be greatly appreciated!!
Thanks,
Patrick
Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
Hi,
I am not sure about
InitialContext ic= new InitialContext();
You must have to pass Hashtable/properties(ht) contains information about ContextFactory, Provider URL.
InitialContext ic= new InitialContext(ht);
Regards,
M.S.Raman.
Patrick ODonnell
Ranch Hand

Joined: Nov 28, 2001
Posts: 31
Thanks for your reply.
If I have a properties file as follows:
# Default Java 2 SDK, Enterprise Edition 1.3 Reference Implementation Settings
Java2SdkEe13.properties.java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory
Java2SdkEe13.properties.java.naming.factory.url.pkgs=com.sun.enterprise.naming
Java2SdkEe13.properties.queue.connectionfactory.name=QueueConnectionFactory
Java2SdkEe13.properties.queue.name=jms/Queue
Java2SdkEe13.properties.topic.connectionfactory.name=TopicConnectionFactory
Java2SdkEe13.properties.topic.name=jms/Topic
how would I set-up an initial context from this file?
Thanks,
Patrick.
Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
Hi,
I am not sure about j2ee server.
But with reference to the following url:
http://forum.sun.com/thread.jsp?forum=8&thread=6761
Context Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.enterprise.naming.SerialInitContextFactory");
prop.put(Context.PROVIDER_URL, "localhost:1050");
prop.put(Context.SECURITY_AUTHENTICATION, "simple");
prop.put(Context.SECURITY_PRINCIPAL, "guest");
prop.put(Context.SECURITY_CREDENTIALS, "guest123");
Context initial = new InitialContext(prop);
************************************************
Then in the try catch block use the following code
try
{
initial.lookup("QueueConnectionFactory");// for Queues.
}
catch(NamingException ne)
{ }

Regards,
M.S.Raman.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JMS and JNDI
 
Similar Threads
JNDI
How to configure properties in OC4J
Using JNDI to store and retrieve properties
How can MDB listen a remote queue ?
how to resolve this problem in simple stand alone java application.