You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Andrew Brock <ca...@gmail.com> on 2011/05/03 13:54:52 UTC

Changing embedded Tomcat from v6 to v7 causes InitialContext lookup to fail

(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


Re: Changing embedded Tomcat from v6 to v7 causes InitialContext lookup to fail

Posted by Andrew Brock <ca...@gmail.com>.
Ah, that was it - thanks.

Andrew


On 3 May 2011 21:57, Andrew Brock <ca...@gmail.com> wrote:
> ---------- Forwarded message ----------
> From: Mark Thomas <ma...@apache.org>
> Date: 3 May 2011 21:51
> Subject: Re: Changing embedded Tomcat from v6 to v7 causes
> InitialContext lookup to fail
> To: Tomcat Users List <us...@tomcat.apache.org>
>
>
> On 03/05/2011 12:54, Andrew Brock wrote:
>> (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.
>>
>> 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();
>
> Add the following before you start the instance:
>
> tomcat.enableNaming()
>
> Mark
>
>
>
> ---------------------------------------------------------------------
> 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


Re: Changing embedded Tomcat from v6 to v7 causes InitialContext lookup to fail

Posted by Mark Thomas <ma...@apache.org>.
On 03/05/2011 12:54, Andrew Brock wrote:
> (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.
> 
> 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();

Add the following before you start the instance:

tomcat.enableNaming()

Mark



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