On Tue, 14 Aug 2001, Alex Garrett wrote:

> Forgive me if this is the wrong list to post to, but since it's a 
> source related question (as opposed to a use question) I thought this 
> list would be appropriate for my question.
> 
> I'm reading through the source code and trying to understand the 
> whole startup process -- how org.apache.catalina.startup.Catalina 
> gets everything up and running. Unfortunately, I'm at loggerheads on 
> one particular point. When the default server.xml file is parsed and 
> the "examples" context is created, there are some sample tags like 
> <Environment/> <Resource/> <Parameter/> and <Ejb/>. I realise that 
> these tags correspond to classes in the org.apache.catalina.deploy 
> package and that the classes are added to the StandardContext and 
> accessed through various find methods.
> 

Yes, that's right.

> Reading through the servlet spec (2.3pfd) it seems to me the purpose 
> of these tags is to clue the web app as to what J2EE resources it has 
> available. For example, the <ejb-ref/> tag provides the web app with 
> the name (among other things) of an EJB so it can get a naming 
> context and look up the EJB. Is this right?
> 

Yes.  The place to look for information about how an application uses this
stuff is in the J2EE Platform Specification (down near the bottom):

  http://java.sun.com/j2ee/download.html

In particular, look at Chapter 5:  "Naming".

The intent of the JNDI support in Tomcat 4 is to provide a compatible
environment for accessing <env-entry>, <resource-ref>, and
<resource-env-ref> values in Tomcat stand alone -- i.e. everything except
EJBs -- in a fashion that is identical to what you use on J2EE
servers.  See below for more.

> Here's where I'm lost. I can't find any methods in 
> javax.servlet.ServletContext that would provide access to the 
> ContextEjbs (or any of the other deploy classes). In other words, 
> StandardContext has the findEjb(String) method, but I don't see how 
> javax.servlet.ServletContext or 
> org.apache.catalina.core.ApplicationContext is able to access these 
> deploy elements.
> 
> Or have I completely misunderstood the purpose of the <Environment/> 
> <Resource/> <Parameter/> and <Ejb/> tags? In any respect, I'd greatly 
> appreciate a good dollop of enlightenment.
> 

Let's say that what you want to do is access a connection pool (i.e. an
implementation of javax.sql.DataSource) as you are building a web app on
Tomcat 4, and you want to use exactly the same code that you will use when
the app is deployed on a J2EE server -- something like this:

  Context initialContext = new InitialContext();
  DataSource ds = (DataSource)
   initialContext.lookup("java:comp/env/jdbc/EmployeeAppDB");
  Connection conn = ds.getConnection();
  ... use this Connection ...
  conn.close();  // Return connection to the pool

Now, in your application's web.xml, you declare a reference to this
connection pool, but without details:

  <resource-env-ref>
    <resource-env-ref-name>jdbc/EmployeeAppDb</resource-env-ref-name>
    <resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
  </resource-env-ref>

The actual linkage of this connection pool to a "real" database happens
inside Tomcat 4's "server.xml" file -- see the declaration of the
"/examples" context.

> Thanks,
>       Alex
> 
> 

Craig


Reply via email to