tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Brock <catc...@gmail.com>
Subject Changing embedded Tomcat from v6 to v7 causes InitialContext lookup to fail
Date Tue, 03 May 2011 11:54:52 GMT
(Note: this question is also on StackExchange at
http://stackoverflow.com/questions/5866237/)

I'm using JUnit test cases to exercise my web service using embedded
Tomcat. Under Tomcat 6 everything was working fine, but when I
switched my project to Tomcat 7 I'm coming unstuck.

The code I was using for Tomcat 6:

********

Embedded container = new Embedded();
container.setCatalinaHome("C:\\Program Files\\Apache Software
Foundation\\Tomcat 7.0.11");
container.setRealm(new MemoryRealm());
container.setName("Catalina");
Engine engine = container.createEngine();
container.addEngine(engine);
Host host = container.createHost("localhost", "/DecoderServiceTest");
Context rootContext = container.createContext("/DecoderServiceTest",
System.getProperty("user.dir") + "/build/web");
host.addChild(rootContext);
engine.setName("Catalina");
engine.addChild(host);
engine.setDefaultHost("localhost");
container.addEngine(engine);
Connector connector =
container.createConnector(InetAddress.getLocalHost(), 4321, false);
container.addConnector(connector);
container.start();

********

I've changed my code to use the new org.apache.catalina.startup.Tomcat
class (available in Tomcat 7) as follows:

******

Tomcat tomcat = new Tomcat();
tomcat.setBaseDir("C:\\Program Files\\Apache Software
Foundation\\Tomcat 7.0.11");
tomcat.setPort(1234);
tomcat.addWebApp("/DecoderServiceTest",
System.getProperty("user.dir")+"/build/web");
tomcat.setHostname("localhost");
tomcat.start();

******

The web application works when deployed to Tomcat 7 (in a non-embedded
state - obviously not using any of the above code), but when I run it
as an embedded server using the above Tomcat 7 code, I get JNDI
InitialContext complaints. The constructor of my web service does the
usual calls to setup a Context as follows:

********

  Context initCtx = new InitialContext();
  Context envCtx = (Context) initCtx.lookup("java:comp/env");
  int thumbnailSize = (Integer) envCtx.lookup("thumbnail-pixel-size");

********

but I receive a NamingException with the message that "Name java:comp
is not bound in this Context" when I try and create the envCtx
variable. I assume that I've missed a configuration parameter in the
setup of the embedded Tomcat 7 server but I haven't been able to put
my finger on it. Can anyone suggest what I can try?

I'm using Tomcat 7.0.11, Windows XP SP3 and NetBeans 7.0

Thanks.

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


Mime
View raw message