Doew anyone know th Initial Context properties for JMS?

K

Ken Baltrinic

I am trying to get the following code to work from a session bean running on
AppServer8. When I call new InitialContext(), the context I get pack has no
properties. This leads me to suspect that i need a jndi.properties file
with the correct settings. I suspect the settings I need are
java.naming.factory.initial and java.naming.provider.url but I don't know
what to set them to. I am also not sure exactly where to put the properties
file or how to tell the AppServer where to find it. Can anyone help?

Thanks in Advance,
Ken
 
K

Ken Baltrinic

This is what I cant get to work:

Context ctx = new InitialContext(prop);

//THe above line runs but contains an empty context.
//consequently the following fails.

TopicConnectionFactory topicConnectionFactory;
topicConnectionFactory = (TopicConnectionFactory) ctx.lookup(
"jms/log4jConnectionFactory");
 
S

Sudsy

Ken said:
I am trying to get the following code to work from a session bean running on
AppServer8. When I call new InitialContext(), the context I get pack has no
properties. This leads me to suspect that i need a jndi.properties file
with the correct settings. I suspect the settings I need are
java.naming.factory.initial and java.naming.provider.url but I don't know
what to set them to. I am also not sure exactly where to put the properties
file or how to tell the AppServer where to find it. Can anyone help?

It's specific to the app server; you'll have to dig into the
documentation to locate the definitive specification. I've
used code like this in the past:

Context context = null;
Properties props = new Properties();

try {
// for BEA WebLogic
props.put( Context.PROVIDER_URL,
"t3://hostname:7001" );
props.put( Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory" );
// for IBM WebSphere
props.put( Context.PROVIDER_URL,
"iiop://hostname" );
props.put( Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory" );
// for both
context = new InitialContext( props );
}
catch( NamingException e ) {
...
}

I don't run AppServer8 so I don't know that this is going to be of
any use whatsoever... :-(
 
O

Oscar kind

Ken Baltrinic said:
I am trying to get the following code to work from a session bean running on
AppServer8. When I call new InitialContext(), the context I get pack has no
properties. This leads me to suspect that i need a jndi.properties file
with the correct settings. I suspect the settings I need are
java.naming.factory.initial and java.naming.provider.url but I don't know
what to set them to. I am also not sure exactly where to put the properties
file or how to tell the AppServer where to find it. Can anyone help?

As Sudsy already pointed out, this depends on the application server
you're using. For Resin and Tomcat for example, no properties are needed.

Some examples:

Resin:
Context context = new InitialContext();
// Option 1
DataSource dataSource1 = (DataSource)context.lookup("jdbc/datasource");
// Option 2
DataSource dataSource2 = (DataSource)context.lookup("java:comp/env/jdbc/datasource");

Tomcat:
Context initialContext = new InitialContext();
// Option 1
Context context = (Context)initialContext.lookup("java:comp/env");
DataSource dataSource = (DataSource)context.lookup("jdbc/datasource");
// Option 2
DataSource dataSource2 = (DataSource)initialContext.lookup("java:comp/env/jdbc/datasource");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top