You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Chris Hane <ch...@hane.com> on 2001/10/30 10:30:36 UTC
Httpunit Content-type Error
I've been trying to test a struts action/jsp using cactus/httpunit and have
run into the following error as displayed by junit:
com.meterware.httpunit.NotHTMLException: The content type of the response
is 'text/plain': it must be 'text/html' in order to be recognized as HTML
at
com.meterware.httpunit.WebResponse.getReceivedPage(WebResponse.java:789)
at com.meterware.httpunit.WebResponse.getForms(WebResponse.java:261)
at com.hane.lms.pages.loginTest.endLogin(loginTest.java:63)
at
org.apache.cactus.AbstractTestCase.callEndMethod(AbstractTestCase.java:304)
at
org.apache.cactus.AbstractTestCase.runGenericTest(AbstractTestCase.java:425)
at org.apache.cactus.ServletTestCase.runTest(ServletTestCase.java:130)
at
org.apache.cactus.AbstractTestCase.runBare(AbstractTestCase.java:371)
I'm trying to understand how cactus works so that I can integrate it into
my development cycle. I have a single test that I'm trying to execute that
uses the struts.ActionServlet. The only logic the struts.Action contains
is to return a forward to a jsp page. I'm not changing the content-type
that should be returned. By what I can tell, the ActionServlet
content-type default to return is 'text/html'. I've also tried adding a
content-type to the jsp file; however, the <meta> tag doesn't seem to have
any change.
Any thoughts on what I've got going on here would be appreciated? I've
also included some of the specific example I'm using below:
My setup is as follows:
cactus 1.3dev
httpunit1.2.7
struts nightly build from 9/24/01
junit 3.7
tomcat 4.0
The TestClass I'm using:
public class loginTest extends ServletTestCase {
[setup/standard code deleted....]
public void beginLogin(WebRequest theRequest) {
theRequest.setURL("localhost:8080","/LMS","/cgi/login",null,null);
}
public void testLogin() {
org.apache.struts.action.ActionServlet servlet = new ActionServlet();
try{
servlet.init(config);
servlet.doPost(request,response);
} catch (Exception ex){
//do nothing right now....
}
}
public void endLogin( com.meterware.httpunit.WebResponse response) {
try{
com.meterware.httpunit.WebForm wf = response.getForms()[0];
assertNull(wf.getParameterValue("userName"));
assertNull(wf.getParameterValue("userPassword"));
assertNull(wf.getParameterValue("resumeWorkflow"));
}catch(org.xml.sax.SAXException ex){
//does nothing right now...
}
}
The jsp file being returned by the struts forward:
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="htmlStruts" %>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title>LMS - Login</title>
<htmlStruts:base/>
</head>
<body>
<H1>Welcome</H1><BR/>
<B>This the the LMS demonstration. Before continuing you will need
to login.</B><BR/>
<htmlStruts:errors/></BR>
<htmlStruts:form action="/login">
<TABLE>
<TR><TD>User Name</TD><TD><htmlStruts:text property="userName"
size="50"/></TD></TR>
<TR><TD>Password</TD> <TD><htmlStruts:password
property="userPassword" size="50" redisplay="false"/></TD></TR>
</TABLE>
<htmlStruts:hidden property="resumeWorkflow"/>
<htmlStruts:submit>Login</htmlStruts:submit>
</htmlStruts:form>
</body>
</html>
Thanks,
Chris....
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Httpunit Content-type Error
Posted by Russell Gold <ru...@acm.org>.
At 03:30 AM 10/30/2001 -0600, Chris Hane wrote:
>I've been trying to test a struts action/jsp using cactus/httpunit and
>have run into the following error as displayed by junit:
>
>com.meterware.httpunit.NotHTMLException: The content type of the response
>is 'text/plain': it must be 'text/html' in order to be recognized as HTML
> at
> com.meterware.httpunit.WebResponse.getReceivedPage(WebResponse.java:789)
> at com.meterware.httpunit.WebResponse.getForms(WebResponse.java:261)
> at com.hane.lms.pages.loginTest.endLogin(loginTest.java:63)
> at
> org.apache.cactus.AbstractTestCase.callEndMethod(AbstractTestCase.java:304)
> at
> org.apache.cactus.AbstractTestCase.runGenericTest(AbstractTestCase.java:425)
> at
> org.apache.cactus.ServletTestCase.runTest(ServletTestCase.java:130)
> at
> org.apache.cactus.AbstractTestCase.runBare(AbstractTestCase.java:371)
>
>I'm trying to understand how cactus works so that I can integrate it into
>my development cycle. I have a single test that I'm trying to execute
>that uses the struts.ActionServlet. The only logic the struts.Action
>contains is to return a forward to a jsp page. I'm not changing the
>content-type that should be returned. By what I can tell, the
>ActionServlet content-type default to return is 'text/html'. I've also
>tried adding a content-type to the jsp file; however, the <meta> tag
>doesn't seem to have any change.
>
>Any thoughts on what I've got going on here would be appreciated? I've
>also included some of the specific example I'm using below:
Try this: call HttpUnitOptions.setLoggingHttpHeaders( true ) before running
your test to see what headers are actually coming back from the redirector.
You want to see if a content-type header of any type is coming back. <meta>
tags are only processed if the response is declared to be text.
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>