Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JMS and JNDI

 
Patrick ODonnell
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic