Re: Problems in Starting up with ServletUnit
Izzy Alanis <[email protected]> Fri, 14 Jan 2011 09:43:46 -0500
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Message-ID | <[email protected]> |
Wolfgang doesn't get nearly as much help as he should around here. But, try using the ServletRunner constructor that takes a contextPath parameter (in addition to the web.xml file) -- just set it to null or the empty string if you don't actually want a context path. Wolfgang: I think this is a bug. That version of constructor sets the _contextDir field in WebApplication -- which helps the WebApplication class resolve the jsp file reference relative to the location of the web.xml file, but the other ServletRunner constructors don't set that field, which makes WebApplication resolve the jsp files relative to the current working directory. - Izzy 2011/1/13 Narinder Kumar <[email protected]>: > Hi Wolfgang, > Thanks for your reply. I will try to dig into it myself and get back to y= ou > with more information if I am able to find the root cause of the problem. > BTW : Are you the only one supporting httpunit and servlet modules or you > get some other collaborators as well from time to time ? > Best Regards > Narinder > > 2011/1/13 Wolfgang Fahl <[email protected]> >> >> Narinder, >> >> thanks for making the mailinglist a bit more active with your e-mail. >> I'd be happy to support you but there are two obstacles: >> - Servlet...something is not the part of httpunit I know well >> - I have other urgent issues on my agenda that hold me up. >> >> You might want to investigate a solution and post it accoring to the FAQ= s. >> >> Yours >> >> Wolfgang >> >> Am 13.01.11 11:19, schrieb Narinder Kumar: >> >> Hi, >> I was planning to unit test my Servlet through ServletUnit and ran across >> some problems : >> >> As a starting point, we are supposed to create a ServletRunner object. O= ne >> of the constructors expects File object with web.xml file. I provide the >> full path of my web.xml file but somehow it ignores the path provided and >> searches at the top level folder. The code-snippet and error message is >> below: >> >> <code> >> =A0=A0 =A0ServletRunner sr =3D new ServletRunner(new >> File("C:/eclipse-workspaces/pocs/lms-csd/src/main/webapp/WEB-INF/web.xml= ")); >> =A0 =A0ServletUnitClient sc =3D sr.newClient(); >> =A0 =A0WebRequest request =A0 =3D new >> PostMethodWebRequest("http://localhost/login" ); >> =A0 =A0request.setParameter( "userId", "test" ); >> =A0 =A0request.setParameter( "password", "csd" ); >> =A0 =A0WebResponse response =3D sc.getResponse(request); >> >> =A0 =A0String text =3D response.getText(); >> =A0 =A0Assert.assertTrue(text.contains("Welcome to Leave Management Syst= em")); >> </code> >> com.meterware.httpunit.HttpInternalErrorException: Error on HTTP request: >> 500 org.apache.jasper.JasperException: java.io.FileNotFoundException: >> C:\eclipse-workspaces\pocs\lms-csd\WEB-INF\web.xml (The system cannot fi= nd >> the path specified) [http://localhost/login] >> >> Why does the system keep on looking at the folder structure to be >> .../WEB-INF/web.xml. Mine is a maven project and I would not like to cha= nge >> the structure of the project to adapt this way. How can I make ServletRu= nner >> class to read from a specified folder ? >> >> In the Servlet code, I use the following code : >> >> =A0=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 String result =3D null >> =A0=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (someCondition) >> result =3D "/welcome.jsp"; >> } else { >> logger.warn("Password Validation failed"); >> request.setAttribute("failedlogin", new Boolean(true)); >> result =3D "/index.jsp"; >> } >> } >> RequestDispatcher requestDispatcher =3D >> getServletContext().getRequestDispatcher(result); >> requestDispatcher.forward(request, response); >> >> Again ServletUnit expects welcome.jsp to be at root foler, though jsp >> files are present at .../src/main/webapp/ folder. Again how can ServletU= nit >> be told about the target folder location ? >> >> Many thanks in advance. >> Best Regards >> Narinder >> >> >> ------------------------------------------------------------------------= ------ >> Protect Your Site and Customers from Malware Attacks >> Learn about various malware tactics and how to avoid them. Understand >> malware threats, the impact they can have on your business, and how you >> can protect your company and customers by using code signing. >> http://p.sf.net/sfu/oracle-sfdevnl >> >> _______________________________________________ >> Httpunit-develop mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/httpunit-develop >> >> -- >> >> BITPlan - smart solutions >> Wolfgang Fahl >> Pater-Delp-Str. 1, D-47877 Willich Schiefbahn >> Tel. +49 2154 811-480, Fax +49 2154 811-481 >> Web: http://www.bitplan.de >> BITPlan GmbH, Willich - HRB 6820 Krefeld, Steuer-Nr.: 10258040548, >> Gesch=E4ftsf=FChrer: Wolfgang Fahl >> >> >> ------------------------------------------------------------------------= ------ >> Protect Your Site and Customers from Malware Attacks >> Learn about various malware tactics and how to avoid them. Understand >> malware threats, the impact they can have on your business, and how you >> can protect your company and customers by using code signing. >> http://p.sf.net/sfu/oracle-sfdevnl >> _______________________________________________ >> Httpunit-develop mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/httpunit-develop >> > > > -------------------------------------------------------------------------= ----- > Protect Your Site and Customers from Malware Attacks > Learn about various malware tactics and how to avoid them. Understand > malware threats, the impact they can have on your business, and how you > can protect your company and customers by using code signing. > http://p.sf.net/sfu/oracle-sfdevnl > _______________________________________________ > Httpunit-develop mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/httpunit-develop > > ---------------------------------------------------------------------------= --- Protect Your Site and Customers from Malware Attacks Learn about various malware tactics and how to avoid them. Understand = malware threats, the impact they can have on your business, and how you = can protect your company and customers by using code signing. http://p.sf.net/sfu/oracle-sfdevnl