Programatically setting web.xml in embedded Tomcat
Hi all, I'm currently using Tomcat's embedded feature for unit testing of a web service. This web service displays different behaviour depending on the contents of the web.xml file. I therefore want to exercise different web.xml configurations in my unit tests. Currently the setup code I'm using is as follows: Tomcat tomcat = new Tomcat(); tomcat.setBaseDir(catalinaHome); tomcat.setPort(port); tomcat.addWebapp(/ServiceTest, System.getProperty(user.dir) + build/web); tomcat.setHostname(localhost); tomcat.enableNaming(); tomcat.start(); As you can see, the webapp is currently sourced from the NetBeans build directory. What is the best way for me to test different web.xml files? Is there a way I can set the webapp to the same directory as I am currently, but point at a web.xml file that is somewhere else? (I'm not too keen on altering the build/web directory just in case the test fails and ends up breaking the real web.xml file.) My fall-back position is to have my test cases make a temporary copy of the build/web directory and then override the web.xml file with the one I want to use in that specific test case, but I was wondering if there is a more elegant solution. My environment is: Tomcat 7.0.11 NetBeans 7.0 Windows XP Thanks, Andrew
Re: Changing embedded Tomcat from v6 to v7 causes InitialContext lookup to fail
Ah, that was it - thanks. Andrew On 3 May 2011 21:57, Andrew Brock catc...@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 users@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-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
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-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
JasperException: No tag xhtml defined in tag library associated with uri urn:jsptagdir:/WEB-INF/tags
Hi, I am trying to support an existing web site in jspx. I have setup Tomcat on a Windows server as a test environment before I deploy my changes. However I cannot open the index page. I get this error and I am not sure how to fix it http://localhost:8080/viewscast/index.jspx: HTTP Status 500 - _ type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: No tag xhtml defined in tag library associated with uri urn:jsptagdir:/WEB-INF/tags org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServle tWrapper.java:510) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.ja va:375) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) root cause org.apache.jasper.JasperException: No tag xhtml defined in tag library associated with uri urn:jsptagdir:/WEB-INF/tags org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHand ler.java:50) ... The following is the code from the index.jspx page: tags:xhtml xmlns:tags=urn:jsptagdir:/WEB-INF/tags xmlns:jsp=http://java.sun.com/JSP/Page; xmlns:c=http://java.sun.com/jsp/jstl/core; xmlns:fmt=http://java.sun.com/jsp/jstl/fmt; xmlns:syn=http://www.synovate.com/core; xmlns=http://www.w3.org/1999/xhtml; jsp:directive.page contentType=text/html; charset=utf-8 language=java session=false/ head c:import url=/jspf/http-equiv.jspx/ c:import url=/jspf/meta.jspx/ c:import url=/jspf/link.jspx/ c:import url=/viewscast/jspf/link.jspx/ c:import url=/viewscast/jspf/silo.change.jspx/ /head body class=index div id=hide#160;/div c:import url=/viewscast/jspf/menu.cool.jspx/ div id=wrapper table border=0 cellpadding=0 cellspacing=0 height=100% tr td valign=top height=353 c:import url=/viewscast/jspf/header.jspx/ c:import url=/viewscast/jspf/menu.jspx/ c:import url=/viewscast/jspf/index.silos.jspx/ /td /tr tr td valign=top div id=headlines div id=left a href=${langPath}/current/news/div id=title#160;/div/a /div div id=news div id=padding c:import url=/jspf/latest.news.jspx/ /div /div div id=right a href=${langPath}/current/news/More news #187;/a /div /div /td /tr tr td style=height:51px c:import url=/jspf/inside.footer.jspx/ c:import url=/viewscast/jspf/footer.jspx/ /td /tr /table /div div id=onepix#160;/div /body /tags:xhtml I have tried downloading the xtags and adding them to the WEB_INF folder in the ROOT directory but this has not helped. Any assistance would be greatly appreciated. Many thanks Andrew