You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by August Detlefsen <au...@yahoo.com> on 2002/06/28 01:13:11 UTC

JNDI - What resources are loaded?

Is there a way to list all of the JNDI Resources that are loaded for a
particular context? 



__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: AW: JNDI - What resources are loaded?

Posted by Liam Morley <lm...@gdc.wpi.edu>.
JNDI, a standard extension for Java, stands for Java Naming and 
Directory Interface. The website at Sun's page: 
http://java.sun.com/products/jndi/ explains it a lot more than I could.

Best of luck,
Liam Morley

Power-Netz (Schwarz) wrote:

>OT: what is JNDI ???
>
>  
>
>>>Is there a way to list all of the JNDI Resources that are loaded for a
>>>particular context?
>>>      
>>>
>>Sure.
>>
>>Here is a snipp from my "JNDI browser" JSP:
>>
>><%@ page
>>  info="JNDI browser"
>>  import="javax.naming.*, javax.sql.*, java.sql.*"
>>  contentType="text/html; charset=windows-1250"
>>%><%!
>>static public String DEF_CPATH = "java:/";
>>%><%
>>//String contextPath = "java:comp/env/jdbc";
>>String contextPath = request.getParameter( "cpath" );
>>if( contextPath == null ) {
>>  contextPath = DEF_CPATH;
>>}
>>%>
>><html>
>><head>
>><title>Test - JNDI browser</title>
>><meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
>></head>
>>
>><body bgcolor="#FFFFFF" text="#000000">
>><h1>JNDI browser</h1>
>><p>Context looked up: <strong><%= contextPath %></strong></p>
>><%
>>InitialContext initCtx;
>>Context envCtx;
>>
>>initCtx = new InitialContext();
>>if( (envCtx = (Context)initCtx.lookup( contextPath )) == null ) {
>>  out.println( "<p>No " + contextPath + " context</p>" );
>>} else {
>>  NamingEnumeration enum = initCtx.listBindings( contextPath );
>>  int i = 1;
>>%>
>><table width="100%" border="1" cellspacing="0" cellpadding="3">
>>  <%
>>  while( enum.hasMore() ) {
>>%>
>>  <tr>
>>    <td><%= i %></td>
>>    <td><%= ((Binding)enum.next()).toString() %></td>
>>  </tr>
>><%
>>  }
>>%>
>></table>
>></body>
>></html>
>>
>>Nix.
>>
>>    
>>
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
>
>  
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


AW: JNDI - What resources are loaded?

Posted by "Power-Netz (Schwarz)" <sc...@power-netz.de>.
OT: what is JNDI ???

>
> > Is there a way to list all of the JNDI Resources that are loaded for a
> > particular context?
>
> Sure.
>
> Here is a snipp from my "JNDI browser" JSP:
>
> <%@ page
>   info="JNDI browser"
>   import="javax.naming.*, javax.sql.*, java.sql.*"
>   contentType="text/html; charset=windows-1250"
> %><%!
> static public String DEF_CPATH = "java:/";
> %><%
> //String contextPath = "java:comp/env/jdbc";
> String contextPath = request.getParameter( "cpath" );
> if( contextPath == null ) {
>   contextPath = DEF_CPATH;
> }
> %>
> <html>
> <head>
> <title>Test - JNDI browser</title>
> <meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
> </head>
>
> <body bgcolor="#FFFFFF" text="#000000">
> <h1>JNDI browser</h1>
> <p>Context looked up: <strong><%= contextPath %></strong></p>
> <%
> InitialContext initCtx;
> Context envCtx;
>
> initCtx = new InitialContext();
> if( (envCtx = (Context)initCtx.lookup( contextPath )) == null ) {
>   out.println( "<p>No " + contextPath + " context</p>" );
> } else {
>   NamingEnumeration enum = initCtx.listBindings( contextPath );
>   int i = 1;
> %>
> <table width="100%" border="1" cellspacing="0" cellpadding="3">
>   <%
>   while( enum.hasMore() ) {
> %>
>   <tr>
>     <td><%= i %></td>
>     <td><%= ((Binding)enum.next()).toString() %></td>
>   </tr>
> <%
>   }
> %>
> </table>
> </body>
> </html>
>
> Nix.
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JNDI - What resources are loaded?

Posted by Nikola Milutinovic <Ni...@ev.co.yu>.
August Detlefsen wrote:

> Thanks Nikola !
> 
> I was intrigued by this, so I took it a step further and made it
> recursive -it now lists all bindings with one click. I hope this is
> useful to someone: 

Heh, nice. I didn't want to go for recursion, since I was not sure how many 
levels of recursion I was facing.

Nix.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JNDI - What resources are loaded?

Posted by "Craig R. McClanahan" <cr...@apache.org>.
There is code very similar to this in the JNDI example of the standard
"examples" webapp that comes with Tomcat 4.

Craig


On Fri, 28 Jun 2002, August Detlefsen wrote:

> Date: Fri, 28 Jun 2002 12:52:49 -0700 (PDT)
> From: August Detlefsen <au...@yahoo.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>,
>      augustd@codemagi.com
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: Re: JNDI - What resources are loaded?
>
> Thanks Nikola !
>
> I was intrigued by this, so I took it a step further and made it
> recursive -it now lists all bindings with one click. I hope this is
> useful to someone:
>
> <%@ page
>     import="javax.naming.*"
> %>
>
> <HTML>
> <HEAD>
> <TITLE>JNDI Bindings</TITLE>
> </HEAD>
> <BODY>
>
> <%
>         Context initCtx = new InitialContext();
>
>         String initContextName = "java:";
>
>         displayContext(initContextName, "", out, initCtx);
> %>
>
> </BODY>
>
> <%!
>
>         private void displayContext(String contName, String
> prevContName, javax.servlet.jsp.JspWriter out, Context ctx)
>                 throws javax.naming.NamingException,
> java.io.IOException {
>
>                 String fieldSep = "/";
>                 if (prevContName == null || "".equals(prevContName) ||
> prevContName.endsWith(":") ) {
>                         fieldSep = "";
>                 }
>
>                 String lookupCtx = prevContName + fieldSep + contName;
>
>                 NamingEnumeration names = ctx.listBindings(lookupCtx);
>
>                 out.print("<UL>");
>
>                 while ( names.hasMore() ) {
>
>                         Binding bind = (Binding)names.next();
>
>                         out.print( "<LI><B>" + bind.getName() + "</B> =
> " + bind.getObject().toString() );
>
>                         if (bind.getObject() instanceof
> javax.naming.Context) {
>                                 displayContext(bind.getName(),
> lookupCtx, out, ctx);
>                         }
>                 }
>
>                 out.print("</UL>");
>
>         }
> %>
>
>
>
> --- Nikola Milutinovic <Ni...@ev.co.yu> wrote:
> > > Is there a way to list all of the JNDI Resources that are loaded
> > for a
> > > particular context?
> >
> > Sure.
> >
> > Here is a snipp from my "JNDI browser" JSP:
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! - Official partner of 2002 FIFA World Cup
> http://fifaworldcup.yahoo.com
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JNDI - What resources are loaded?

Posted by August Detlefsen <au...@yahoo.com>.
Thanks Nikola !

I was intrigued by this, so I took it a step further and made it
recursive -it now lists all bindings with one click. I hope this is
useful to someone: 

<%@ page
    import="javax.naming.*"
%>

<HTML>
<HEAD>
<TITLE>JNDI Bindings</TITLE>
</HEAD>
<BODY>

<%
        Context initCtx = new InitialContext();

        String initContextName = "java:";

        displayContext(initContextName, "", out, initCtx);
%>

</BODY>

<%!

        private void displayContext(String contName, String
prevContName, javax.servlet.jsp.JspWriter out, Context ctx) 
                throws javax.naming.NamingException,
java.io.IOException {

                String fieldSep = "/";
                if (prevContName == null || "".equals(prevContName) ||
prevContName.endsWith(":") ) {
                        fieldSep = "";
                }

                String lookupCtx = prevContName + fieldSep + contName;

                NamingEnumeration names = ctx.listBindings(lookupCtx);

                out.print("<UL>");

                while ( names.hasMore() ) {

                        Binding bind = (Binding)names.next();

                        out.print( "<LI><B>" + bind.getName() + "</B> =
" + bind.getObject().toString() );

                        if (bind.getObject() instanceof
javax.naming.Context) {
                                displayContext(bind.getName(),
lookupCtx, out, ctx);
                        }
                }

                out.print("</UL>");

        }
%>



--- Nikola Milutinovic <Ni...@ev.co.yu> wrote:
> > Is there a way to list all of the JNDI Resources that are loaded
> for a
> > particular context? 
> 
> Sure.
> 
> Here is a snipp from my "JNDI browser" JSP:


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JNDI - What resources are loaded?

Posted by Nikola Milutinovic <Ni...@ev.co.yu>.
> Is there a way to list all of the JNDI Resources that are loaded for a
> particular context? 

Sure.

Here is a snipp from my "JNDI browser" JSP:

<%@ page
  info="JNDI browser"
  import="javax.naming.*, javax.sql.*, java.sql.*"
  contentType="text/html; charset=windows-1250"
%><%!
static public String DEF_CPATH = "java:/";
%><%
//String contextPath = "java:comp/env/jdbc";
String contextPath = request.getParameter( "cpath" );
if( contextPath == null ) {
  contextPath = DEF_CPATH;
}
%>
<html>
<head>
<title>Test - JNDI browser</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<h1>JNDI browser</h1>
<p>Context looked up: <strong><%= contextPath %></strong></p>
<%
InitialContext initCtx;
Context envCtx;

initCtx = new InitialContext();
if( (envCtx = (Context)initCtx.lookup( contextPath )) == null ) {
  out.println( "<p>No " + contextPath + " context</p>" );
} else {
  NamingEnumeration enum = initCtx.listBindings( contextPath );
  int i = 1;
%>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
  <%
  while( enum.hasMore() ) {
%>
  <tr> 
    <td><%= i %></td>
    <td><%= ((Binding)enum.next()).toString() %></td>
  </tr>
<%
  }
%>
</table>
</body>
</html>

Nix.

Re: JNDI - What resources are loaded?

Posted by Will Hartung <wi...@msoft.com>.
----- Original Message -----
From: "Craig R. McClanahan" <cr...@apache.org>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Wednesday, July 10, 2002 3:53 PM
Subject: RE: JNDI - What resources are loaded?
>
>
> On Wed, 10 Jul 2002, Keith Wannamaker wrote:
> >
> > I'm creating a J2EE application that contains serveral web applications.
> > Is there a portable J2EE way to set up serveral global parameters in
JNDI
> > that can be accessed by all the web apps?  Or, is it necessary to
duplicate
> > all the parameters in each webapp's deployment descriptor?
>
> J2EE specs don't require the ability to share resources in this way, so
> there's no portability guarantee.  But Tomcat 4.1.x supports this.  In
> server.xml, you put the resources in a <GlobalNamingResources> section at
> the top of the file (or use the admin tool to configure them).  Then,
> inside the <Context> element for each webapp, you use a <ResourceLink>
> element that, in essence, acts like a symlink in the file system and
> points at the shared global resource.  For example, you could share a
> single connection pool across webapps this way.

The other potential option is to load these resources up on the J2EE side.
You can have "initialization" classes run on server startup, and those
classes should be able to populate the JNDI tree with their own entries.

Since most J2EE based servlets use the JNDI tree from the Appserver, this
should be shared across the seperate webapps.

This should be portable across both servlet and J2EE containers, though I've
never actually done this myself.

Lots of 'shoulds' in here, I haven't done this myself. It's just an idea.

Best Regards,

Will Hartung
(willh@msoft.com)




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JNDI - What resources are loaded?

Posted by Will Hartung <wi...@msoft.com>.
I guess that depends on what kind of resources you're using. JMS seems a
little bit heavyweight way to deal with this issue.

Why not simply have the resources returned from a Session Bean on the
appserver?

Regards,

Will Hartung
(willh@msoft.com)

----- Original Message -----
From: "Keith Wannamaker" <Ke...@Wannamaker.org>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Wednesday, July 10, 2002 9:52 PM
Subject: RE: JNDI - What resources are loaded?


> Portability is an issue, so it seems the best way
> to effect global parms in J2EE is to designate them
> for one component (say a web app), then use JMS to
> communicate the values to the other components
> (web apps).  Does this seem like the portable way
> to attack this problem?
>
> Keith
>
> | -----Original Message-----
> | From: Craig R. McClanahan [mailto:craigmcc@apache.org]
> | Sent: Wednesday, July 10, 2002 5:53 PM
> | To: Tomcat Users List
> | Subject: RE: JNDI - What resources are loaded?
> |
> |
> |
> |
> | J2EE specs don't require the ability to share resources in this way, so
> | there's no portability guarantee.  But Tomcat 4.1.x supports this.  In
> | server.xml, you put the resources in a <GlobalNamingResources> section
at
> | the top of the file (or use the admin tool to configure them).
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: JNDI - What resources are loaded?

Posted by Keith Wannamaker <Ke...@Wannamaker.org>.
Portability is an issue, so it seems the best way
to effect global parms in J2EE is to designate them
for one component (say a web app), then use JMS to
communicate the values to the other components 
(web apps).  Does this seem like the portable way
to attack this problem?  

Keith

| -----Original Message-----
| From: Craig R. McClanahan [mailto:craigmcc@apache.org]
| Sent: Wednesday, July 10, 2002 5:53 PM
| To: Tomcat Users List
| Subject: RE: JNDI - What resources are loaded? 
| 
| 
| 
| 
| J2EE specs don't require the ability to share resources in this way, so
| there's no portability guarantee.  But Tomcat 4.1.x supports this.  In
| server.xml, you put the resources in a <GlobalNamingResources> section at
| the top of the file (or use the admin tool to configure them). 

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: JNDI - What resources are loaded?

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 10 Jul 2002, Keith Wannamaker wrote:

> Date: Wed, 10 Jul 2002 18:14:12 -0500
> From: Keith Wannamaker <Ke...@Wannamaker.org>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: RE: JNDI - What resources are loaded?
>
> I'm creating a J2EE application that contains serveral web applications.
> Is there a portable J2EE way to set up serveral global parameters in JNDI
> that can be accessed by all the web apps?  Or, is it necessary to duplicate
> all the parameters in each webapp's deployment descriptor?
>
> If it were simply a group of webapps for tomcat, I'd just put the parms
> in the tomcat conf/web.xml file.  I guess a better way to phrase the
> question is, what is the preferred place for jndi parms in j2ee that
> are scoped for the entire application?
>

J2EE specs don't require the ability to share resources in this way, so
there's no portability guarantee.  But Tomcat 4.1.x supports this.  In
server.xml, you put the resources in a <GlobalNamingResources> section at
the top of the file (or use the admin tool to configure them).  Then,
inside the <Context> element for each webapp, you use a <ResourceLink>
element that, in essence, acts like a symlink in the file system and
points at the shared global resource.  For example, you could share a
single connection pool across webapps this way.

Of course, whether the resources are shared or not is something the server
administrator cares about -- as far as the application developer is
concerned, it always looks like a locally configured resource.  So you can
even do things like initially share a connection pool, then decide to give
a particular webapp its own connection pool instead, with zero impact on
the application itself.

> Thanks for any info,
> Keith
>

Craig


>
> | -----Original Message-----
> | From: Craig R. McClanahan [mailto:craigmcc@apache.org]
> | Sent: Thursday, June 27, 2002 7:02 PM
> | To: Tomcat Users List; augustd@codemagi.com
> | Subject: Re: JNDI - What resources are loaded?
> |
> | You can certainly look at your own context, using the standard JNDI APIs
> |
> | For security reasons, you won't be able to see anybody else's context, or
> | modify the one that Tomcat sets up for you.
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: JNDI - What resources are loaded?

Posted by Keith Wannamaker <Ke...@Wannamaker.org>.
I'm creating a J2EE application that contains serveral web applications.
Is there a portable J2EE way to set up serveral global parameters in JNDI 
that can be accessed by all the web apps?  Or, is it necessary to duplicate
all the parameters in each webapp's deployment descriptor?

If it were simply a group of webapps for tomcat, I'd just put the parms 
in the tomcat conf/web.xml file.  I guess a better way to phrase the 
question is, what is the preferred place for jndi parms in j2ee that 
are scoped for the entire application?

Thanks for any info,
Keith


| -----Original Message-----
| From: Craig R. McClanahan [mailto:craigmcc@apache.org]
| Sent: Thursday, June 27, 2002 7:02 PM
| To: Tomcat Users List; augustd@codemagi.com
| Subject: Re: JNDI - What resources are loaded? 
| 
| You can certainly look at your own context, using the standard JNDI APIs
| 
| For security reasons, you won't be able to see anybody else's context, or
| modify the one that Tomcat sets up for you.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JNDI - What resources are loaded?

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Thu, 27 Jun 2002, August Detlefsen wrote:

> Date: Thu, 27 Jun 2002 16:13:11 -0700 (PDT)
> From: August Detlefsen <au...@yahoo.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>,
>      augustd@codemagi.com
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: JNDI - What resources are loaded?
>
> Is there a way to list all of the JNDI Resources that are loaded for a
> particular context?
>

You can certainly look at your own context, using the standard JNDI APIs
-- for example, javax.naming.Context.list() or
javax.naming.Context.listBindings().  The JNDI example servlet in the
examples webapp uses this approach.

For security reasons, you won't be able to see anybody else's context, or
modify the one that Tomcat sets up for you.

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>