tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "King,Daniel" <dk...@IDFG.STATE.ID.US>
Subject RE: Accessing GlobalNamingResources
Date Thu, 25 Sep 2003 19:01:49 GMT
My own experience and what I have read on this and another user list, is that the kinks with
accessing a datasource in the < GlobalNamingResources> element have only just been worked
out with version 5.  Now you can access the global datasource with just a resource link in
your web app <Context>.  Previously (in version 4.1.27 and lower) I had to put the whole
data source element in the <Context> element of every web app.  By contrast, you can
now put your web app <Context> element in a separate XML file at $CATALINA_HOME/conf/Catalina/localhost,
where the prefix of the XML file name is the same name as the web application.  That keeps
your server.xml from getting too cluttered.   
 
But given all of the problems people have had just accessing a global data source, I would
be surprised if you can do it from your source code, with no resource link specified.  And
not to meddle, but wouldn't doing so tightly couple your web app to your data source details?

	-----Original Message----- 
	From: Miguel Vieira [mailto:miguel@bookmarc.pt] 
	Sent: Thu 9/25/2003 9:18 AM 
	To: tomcat-user@jakarta.apache.org 
	Cc: 
	Subject: RE: Accessing GlobalNamingResources
	
	

	Thank you for the reply João.
	
	I've tried the code with no success, all I got was:
	javax.naming.NameNotFoundException: Name leaders.archive is not bound
	in this Context
	...
	
	My server.xml file has the following GlobalNamingResources:
	<Listener
	className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
	debug="0"/>
	   <GlobalNamingResources>
	     <Environment description="This is a test!" name="leaders.archive"
	override="false" type="java.lang.String" value="LEADERS Archive"/>
	     <Environment name="simpleValue" override="true"
	type="java.lang.Integer" value="30"/>
	     <Resource auth="Container" description="User database that can be
	updated and saved" name="UserDatabase" scope="Shareable"
	type="org.apache.catalina.UserDatabase"/>
	     <ResourceParams name="UserDatabase">
	       <parameter>
	         <name>factory</name>
	        
	<value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
	       </parameter>
	       <parameter>
	         <name>pathname</name>
	         <value>conf/tomcat-users.xml</value>
	       </parameter>
	     </ResourceParams>
	   </GlobalNamingResources>
	
	Do I need to create a ResourceLink in the application context in order
	to read a value in the GlobalNamingResources?
	
	Thanks again,
	Miguel Vieira
	
	> Miguel,
	>
	>
	>
	> I'm assuming you want to access the values as defined for a given
	> parameter in your server.xml or in your web.xml files depending on
	> whether you want them defined globally or per application.
	>
	>
	>
	> Try the folling code in your jsp file and replace the parameter name
	> with the appropriate one.
	>
	>
	>
	> <<BEGIN CODE SNIPET>>
	>
	>    String my_var = "";
	>
	>    try
	>
	>    {
	>
	>       InitialContext initCtx      = new InitialContext();
	>
	>       if(initCtx == null) throw new Exception("Boom - No Context");
	>
	>       //Context envContext = (Context) initialContext.lookup
	> ("java:comp/env");
	>
	>       Context envCtx              =
	> (Context)initCtx.lookup("java:comp/env");
	>
	>               my_var            = (String)
	> envCtx.lookup("my_parameter_name");
	>
	>    }
	>
	>    catch(Exception e)
	>
	>    {
	>
	>       out.println(e.getMessage());
	>
	>       e.printStackTrace();
	>
	>    }
	>
	> <<END CODE SNIPET>>
	>
	>
	>
	> /JM
	>
	>
	>
	>> -----Original Message-----
	>> From: Miguel Vieira [mailto:[EMAIL PROTECTED]
	>> Sent: 25 September 2003 12:35
	>> To: [EMAIL PROTECTED]
	>> Subject: Accessing GlobalNamingResources
	>>
	>>
	>>
	>> Hi,
	>>
	>>
	>>
	>> I'm using Tomcat 4.1.19 and I'd like to know if it's possible to
	>> access
	>>
	>> the GlobalNamingResources, defined in server.xml, from a servlet,
	>>
	>> without creating a ResourceLink in the servlet's context?
	>>
	>>
	>>
	>> Thanks,
	>>
	>> Miguel Vieira
	
	
	---------------------------------------------------------------------
	To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
	For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
	
	
	

Mime
  • Unnamed multipart/mixed (inline, None, 0 bytes)
View raw message