?
Solved

HTTPUnit does not find JSP pages

Posted on 2006-03-28
1
Medium Priority
?
863 Views
Last Modified: 2008-01-09
In my HttpServlet I redirect the request using the following:
request.getRequestDispatcher("/testpage.jsp").forward(request, response);

Then in my HTTPUnit TestCase I have the following:
public void testGet() throws Exception
{
        ServletRunner sr = new ServletRunner(new File(
            "WebContent/WEB-INF/web.xml"));
        ServletUnitClient client = sr.newClient();

        WebResponse response = client
            .getResponse("http://localhost:8080/MyRecord?username=tester");
        Assert.assertEquals(response.getResponseCode(),
            HttpServletResponse.SC_OK);
}

The tests works fine until it reaches the request redirection line in my servlet. It then fails with the following error:
com.meterware.httpunit.HttpInternalErrorException: Error on HTTP request: 500 org.apache.jasper.JasperException: C:\Documents and Settings\shahla\MyWorkspace\MyProject\WEB-INF\web.xml (The system cannot find the path specified) [http://localhost:8080/MyRecord?username=tester]
      at com.meterware.servletunit.ServletUnitClient.newResponse(ServletUnitClient.java:121)
      at com.meterware.httpunit.WebWindow.getResource(WebWindow.java:164)
      at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:128)
      at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:121)
      at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:102)
      at com.meterware.httpunit.WebClient.getResponse(WebClient.java:87)
      at test.LoadRecordTest.testGet(LoadRecordTest.java:45)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at junit.framework.TestCase.runTest(TestCase.java:154)
      at junit.framework.TestCase.runBare(TestCase.java:127)
      at junit.framework.TestResult$1.protect(TestResult.java:106)
      at junit.framework.TestResult.runProtected(TestResult.java:124)
      at junit.framework.TestResult.run(TestResult.java:109)
      at junit.framework.TestCase.run(TestCase.java:118)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

My web.xml has the following:
<servlet>
      <description></description>
      <display-name>LoadRecordServlet</display-name>
      <servlet-name>LoadRecordServlet</servlet-name>
      <servlet-class>test.LoadRecordServlet</servlet-class>
</servlet>
<servlet-mapping>
      <servlet-name>LoadRecordServlet</servlet-name>
      <url-pattern>/MyRecord</url-pattern>
</servlet-mapping>

The test passes when I commented out the line that redirects the request. Do I have to do something special to allow ServletUnitClient in HTTPUnit to follow redirections? Autoredirect is already set to true.

Any help is greatly appreciated.
0
Comment
Question by:salmasri
1 Comment
 
LVL 29

Accepted Solution

by:
bloodredsun earned 750 total points
ID: 16319418
It's not a redirection but an internal forward. A redirection invovles a response being send to the browser saying that the content has temporarily moved -  HTTP code 307.
Because the servlet does not actually do the response, I think you need to implement what is shown here http://httpunit.sourceforge.net/doc/servletunit-intro.html in the section entitled "Testing Servlet Internals"
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the below post we have mentioned the best hosting type for startups. Also, check out some of the superlative web hosting companies that are proposing affordable web hosting solutions to host your startup website.
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month17 days, 5 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question