Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat: what is the init context params to use for making an external client connection to Tomcat 5.5 JNDI tree?

Tags:

tomcat

jndi

Currently I am using this for JBoss, but I need something also for an external Tomcat:

Properties props = new Properties();
props.put(Context.PROVIDER_URL, "jnp://localhost:1099");
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");
props.put("j2ee.clientName", "abtest");

Searching with Google I find this ones, but I am not able to figure out what Tomcat's port configuring to accept JNDI connection...

props.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.naming.java.javaURLContextFactory");
props.put(Context.PROVIDER_URL, "http://localhost:???");

Please can You help me?

like image 940
Steel Plume Avatar asked Nov 20 '25 00:11

Steel Plume


2 Answers

As far as I know, tomcat doe not support remote access to its JNDI tree, so you can access it only from the tomcat process. Because of that, The tomcat sets all the initialization params for the default InitialConext, and you can use it like this:

// Obtain our environment naming context
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");

// Look up our data source
DataSource ds = (DataSource)
  envCtx.lookup("jdbc/EmployeeDB");

// Allocate and use a connection from the pool
Connection conn = ds.getConnection();
... use this connection to access the database ...
conn.close();

You can also learn more of the JNDI in tomcat in this link

like image 60
David Rabinowitz Avatar answered Nov 22 '25 18:11

David Rabinowitz


I found this helpful link for using in Tomcat: EJB in Jboss called from Tomcat

It seems to be stupid, but in fact the approach in that topic is good enough to be considered. The main idea is here: The Tomcat server has its own JNDI system, so that an inside web-app must declare the JNDI they want to use first, then use that declaration to lookup the remote server's object (Jboss' EJB).

Hope that helps you,

Regards,

like image 34
mrdeath Avatar answered Nov 22 '25 19:11

mrdeath



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!