Re: [tomcat-6.0.33] META-INF/context.xml Environment not working

2011-09-23 Thread Mark Thomas
On 23/09/2011 05:37, Tim Watts wrote:
 Wonderful. Thank You!
 
 You're right about Parameter/context-param but I'm not sure all
 standards conforming servlet containers are guaranteed to provide an
 'external override' behaviour.

If the resource entry in web.xml is insufficient to fully configure the
resource, they'll have to provide some form of mechanism for this.

You might also want to read:
http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html#web.xml_configuration
and
http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html#context.xml_configuration

Mark

 
 
 On Fri, 2011-09-23 at 07:07 +0400, Konstantin Kolinko wrote:
 2011/9/22 Tim Watts t...@cliftonfarm.org:
 6.0.33

Environment
name=configName

 value=${catalina.base}/local/xbasic/config/master.properties
description=Full path name of the config file.
type=java.lang.String/

 I got it to work by removing the env-entry from web.xml.

 You have to add override=false to your Environment element. It is
 tricky, but it is documented

 http://tomcat.apache.org/tomcat-6.0-doc/config/context.html#Environment_Entries


 BTW, I think Parameter (context-param in web.xml) are easier to
 use. Note that it requires override=false as well.

 Best regards,
 Konstantin Kolinko

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

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


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



Re: [tomcat-6.0.33] META-INF/context.xml Environment not working

2011-09-22 Thread Pid *
Why not do your initialisation in the Servlet.init() method?


p

On 22 Sep 2011, at 16:42, Tim Watts t...@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-nameArchetype Created Web Application/display-name
  servlet
servlet-nameController/servlet-name
servlet-classorg.cliftonfarm.xbasic.Controller/servlet-class
  /servlet
  servlet-mapping
servlet-nameController/servlet-name
url-pattern/*/url-pattern
  /servlet-mapping
  env-entry
  env-entry-nameconfigName/env-entry-name
  env-entry-typejava.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-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: [tomcat-6.0.33] META-INF/context.xml Environment not working

2011-09-22 Thread Tim Watts
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 t...@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; 
  

RE: [tomcat-6.0.33] META-INF/context.xml Environment not working

2011-09-22 Thread Leo Donahue - PLANDEVX
-Original Message-
From: Tim Watts [mailto:t...@cliftonfarm.org]
Subject: [tomcat-6.0.33] META-INF/context.xml Environment not working

=== 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


In my context.xml, I use type=javax.sql.DataSource, and I'm using a 
Resource element instead of Environment

Resource
name=configName
auth=Container
type=javax.sql.DataSource
username=username
password=password
driverClassName=whatever driver you have
url=your jdbc driver connection stuff/

resource-ref
descriptionDB Connection/description
res-ref-nameconfigName/res-ref-name
res-typejavax.sql.DataSource/res-type
res-authContainer/res-auth
/resource-ref

=== 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-nameArchetype Created Web Application/display-name
  servlet
servlet-nameController/servlet-name
servlet-classorg.cliftonfarm.xbasic.Controller/servlet-class
  /servlet
  servlet-mapping
servlet-nameController/servlet-name
url-pattern/*/url-pattern
  /servlet-mapping
  env-entry
   env-entry-nameconfigName/env-entry-name
   env-entry-typejava.lang.String/env-entry-type
  /env-entry
/web-app


I don't have a env-entry in my web.xml


=== 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 +]);
}
...

My version of this code, with your name:

private DataSource ds;

public void createDataSource(){
// Setup the DataSource Context
try{
Context ctx = new InitialContext();
ds = (DataSource) ctx.lookup(java:comp/env/configName);

} catch (NamingException ex){

FacesContext.getCurrentInstance().getExternalContext().log(DataSource lookup 
failed, ex);
}
}


RE: [tomcat-6.0.33] META-INF/context.xml Environment not working

2011-09-22 Thread Tim Watts
I got it to work by removing the env-entry from web.xml. I believe
this is a regression because it works correctly under 5.5.17. Under
5.5.17 it finds the env entry with or without having defined in web.xml.
Under 6.0.33 having the env entry defined in web.xml *prevents* it from
finding it.


On Thu, 2011-09-22 at 09:10 -0700, Leo Donahue - PLANDEVX wrote:
 -Original Message-
 From: Tim Watts [mailto:t...@cliftonfarm.org]
 Subject: [tomcat-6.0.33] META-INF/context.xml Environment not working
 
 === 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
 
 
 In my context.xml, I use type=javax.sql.DataSource, and I'm using a 
 Resource element instead of Environment
 
   Resource
 name=configName
   auth=Container
   type=javax.sql.DataSource
   username=username
   password=password
   driverClassName=whatever driver you have
 url=your jdbc driver connection stuff/
 
   resource-ref
   descriptionDB Connection/description
   res-ref-nameconfigName/res-ref-name
   res-typejavax.sql.DataSource/res-type
   res-authContainer/res-auth
   /resource-ref
 
 === 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-nameArchetype Created Web Application/display-name
   servlet
 servlet-nameController/servlet-name
 servlet-classorg.cliftonfarm.xbasic.Controller/servlet-class
   /servlet
   servlet-mapping
 servlet-nameController/servlet-name
 url-pattern/*/url-pattern
   /servlet-mapping
   env-entry
  env-entry-nameconfigName/env-entry-name
  env-entry-typejava.lang.String/env-entry-type
   /env-entry
 /web-app
 
 
 I don't have a env-entry in my web.xml
 
 
 === 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 +]);
 }
 ...
 
 My version of this code, with your name:
 
 private DataSource ds;
 
 public void createDataSource(){
 // Setup the DataSource Context
 try{
 Context ctx = new InitialContext();
 ds = (DataSource) ctx.lookup(java:comp/env/configName);
 
 } catch (NamingException ex){
 
 FacesContext.getCurrentInstance().getExternalContext().log(DataSource lookup 
 failed, ex);
 }
 }



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



Re: [tomcat-6.0.33] META-INF/context.xml Environment not working

2011-09-22 Thread Konstantin Kolinko
2011/9/22 Tim Watts t...@cliftonfarm.org:
 6.0.33

        Environment
                name=configName
                value=${catalina.base}/local/xbasic/config/master.properties
                description=Full path name of the config file.
                type=java.lang.String/

 I got it to work by removing the env-entry from web.xml.

You have to add override=false to your Environment element. It is
tricky, but it is documented

http://tomcat.apache.org/tomcat-6.0-doc/config/context.html#Environment_Entries


BTW, I think Parameter (context-param in web.xml) are easier to
use. Note that it requires override=false as well.

Best regards,
Konstantin Kolinko

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



Re: [tomcat-6.0.33] META-INF/context.xml Environment not working

2011-09-22 Thread Tim Watts
Wonderful. Thank You!

You're right about Parameter/context-param but I'm not sure all
standards conforming servlet containers are guaranteed to provide an
'external override' behaviour.


On Fri, 2011-09-23 at 07:07 +0400, Konstantin Kolinko wrote:
 2011/9/22 Tim Watts t...@cliftonfarm.org:
  6.0.33
 
 Environment
 name=configName
 
  value=${catalina.base}/local/xbasic/config/master.properties
 description=Full path name of the config file.
 type=java.lang.String/
 
  I got it to work by removing the env-entry from web.xml.
 
 You have to add override=false to your Environment element. It is
 tricky, but it is documented
 
 http://tomcat.apache.org/tomcat-6.0-doc/config/context.html#Environment_Entries
 
 
 BTW, I think Parameter (context-param in web.xml) are easier to
 use. Note that it requires override=false as well.
 
 Best regards,
 Konstantin Kolinko
 
 -
 To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
 For additional commands, e-mail: users-h...@tomcat.apache.org
 



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