Return-Path: list-help: list-unsubscribe: List-Post: List-Id: Mailing-List: contact cactus-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list cactus-user@jakarta.apache.org Received: (qmail 38717 invoked from network); 11 Nov 2003 17:59:46 -0000 Received: from unknown (HELO smtp.noos.fr) (212.198.2.115) by daedalus.apache.org with SMTP; 11 Nov 2003 17:59:46 -0000 Received: (qmail 15729 invoked by uid 0); 11 Nov 2003 17:59:47 -0000 Received: from unknown (HELO vma) ([195.132.245.195]) (envelope-sender ) by 212.198.2.115 (qmail-ldap-1.03) with SMTP for ; 11 Nov 2003 17:59:47 -0000 From: "Vincent Massol" To: "'Cactus Users List'" Subject: RE: getServletContext() throws a NullPointerException Date: Tue, 11 Nov 2003 18:59:16 +0100 Message-ID: <014101c3a87d$86559580$2502a8c0@vma> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.4024 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 In-Reply-To: Importance: Normal X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Hi David, Are you sure you've called init(config)? See http://jakarta.apache.org/cactus/writing/howto_testcase_servlet.html (section "Tips and tricks"). Thanks -Vincent > -----Original Message----- > From: David Lemieux (QC/EMC) [mailto:David.Lemieux@ericsson.com] > Sent: 11 November 2003 17:20 > To: 'Cactus Users List' (E-mail) > Subject: getServletContext() throws a NullPointerException > > Hi, > > If I call the servlet directly, everything work fine. But if I run it with > cactus, it throws a NullPointerException. > I've included the junit ant log, the test class and the class under test. > There is nothing in the server log. > > The appserver is weblogic 8.1 > Cactus version is 1.5rc1 > > > /************************************************/ > /************************************************/ > [junit] Testcase: testExample took 1.016 sec > [junit] Testcase: testXXX took 0.094 sec > [junit] Testcase: testShouldNotBeSuccess took 0.031 sec > [junit] Testcase: testResultSessionBean took 0.219 sec > [junit] Testcase: testResponseHelloServlet took 0.187 sec > [junit] Caused an ERROR > [junit] null > [junit] java.lang.NullPointerException > [junit] at > javax.servlet.GenericServlet.getServletContext(GenericServlet.java:205) > [junit] at > XXX.applications.sampleapplication.HelloServlet.processRequest(Unknown > Source) > [junit] at > XXX.applications.sampleapplication.TestHelloServlet.testResponseHelloSer vl > et(Unknown Source) > [junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native > Method) > [junit] at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav a: > 39) > [junit] at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor Im > pl.java:25) > [junit] at > org.apache.cactus.ServletTestCase.runCactusTest(ServletTestCase.java:295 ) > [junit] at > org.apache.cactus.ServletTestCase.runBare(ServletTestCase.java:263) > [junit] at > org.apache.cactus.server.AbstractWebTestCaller.doTest(AbstractWebTestCal le > r.java:156) > [junit] at > org.apache.cactus.server.AbstractWebTestController.handleRequest_aroundB od > y0(AbstractWebTestController.java:130) > [junit] at > org.apache.cactus.server.AbstractWebTestController.handleRequest_aroundB od > y1$advice(AbstractWebTestController.java:158) > [junit] at > org.apache.cactus.server.AbstractWebTestController.handleRequest(Abstrac tW > ebTestController.java) > [junit] at > org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(Servle tT > estRedirector.java:138) > [junit] at > org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice (S > ervletTestRedirector.java:158) > [junit] at > org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirec to > r.java) > [junit] at > org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(Servlet Te > stRedirector.java:109) > [junit] at > org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice( Se > rvletTestRedirector.java:158) > [junit] at > org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirect or > .java) > [junit] at > javax.servlet.http.HttpServlet.service(HttpServlet.java:740) > [junit] at > javax.servlet.http.HttpServlet.service(HttpServlet.java:853) > [junit] at > weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(Se rv > letStubImpl.java:1053) > [junit] at > weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl. ja > va:387) > [junit] at > weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28) > [junit] at > weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java: 27 > ) > [junit] at > weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.r un > (WebAppServletContext.java:6316) > [junit] at > weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSu bj > ect.java:317) > [junit] at > weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118 ) > [junit] at > weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServl et > Context.java:3622) > [junit] at > weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl. ja > va:2569) > [junit] at > weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197) > [junit] at > weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170) > [junit] > [junit] Testcase: testResponseHelloServlet > [junit] TEST XXX.AllTest FAILED > > /******************************************************************/ > /******************************************************************/ > > package XXX.applications.sampleapplication; > > import java.io.IOException; > > import javax.servlet.ServletException; > > import junit.framework.Test; > import junit.framework.TestSuite; > > import org.apache.cactus.ServletTestCase; > import org.apache.cactus.WebRequest; > import org.apache.cactus.WebResponse; > > import XXX.test.genericframework.log.LoggerFactory; > > public class TestHelloServlet extends ServletTestCase{ > > ... > > public void beginResponseHelloServlet(WebRequest myWebRequest){ > > LoggerFactory.getInstance().logInfo("beginResponseHelloServlet","bef > ore addParameter"); > myWebRequest.addParameter("username","David"); > } > > public void endResponseHelloServlet(WebResponse theResponse){ > > LoggerFactory.getInstance().logInfo("endResponseHelloServlet","in > endXXX"); > assertTrue("Assert that the submitted name is the one on the > page",theResponse.getText().indexOf("David") != -1); > } > > > public void testResponseHelloServlet(){ > > LoggerFactory.getInstance().logInfo("testResponseHelloServlet","test > "); > HelloServlet myHelloServlet = new HelloServlet(); > > assertNotNull("servlet not null",myHelloServlet); > assertNotNull("request not null",request); > assertNotNull("response not null",response); > > try { > myHelloServlet.init(); > myHelloServlet.processRequest(request,response); > } catch (ServletException e) { > // XXX Auto-generated catch block > e.printStackTrace(); > fail(e.toString()); > } catch (IOException e) { > // XXX Auto-generated catch block > e.printStackTrace(); > fail(e.toString()); > } > } > } > /*********************************************************************** */ > /*********************************************************************** */ > > public void processRequest(HttpServletRequest > request,HttpServletResponse response) throws ServletException, IOException > { > > System.out.println("Debut"); > response.setContentType("text/html"); > response.setBufferSize(8192); > PrintWriter out = response.getWriter(); > > String message = null; > > ... // Set message using session bean > > if(message == null){ > message = ""; > } > // then write the data of the response > out.println("" + > "Hello"); > > // then write the data of the response > out.println("" + > " height=\"100\">" + > "

" + message + "

" + > "
" + > "" + > "

" + > "" + > "" + > "
"); > > String username = request.getParameter("username"); > if ( username != null && username.length() > 0 ) { > /* THE NEXT LINE THROWS THE EXCEPTION */ > /*******/ RequestDispatcher dispatcher = > getServletContext().getRequestDispatcher("/sampleapplication/hellorespon se > "); > > if (dispatcher != null){ > dispatcher.include(request, response); > } > > } > out.println(""); > out.close(); > System.out.println("Fin"); > } > /*********************************************************************** ** > *********/ > /*********************************************************************** ** > *********/ > > > David Lemieux >