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 Kim Madsen <ki...@inceptor.com> on 2002/03/05 16:35:17 UTC

com.meterware.httpunit.WebResponse

I have found a problem when using 

public void endXXX(com.meterware.httpunit.WebResponse theResponse)

in a Cactus test case.

In my Servlet I do a
	response.setHeader("Content-Type", "text/html");

When I latter check it using com.meterware.httpunit.WebResponse I get an
assertion error because it says the header is "text/html, text/html":

Unexpected content type expected:<text/html> but was:<text/html,
text/html> 

junit.framework.AssertionFailedError: Unexpected content type
expected:<text/html> but was:<text/html, text/html>


However, if I use
public void endXXX(org.apache.cactus.WebResponse theResponse)

in my Cactus test case, the headers is "text/html" - as expected.

I do not know, if this is a Cactus bug or a Meterware bug.
Any advice?

The code is as follows:


    /* Bug in Cactus or Meterware?
     * Context header comes back as "text/html, text/html"
     * Where it was expected to be "text/html".
     */
    public void endServeResource(com.meterware.httpunit.WebResponse
theResponse) {

	try {
	    assertEquals("Unexpected content type",
			 "text/html",
			 theResponse.getHeaderField("Content-Type"));	    
	} catch (Exception e) {
	    fail(e);
	}
    }

    /* This works fine
     */
    public void endServeResource(org.apache.cactus.WebResponse
theResponse) {

	try {
	    java.net.HttpURLConnection connection = 
		theResponse.getConnection();

	    assertEquals("Unexpected content type",
			 "text/html", connection.getContentType());
	} catch (Exception e) {
	    fail(e);
	}
    }


Again this is not an urgent problem, as I already found the work arround
it.

Cheers, Kim

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: com.meterware.httpunit.WebResponse

Posted by Kim Madsen <ki...@inceptor.com>.
Thanks for your help, that make me realize that it was caused by me not
using the Servlet API correctly...

Was was using
        response.setHeader("Content-Type", "text/html");
where I should have been using
        response.setContentType("text/html");

I have changed that in my servlet, and it now works on the same version
of HttpUnit, where it previously failed.

However, it was probably for the best, that it was discovered, because
even when I used 
        response.setHeader("Content-Type", "text/html");
the Servlet was working (returning the ContentType Header correctly)
when invoked directly (e.g. using telnet).

Cheers, Kim

Russell Gold wrote:
> 
> At 3:35 PM +0000 3/5/02, Kim Madsen wrote:
> >I have found a problem when using
> >
> >public void endXXX(com.meterware.httpunit.WebResponse theResponse)
> >
> >in a Cactus test case.
> >
> >In my Servlet I do a
> >       response.setHeader("Content-Type", "text/html");
> >
> >When I latter check it using com.meterware.httpunit.WebResponse I get an
> >assertion error because it says the header is "text/html, text/html":
> >
> >Unexpected content type expected:<text/html> but was:<text/html,
> >text/html>
> >
> >junit.framework.AssertionFailedError: Unexpected content type
> >expected:<text/html> but was:<text/html, text/html>
> >
> >
> >However, if I use
> >public void endXXX(org.apache.cactus.WebResponse theResponse)
> >
> >in my Cactus test case, the headers is "text/html" - as expected.
> >
> >I do not know, if this is a Cactus bug or a Meterware bug.
> >Any advice?
> 
> I have found and fixed a bug in HttpUnit which could possibly cause this. The scenario occurs when a servlet returns multiple headers with the same key. Normally, this should not be possible AFAIK, but it may be that you have found a way around it.
> 
> The newest code in cvs (soon to be released) will check only the first header for the getContentType method.
> --
> ------------------------------------------------------------------------
> Russell Gold                     | "... society is tradition and order
> russgold@acm.org                 | and reverence, not a series of cheap
>                                  | bargains between selfish interests."
> http://www.httpunit.org          |   - Poul Anderson, "Iron"
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: com.meterware.httpunit.WebResponse

Posted by Russell Gold <ru...@acm.org>.
At 3:35 PM +0000 3/5/02, Kim Madsen wrote:
>I have found a problem when using
>
>public void endXXX(com.meterware.httpunit.WebResponse theResponse)
>
>in a Cactus test case.
>
>In my Servlet I do a
>	response.setHeader("Content-Type", "text/html");
>
>When I latter check it using com.meterware.httpunit.WebResponse I get an
>assertion error because it says the header is "text/html, text/html":
>
>Unexpected content type expected:<text/html> but was:<text/html,
>text/html>
>
>junit.framework.AssertionFailedError: Unexpected content type
>expected:<text/html> but was:<text/html, text/html>
>
>
>However, if I use
>public void endXXX(org.apache.cactus.WebResponse theResponse)
>
>in my Cactus test case, the headers is "text/html" - as expected.
>
>I do not know, if this is a Cactus bug or a Meterware bug.
>Any advice?

I have found and fixed a bug in HttpUnit which could possibly cause this. The scenario occurs when a servlet returns multiple headers with the same key. Normally, this should not be possible AFAIK, but it may be that you have found a way around it.

The newest code in cvs (soon to be released) will check only the first header for the getContentType method.
-- 
------------------------------------------------------------------------
Russell Gold                     | "... society is tradition and order
russgold@acm.org                 | and reverence, not a series of cheap
                                 | bargains between selfish interests."
http://www.httpunit.org          |   - Poul Anderson, "Iron"

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: com.meterware.httpunit.WebResponse

Posted by Vincent Massol <vm...@octo.com>.
Kim,

As an educated guess, I would say it looks like a HttpUnit bug ;-)

This is my guess because Cactus is completely transparent with regards
to the HttpServletResponse object (no wrapping, nothing). Also, on the
client side, the content type is set using :

        connection.setRequestProperty("Content-type",
            theRequest.getContentType());

where connection is a HttpURLConnection object.

Have you sent this mail to the HttpUnit mailing-list.

-Vincent

P.S.: Can you please not use BCC when sending mail to the list ?

> -----Original Message-----
> From: kim [mailto:kim] On Behalf Of Kim Madsen
> Sent: 05 March 2002 21:05
> Subject: com.meterware.httpunit.WebResponse
> 
> I have found a problem when using
> 
> public void endXXX(com.meterware.httpunit.WebResponse theResponse)
> 
> in a Cactus test case.
> 
> In my Servlet I do a
> 	response.setHeader("Content-Type", "text/html");
> 
> When I latter check it using com.meterware.httpunit.WebResponse I get
an
> assertion error because it says the header is "text/html, text/html":
> 
> Unexpected content type expected:<text/html> but was:<text/html,
> text/html>
> 
> junit.framework.AssertionFailedError: Unexpected content type
> expected:<text/html> but was:<text/html, text/html>
> 
> 
> However, if I use
> public void endXXX(org.apache.cactus.WebResponse theResponse)
> 
> in my Cactus test case, the headers is "text/html" - as expected.
> 
> I do not know, if this is a Cactus bug or a Meterware bug.
> Any advice?
> 
> The code is as follows:
> 
> 
>     /* Bug in Cactus or Meterware?
>      * Context header comes back as "text/html, text/html"
>      * Where it was expected to be "text/html".
>      */
>     public void endServeResource(com.meterware.httpunit.WebResponse
> theResponse) {
> 
> 	try {
> 	    assertEquals("Unexpected content type",
> 			 "text/html",
> 			 theResponse.getHeaderField("Content-Type"));
> 	} catch (Exception e) {
> 	    fail(e);
> 	}
>     }
> 
>     /* This works fine
>      */
>     public void endServeResource(org.apache.cactus.WebResponse
> theResponse) {
> 
> 	try {
> 	    java.net.HttpURLConnection connection =
> 		theResponse.getConnection();
> 
> 	    assertEquals("Unexpected content type",
> 			 "text/html", connection.getContentType());
> 	} catch (Exception e) {
> 	    fail(e);
> 	}
>     }
> 
> 
> Again this is not an urgent problem, as I already found the work
arround
> it.
> 
> Cheers, Kim
> 
> --
> To unsubscribe, e-mail:   <mailto:cactus-user-
> unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:cactus-user-
> help@jakarta.apache.org>
> 




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>