rwaldhoff 01/08/16 16:59:15 Modified: httpclient/src/java/org/apache/commons/httpclient Tag: rlwrefactoring HttpMethodBase.java httpclient/src/test/org/apache/commons/httpclient Tag: rlwrefactoring TestWebapp.java TestWebappMethods.java TestWebappRedirect.java Added: httpclient/src/test/org/apache/commons/httpclient Tag: rlwrefactoring TestWebappBasicAuth.java Log: Adding authentication tests. Fixing HttpMethodBase due to those tests Updating some other tests based upon method name changes (setRequestBody instead of setData) Revision Changes Path No revision No revision 1.10.2.19 +28 -17 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java Index: HttpMethodBase.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v retrieving revision 1.10.2.18 retrieving revision 1.10.2.19 diff -u -r1.10.2.18 -r1.10.2.19 --- HttpMethodBase.java 2001/08/16 15:04:49 1.10.2.18 +++ HttpMethodBase.java 2001/08/16 23:59:14 1.10.2.19 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v 1.10.2.18 2001/08/16 15:04:49 rwaldhoff Exp $ - * $Revision: 1.10.2.18 $ - * $Date: 2001/08/16 15:04:49 $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v 1.10.2.19 2001/08/16 23:59:14 rwaldhoff Exp $ + * $Revision: 1.10.2.19 $ + * $Date: 2001/08/16 23:59:14 $ * ==================================================================== * Copyright (C) The Apache Software Foundation. All rights reserved. * @@ -62,7 +62,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a> * @author Rodney Waldhoff - * @version $Id: HttpMethodBase.java,v 1.10.2.18 2001/08/16 15:04:49 rwaldhoff Exp $ + * @version $Id: HttpMethodBase.java,v 1.10.2.19 2001/08/16 23:59:14 rwaldhoff Exp $ */ public abstract class HttpMethodBase implements HttpMethod { @@ -384,6 +384,16 @@ readResponse(state,connection); + if(HttpStatus.SC_CONTINUE == statusCode) { + if(!bodySent) { + bodySent = writeRequestBody(state,connection); + readResponse(state,connection); + } else { + log.warn("HttpMethodBase.execute(): received 100 response, but I've already sent the response."); + break; + } + } + if(!http11) { log.debug("HttpMethodBase.execute(): closing connection since we're using HTTP/1.0"); connection.close(); @@ -395,16 +405,6 @@ } } - if(HttpStatus.SC_CONTINUE == statusCode) { - if(!bodySent) { - bodySent = writeRequestBody(state,connection); - readResponse(state,connection); - } else { - log.warn("HttpMethodBase.execute(): received 100 response, but I've already sent the response."); - break; - } - } - if(HttpStatus.SC_UNAUTHORIZED == statusCode) { Header wwwauth = getResponseHeader("WWW-Authenticate"); if(null != wwwauth) { @@ -418,13 +418,19 @@ realms.add(foo); } - if(null == Authenticator.challengeResponse(wwwauth.getValue(),state)) { + String authresponse = null; + try { + authresponse = Authenticator.challengeResponse(wwwauth.getValue(),state); + } catch(HttpException e) { + // ignored + } + if(null == authresponse) { // won't be able to authenticate to this challenge // without additional information if(log.isDebugEnabled()) { log.debug("HttpMethodBase.execute(): Server demands authentication credentials, but none are available, so aborting."); } - return HttpStatus.SC_UNAUTHORIZED; + break; } else { if(log.isDebugEnabled()) { log.debug("HttpMethodBase.execute(): Server demands authentication credentials, will try again."); @@ -668,7 +674,12 @@ if(!requestHeaders.containsKey("authorization")) { Header wwwAuthenticateHeader = (Header)(responseHeaders.get("www-authenticate")); if(null != wwwAuthenticateHeader) { - String challengeResponse = Authenticator.challengeResponse(wwwAuthenticateHeader.getValue(),state); + String challengeResponse = null; + try { + challengeResponse = Authenticator.challengeResponse(wwwAuthenticateHeader.getValue(),state); + } catch(HttpException e) { + // ignored + } if (challengeResponse != null) { setRequestHeader("Authorization",challengeResponse); } No revision No revision 1.1.2.3 +5 -4 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/Attic/TestWebapp.java Index: TestWebapp.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/Attic/TestWebapp.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- TestWebapp.java 2001/08/14 22:39:21 1.1.2.2 +++ TestWebapp.java 2001/08/16 23:59:14 1.1.2.3 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/Attic/TestWebapp.java,v 1.1.2.2 2001/08/14 22:39:21 rwaldhoff Exp $ - * $Revision: 1.1.2.2 $ - * $Date: 2001/08/14 22:39:21 $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/Attic/TestWebapp.java,v 1.1.2.3 2001/08/16 23:59:14 rwaldhoff Exp $ + * $Revision: 1.1.2.3 $ + * $Date: 2001/08/16 23:59:14 $ * ==================================================================== * Copyright (C) The Apache Software Foundation. All rights reserved. * @@ -32,7 +32,7 @@ * "httpclient.test.webappContext" property. * * @author Rodney Waldhoff - * @version $Id: TestWebapp.java,v 1.1.2.2 2001/08/14 22:39:21 rwaldhoff Exp $ + * @version $Id: TestWebapp.java,v 1.1.2.3 2001/08/16 23:59:14 rwaldhoff Exp $ */ public class TestWebapp extends TestCase { @@ -46,6 +46,7 @@ suite.addTest(TestWebappParameters.suite()); suite.addTest(TestWebappHeaders.suite()); suite.addTest(TestWebappRedirect.suite()); + suite.addTest(TestWebappBasicAuth.suite()); return suite; } 1.1.2.4 +5 -5 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/Attic/TestWebappMethods.java Index: TestWebappMethods.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/Attic/TestWebappMethods.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- TestWebappMethods.java 2001/08/15 23:19:34 1.1.2.3 +++ TestWebappMethods.java 2001/08/16 23:59:14 1.1.2.4 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/Attic/TestWebappMethods.java,v 1.1.2.3 2001/08/15 23:19:34 rwaldhoff Exp $ - * $Revision: 1.1.2.3 $ - * $Date: 2001/08/15 23:19:34 $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/Attic/TestWebappMethods.java,v 1.1.2.4 2001/08/16 23:59:14 rwaldhoff Exp $ + * $Revision: 1.1.2.4 $ + * $Date: 2001/08/16 23:59:14 $ * ==================================================================== * Copyright (C) The Apache Software Foundation. All rights reserved. * @@ -32,7 +32,7 @@ * "httpclient.test.webappContext" property. * * @author Rodney Waldhoff - * @version $Id: TestWebappMethods.java,v 1.1.2.3 2001/08/15 23:19:34 rwaldhoff Exp $ + * @version $Id: TestWebappMethods.java,v 1.1.2.4 2001/08/16 23:59:14 rwaldhoff Exp $ */ public class TestWebappMethods extends TestCase { @@ -281,7 +281,7 @@ HttpClient client = new HttpClient(); client.startSession(host, port); PutMethod method = new PutMethod("/" + context + "/body"); - method.setData("This is data to be sent in the body of an HTTP PUT."); + method.setRequestBody("This is data to be sent in the body of an HTTP PUT."); try { client.executeMethod(method); } catch (Throwable t) { 1.1.2.4 +5 -8 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/Attic/TestWebappRedirect.java Index: TestWebappRedirect.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/Attic/TestWebappRedirect.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- TestWebappRedirect.java 2001/08/15 23:19:34 1.1.2.3 +++ TestWebappRedirect.java 2001/08/16 23:59:14 1.1.2.4 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/Attic/TestWebappRedirect.java,v 1.1.2.3 2001/08/15 23:19:34 rwaldhoff Exp $ - * $Revision: 1.1.2.3 $ - * $Date: 2001/08/15 23:19:34 $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/Attic/TestWebappRedirect.java,v 1.1.2.4 2001/08/16 23:59:14 rwaldhoff Exp $ + * $Revision: 1.1.2.4 $ + * $Date: 2001/08/16 23:59:14 $ * ==================================================================== * Copyright (C) The Apache Software Foundation. All rights reserved. * @@ -33,7 +33,7 @@ * "httpclient.test.webappContext" property. * * @author Rodney Waldhoff - * @version $Id: TestWebappRedirect.java,v 1.1.2.3 2001/08/15 23:19:34 rwaldhoff Exp $ + * @version $Id: TestWebappRedirect.java,v 1.1.2.4 2001/08/16 23:59:14 rwaldhoff Exp $ */ public class TestWebappRedirect extends TestCase { @@ -152,7 +152,7 @@ PutMethod method = new PutMethod("/" + context + "/redirect"); method.setFollowRedirects(true); method.setQueryString("to=" + URLEncoder.encode("http://" + host + ":" + port + "/" + context + "/body?foo=bar&bar=foo")); - method.setData("This is data to be sent in the body of an HTTP PUT."); + method.setRequestBody("This is data to be sent in the body of an HTTP PUT."); try { client.executeMethod(method); } catch (Throwable t) { @@ -163,7 +163,4 @@ assertEquals(200,method.getStatusCode()); } } - - - No revision No revision 1.1.2.1 +195 -0 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/Attic/TestWebappBasicAuth.java