Re: Getting Statuscode from WebResponse

"Wolfgang Fahl" <[email protected]>
Newsgroups gmane.comp.web.httpunit.devel
Organization BITPlan GmbH
Message-ID <[email protected]>
Mark wrote:
> first of all thanks for developing HTTPUnit.
> 
> Is there a way to get the statuscode (e.g 203) of a WebResponse?
> I use HTTPUnit to test RESTful Web Services and asserting a special 
> statuscode is one requirement.
The default response codes are defined in 
HttpURLConnection, e.g.:
/**
  * HTTP Status-Code 203: NonAuthoritative Information.
  */    
    public static final int HTTP_NOT_AUTHORITATIVE = 203; 



in WebClientTest.java you'll find an example for the 
handling:
    public void testNotFound() throws Exception {
        WebConversation wc = new WebConversation();
        WebRequest request = new GetMethodWebRequest( getHostPath() + "/nothing.htm" );
        try {
            wc.getResponse( request );
            fail( "Should have rejected the request" );
        } catch (HttpNotFoundException e) {
            assertEquals( "Response code", HttpURLConnection.HTTP_NOT_FOUND, e.getResponseCode() );
            assertEquals( "Response message", "unable to find /nothing.htm", e.getResponseMessage() );
        }
    }


It looks like it would be sufficient that you have your 
own Exception handling for non standard response-Codes.

Yours
  Wolfgang

(I'm also from germany - so simply give me a call if 
you'd like to discuss more details)

BITPlan - smart solutions
Pater-Delp-Str. 1, D-47877 Willich Schiefbahn
Tel. +49 1805 - BITPLAN / +49 1805 248 752, Fax +49 2154 811-481
Web: http://www.bitplan.de
bitplan GmbH, Willich - HRB 6820 Krefeld, VAT-ID: 10258040548, 
Geschäftsführer: Wolfgang Fahl

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

_______________________________________________
Httpunit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/httpunit-develop
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.