commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/server ProxyAuthRequestHandler.java SimpleHttpServer.java
Date Mon, 09 Feb 2004 18:16:28 GMT
olegk       2004/02/09 10:16:28

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        MultiThreadedHttpConnectionManager.java
               httpclient/src/java/org/apache/commons/httpclient/auth
                        BasicScheme.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestBadContentLength.java TestProxy.java
               httpclient/src/test/org/apache/commons/httpclient/server
                        ProxyAuthRequestHandler.java SimpleHttpServer.java
  Log:
  Minor corrections to SimpleHttpServer related code
  
  Contributed by Oleg Kalnichevski
  
  Revision  Changes    Path
  1.32      +3 -4      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java
  
  Index: MultiThreadedHttpConnectionManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- MultiThreadedHttpConnectionManager.java	13 Jan 2004 18:47:25 -0000	1.31
  +++ MultiThreadedHttpConnectionManager.java	9 Feb 2004 18:16:28 -0000	1.32
  @@ -1404,7 +1404,6 @@
            * @see org.apache.commons.httpclient.HttpConnection#setSocketTimeout(int)
            */
           public void setSocketTimeout(int timeout) throws SocketException, IllegalStateException
{
  -            // TODO Auto-generated method stub
               if (hasConnection()) {
                   wrappedConnection.setSocketTimeout(timeout);
               } else {
  
  
  
  1.14      +6 -4      jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/BasicScheme.java
  
  Index: BasicScheme.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/BasicScheme.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- BasicScheme.java	14 Jan 2004 20:48:43 -0000	1.13
  +++ BasicScheme.java	9 Feb 2004 18:16:28 -0000	1.14
  @@ -210,6 +210,9 @@
   
           LOG.trace("enter BasicScheme.authenticate(Credentials, HttpMethod)");
   
  +        if (method == null) {
  +            throw new IllegalArgumentException("Method may not be null");
  +        }
           UsernamePasswordCredentials usernamepassword = null;
           try {
               usernamepassword = (UsernamePasswordCredentials) credentials;
  @@ -218,7 +221,6 @@
                       "Credentials cannot be used for basic authentication: " 
                       + credentials.getClass().getName());
           }
  -        
           return BasicScheme.authenticate(
               usernamepassword, 
               method.getParams().getCredentialCharset());
  
  
  
  1.4       +4 -23     jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestBadContentLength.java
  
  Index: TestBadContentLength.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestBadContentLength.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestBadContentLength.java	6 Jan 2004 20:08:56 -0000	1.3
  +++ TestBadContentLength.java	9 Feb 2004 18:16:28 -0000	1.4
  @@ -109,26 +109,7 @@
       // ----------------------------------------------------------- Test Methods
   
       public void setUp() throws IOException {
  -        /*
  -         * uncomment to enable wire log
  -         */
  -        /*       
  -        System.setProperty(
  -            "org.apache.commons.logging.Log",
  -            "org.apache.commons.logging.impl.SimpleLog");
  -        System.setProperty(
  -            "org.apache.commons.logging.simplelog.showdatetime",
  -            "true");
  -        System.setProperty(
  -            "org.apache.commons.logging.simplelog.log.httpclient.wire",
  -            "debug");
  -        System.setProperty(
  -            "org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient",
  -            "debug");
  -        */
  -
           client = new HttpClient();
  -
           server = new SimpleHttpServer(); // use arbitrary port
           server.setRequestHandler(new MyHttpRequestHandler());
       }
  
  
  
  1.4       +12 -21    jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestProxy.java
  
  Index: TestProxy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestProxy.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestProxy.java	11 Dec 2003 09:19:19 -0000	1.3
  +++ TestProxy.java	9 Feb 2004 18:16:28 -0000	1.4
  @@ -76,6 +76,9 @@
    */
   public class TestProxy extends TestCase {
   
  +    private static String TARGET_HOST = null;
  +    private static int TARGET_PORT = -1;
  +
       public TestProxy(String testName) {
           super(testName);
       }
  @@ -85,16 +88,9 @@
       }
   
       protected void setUp() throws Exception {
  -        /*
  -	 * System.setProperty("org.apache.commons.logging.Log",
  -	 * "org.apache.commons.logging.impl.SimpleLog");
  -	 * System.setProperty("org.apache.commons.logging.simplelog.showdatetime",
  -	 * "true");
  -	 * System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire",
  -	 * "debug");
  -	 * System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient",
  -	 * "debug");
  -	 */
  +        super.setUp();
  +        TARGET_HOST = System.getProperty("httpclient.test.localHost", "localhost");
  +        TARGET_PORT = Integer.parseInt(System.getProperty("httpclient.test.localPort",
"8080")); 
       }
   
       public void testSimpleGet() throws Exception {
  @@ -102,10 +98,7 @@
   
           HttpClient client = new HttpClient();
           HostConfiguration hc = new HostConfiguration();
  -        hc.setHost(
  -        System.getProperty("httpclient.test.localHost", "localhost"),
  -        Integer.parseInt(System.getProperty("httpclient.test.localPort", "8080")),
  -        Protocol.getProtocol("http"));
  +        hc.setHost(TARGET_HOST, TARGET_PORT, Protocol.getProtocol("http"));
           hc.setProxy(proxy.getLocalAddress(), proxy.getLocalPort());
           client.setHostConfiguration(hc);
   
  @@ -122,10 +115,7 @@
   
           HttpClient client = new HttpClient();
           HostConfiguration hc = new HostConfiguration();
  -        hc.setHost(
  -        System.getProperty("httpclient.test.localHost", "localhost"),
  -        Integer.parseInt(System.getProperty("httpclient.test.localPort", "8080")),
  -        Protocol.getProtocol("http"));
  +        hc.setHost(TARGET_HOST, TARGET_PORT, Protocol.getProtocol("http"));
           hc.setProxy(proxy.getLocalAddress(), proxy.getLocalPort());
           client.setHostConfiguration(hc);
           client.getState().setProxyCredentials(null, null, creds);
  @@ -135,4 +125,5 @@
           assertEquals(200, get.getStatusCode());
           get.releaseConnection();
       }
  +
   }
  
  
  
  1.7       +9 -20     jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/server/ProxyAuthRequestHandler.java
  
  Index: ProxyAuthRequestHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/server/ProxyAuthRequestHandler.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ProxyAuthRequestHandler.java	12 Jan 2004 18:50:15 -0000	1.6
  +++ ProxyAuthRequestHandler.java	9 Feb 2004 18:16:28 -0000	1.7
  @@ -67,9 +67,8 @@
   
   import org.apache.commons.httpclient.Credentials;
   import org.apache.commons.httpclient.Header;
  -import org.apache.commons.httpclient.auth.AuthenticationException;
  +import org.apache.commons.httpclient.UsernamePasswordCredentials;
   import org.apache.commons.httpclient.auth.BasicScheme;
  -import org.apache.commons.httpclient.auth.MalformedChallengeException;
   
   /**
    * This request handler guards access to a proxy when used in a request handler
  @@ -77,6 +76,7 @@
    * authentication handshake if necessary.
    * 
    * @author Ortwin Glueck
  + * @author Oleg Kalnichevski
    */
   public class ProxyAuthRequestHandler implements HttpRequestHandler {
       private Credentials credentials;
  @@ -152,21 +152,10 @@
        * @param clientAuth
        */
       private boolean checkAuthorization(Header clientAuth) {
  -        // TODO Auto-generated method stub
  -        BasicScheme scheme;
  -        try {
  -            scheme = new BasicScheme();
  -            scheme.processChallenge("basic realm=test");
  -            String expectedAuthString = scheme.authenticate(credentials, null);
  -            return expectedAuthString.equals(clientAuth.getValue());
  -        } catch (MalformedChallengeException e) {
  -            // TODO Auto-generated catch block
  -            e.printStackTrace();
  -        } catch (AuthenticationException e) {
  -            // TODO Auto-generated catch block
  -            e.printStackTrace();
  -        }
  -        return false;
  +        String expectedAuthString = BasicScheme.authenticate(
  +            (UsernamePasswordCredentials)credentials,
  +            "ISO-8859-1");
  +        return expectedAuthString.equals(clientAuth.getValue());
       }
   
       private Header findHeader(Header[] headers, String name) {
  
  
  
  1.3       +15 -4     jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/server/SimpleHttpServer.java
  
  Index: SimpleHttpServer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/server/SimpleHttpServer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SimpleHttpServer.java	5 Dec 2003 21:23:15 -0000	1.2
  +++ SimpleHttpServer.java	9 Feb 2004 18:16:28 -0000	1.3
  @@ -64,6 +64,7 @@
   package org.apache.commons.httpclient.server;
   
   import java.io.IOException;
  +import java.net.InetAddress;
   import java.net.ServerSocket;
   import java.net.Socket;
   import java.net.SocketException;
  @@ -132,7 +133,17 @@
        * @return String representation of the IP address or <code>null</code>
if not running
        */
       public String getLocalAddress() {
  -    	return server.getInetAddress().getHostAddress();
  +        InetAddress address = server.getInetAddress();
  +        // Ugly work-around for older JDKs
  +        byte[] octets = address.getAddress();
  +        if ((octets[0] == 0) 
  +         && (octets[1] == 0) 
  +         && (octets[2] == 0) 
  +         && (octets[3] == 0)) {
  +            return "localhost"; 
  +        } else {
  +            return address.getHostAddress();
  +        }
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message