tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Watts <...@cliftonfarm.org>
Subject Re: [tomcat-6.0.33] META-INF/context.xml Environment not working
Date Thu, 22 Sep 2011 16:09:40 GMT
Thank you. Good point but basically the same result:

=== EXCEPTION ================================================
javax.servlet.ServletException: Failed initialization
	org.cliftonfarm.xbasic.Controller.init(Controller.java:32)
	javax.servlet.GenericServlet.init(GenericServlet.java:212)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
	org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	java.lang.Thread.run(Thread.java:636)

root cause 

javax.naming.NameNotFoundException: Name configName is not bound in this Context
	org.apache.naming.NamingContext.lookup(NamingContext.java:770)
	org.apache.naming.NamingContext.lookup(NamingContext.java:140)
	org.apache.naming.NamingContext.lookup(NamingContext.java:781)
	org.apache.naming.NamingContext.lookup(NamingContext.java:140)
	org.apache.naming.NamingContext.lookup(NamingContext.java:781)
	org.apache.naming.NamingContext.lookup(NamingContext.java:153)
	org.apache.naming.SelectorContext.lookup(SelectorContext.java:152)
	javax.naming.InitialContext.lookup(InitialContext.java:409)
	javax.naming.InitialContext.doLookup(InitialContext.java:282)
	org.cliftonfarm.xbasic.Controller.init(Controller.java:29)
	javax.servlet.GenericServlet.init(GenericServlet.java:212)
...

=== init() ================================================
	@Override
	public void init() throws ServletException {
		super.init();
        // get & store JNDI info
        try {
			configName = InitialContext.doLookup("java:comp/env/configName");
	}
        catch (NamingException e) {
			throw new ServletException("Failed initialization", e);
	}
        log(getClass().getName() +": Successfully initialized. configName=[" +configName +"]");
	}


On Thu, 2011-09-22 at 16:50 +0100, Pid * wrote:
> Why not do your initialisation in the Servlet.init() method?
> 
> 
> p
> 
> On 22 Sep 2011, at 16:42, Tim Watts <tim@cliftonfarm.org> wrote:
> 
> > Hello,
> >
> > My very basic servlet fails to initialize when trying to read its JNDI
> > environment entry. The app context name is xbasic. The context.xml is in
> > xbasic.war's META-INF directory and TomCat (6.0.33) correctly copies it
> > to ${tomcat.home}/conf/Catalina/localhost/xbasic.xml on first deploy.
> > Below are the relevant snippets. Can anyone see what I'm doing wrong or
> > is this a bug?
> >
> > BTW, I'm running this under openjdk 6.
> >
> >
> > === EXCEPTION ================================================
> > javax.servlet.ServletException: Error instantiating servlet class org.cliftonfarm.xbasic.Controller
> >    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
> >    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
> >    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
> >    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
> >    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
> >    java.lang.Thread.run(Thread.java:636)
> >
> > root cause
> >
> > javax.naming.NameNotFoundException: Name configName is not bound in this Context
> >    org.apache.naming.NamingContext.lookup(NamingContext.java:770)
> >    org.apache.naming.NamingContext.lookup(NamingContext.java:140)
> >    org.apache.naming.NamingContext.lookup(NamingContext.java:781)
> >    org.apache.naming.NamingContext.lookup(NamingContext.java:140)
> >    org.apache.naming.NamingContext.lookup(NamingContext.java:781)
> >    org.apache.naming.NamingContext.lookup(NamingContext.java:153)
> >    org.apache.naming.SelectorContext.lookup(SelectorContext.java:152)
> >    javax.naming.InitialContext.lookup(InitialContext.java:409)
> >    javax.naming.InitialContext.doLookup(InitialContext.java:282)
> >    org.cliftonfarm.xbasic.Controller.<init>(Controller.java:28)
> >    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> > ...
> >
> > === context.xml ================================================
> > <Context unpackWAR="false" privileged="false" antiResourceLocking="false" antiJARLocking="false">
> >    <Environment
> >        name="configName"
> >        value="${catalina.base}/local/xbasic/config/master.properties"
> >        description="Full path name of the config file."
> >        type="java.lang.String"/>
> >
> > </Context>
> >
> > === web.xml ================================================
> > <?xml version="1.0" encoding="UTF-8"?>
> > <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
> >  <display-name>Archetype Created Web Application</display-name>
> >  <servlet>
> >    <servlet-name>Controller</servlet-name>
> >    <servlet-class>org.cliftonfarm.xbasic.Controller</servlet-class>
> >  </servlet>
> >  <servlet-mapping>
> >    <servlet-name>Controller</servlet-name>
> >    <url-pattern>/*</url-pattern>
> >  </servlet-mapping>
> >  <env-entry>
> >      <env-entry-name>configName</env-entry-name>
> >      <env-entry-type>java.lang.String</env-entry-type>
> >  </env-entry>
> > </web-app>
> >
> > === Servlet constructor ========================================
> > public class Controller extends HttpServlet {
> >    private static final long serialVersionUID = 1L;
> >    private String configName;
> >
> >    /**
> >     * @throws NamingException
> >     * @see HttpServlet#HttpServlet()
> >     */
> >    public Controller() throws NamingException {
> >        super();
> >        // get & store JNDI info
> >        configName = InitialContext.doLookup("java:comp/env/configName"); // line
28
> >        log(getClass().getName() +": Successfully initialized. configName=[" +configName
+"]");
> >    }
> > ...
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message