rwaldhoff    01/05/17 16:58:51

  Modified:    httpclient build.properties.sample build.xml STATUS.html
               httpclient/src/java/org/apache/commons/httpclient
                        HttpClient.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestAll.java
  Added:       httpclient README.txt
               httpclient/src/test/org/apache/commons/httpclient
                        TestHttps.java
  Log:
  * Adding support for HTTPS to HttpClient
  * Added test cases for this
  * Mods to build.xml, build.properties.sample, and STATUS.html to reflect dependency 
on JSSE
  * Adding README.txt with deployment and build instructions
  
  Revision  Changes    Path
  1.2       +9 -1      jakarta-commons/httpclient/build.properties.sample
  
  Index: build.properties.sample
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/build.properties.sample,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- build.properties.sample   2001/04/25 18:42:49     1.1
  +++ build.properties.sample   2001/05/17 23:58:50     1.2
  @@ -1,2 +1,10 @@
   # junit.jar - JUnit 3.2+ Classpath
  -junit.jar=/java/junit/junit.jar
  \ No newline at end of file
  +junit.jar=/java/junit/junit.jar
  +# jsse.jar - JSSE classes (see http://java.sun.com/products/jsse)
  +#  XXX if we were using the classpath=${foo}:${bar} form,
  +#      rather than path elements to set the classpath, we could
  +#      put this as one property:
  +#      
jsse.jar=/java/jsse/lib/jsse.jar:/java/jsse/lib/jcert.jar:/java/jsse/lib/jnet.jar
  +jsse.jar=/java/jsse/lib/jsse.jar
  +jcert.jar=/java/jsse/lib/jcert.jar
  +jnet.jar=/java/jsse/lib/jnet.jar
  \ No newline at end of file
  
  
  
  1.3       +14 -6     jakarta-commons/httpclient/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/build.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- build.xml 2001/04/30 18:24:39     1.2
  +++ build.xml 2001/05/17 23:58:50     1.3
  @@ -3,7 +3,7 @@
   
   <!--
           "HTTP Client" component of the Jakarta Commons Subproject
  -        $Id: build.xml,v 1.2 2001/04/30 18:24:39 remm Exp $
  +        $Id: build.xml,v 1.3 2001/05/17 23:58:50 rwaldhoff Exp $
   -->
   
   
  @@ -56,7 +56,6 @@
     <!-- The base directory for unit test sources -->
     <property name="test.home"               value="src/test"/>
   
  -
   <!-- ========== Compiler Defaults ========================================= -->
   
   
  @@ -73,6 +72,8 @@
     <path id="compile.classpath">
       <pathelement location="${build.home}/classes"/>
       <pathelement location="${junit.jar}"/>
  +    <pathelement location="${jsse.jar}"/>
  +    <pathelement location="${jnet.jar}"/>
     </path>
   
   
  @@ -84,6 +85,9 @@
       <pathelement location="${build.home}/classes"/>
       <pathelement location="${build.home}/tests"/>
       <pathelement location="${junit.jar}"/>
  +    <pathelement location="${jsse.jar}"/>
  +    <pathelement location="${jcert.jar}"/>
  +    <pathelement location="${jnet.jar}"/>
     </path>
   
     <!-- Should all tests fail if one does? -->
  @@ -93,6 +97,9 @@
     <property name="test.runner"             value="junit.textui.TestRunner"/>
     <property name="test.entry" value="org.apache.commons.httpclient.TestAll"/>
   
  +  <!-- HTTPS protocol handler, needed for HTTPS unit tests -->
  +  <property name="java.protocol.handler.pkgs" 
value="-Djava.protocol.handler.pkgs=com.sun.net.ssl.internal.www.protocol"/>
  +
   
   <!-- ========== Executable Targets ======================================== -->
   
  @@ -202,7 +209,7 @@
   <!-- ========== Unit Test Targets ========================================= -->
   
   
  -  <target name="test"  depends="compile.tests" if="test.entry" 
  +  <target name="test"  depends="compile.tests" if="test.entry"
      description="Run all unit test cases">
         <!--
         <junit printsummary="yes" fork="on" haltonfailure="yes">
  @@ -211,10 +218,11 @@
           <classpath refid="test.classpath"/>
         </junit>
         -->
  -      
  -      <java classname="${test.runner}" fork="yes" 
  +
  +      <java classname="${test.runner}" fork="yes"
          failonerror="${test.failonerror}">
  -        <arg value="${test.entry}"/> 
  +        <jvmarg value="${java.protocol.handler.pkgs}"/>
  +        <arg value="${test.entry}"/>
           <classpath refid="test.classpath"/>
         </java>
     </target>
  
  
  
  1.3       +11 -6     jakarta-commons/httpclient/STATUS.html
  
  Index: STATUS.html
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/STATUS.html,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- STATUS.html       2001/04/27 20:24:20     1.2
  +++ STATUS.html       2001/05/17 23:58:50     1.3
  @@ -7,7 +7,7 @@
   
   <div align="center">
   <h1>The Jakarta Commons <em>HTTP Client</em> Component</h1>
  -$Id: STATUS.html,v 1.2 2001/04/27 20:24:20 morgand Exp $<br>
  +$Id: STATUS.html,v 1.3 2001/05/17 23:58:50 rwaldhoff Exp $<br>
   <a href="#Introduction">[Introduction]</a>
   <a href="#Dependencies">[Dependencies]</a>
   <a href="#Release Info">[Release Info]</a>
  @@ -28,16 +28,20 @@
    <p>
     The original source was donated by the Jakarta Slide project.
    </p>
  - 
   
  +
   <a name="Dependencies"></a>
   <h3>2.  DEPENDENCIES</h3>
   
  -<p>The <em>HTTP CLient</em> component is dependent upon the following 
  +<p>The <em>HTTP CLient</em> component is dependent upon the following
   external components for development and use:</p>
   <ul>
   <li><a href="http://java.sun.com/j2se";>Java Development Kit</a>
  -    (Version 1.1 or later)</li>
  +    (Version 1.2 or later)</li>
  +<li><a href="http://java.sun.com/products/jsse";>Java Secure Socket Extension</a>
  +    (Version 1.0.2 or later)
  +    (Required for compliation/testing. Only needed at runtime if
  +    you're using HTTPS URLs.)</li>
   </ul>
   
   
  @@ -62,6 +66,7 @@
   <li>Juergen Pill</li>
   <li>Costin Manolache</li>
   <li>Morgan Delagrange</li>
  +<li>Rodney Waldhoff</li>
   </ul>
   
   <a name="Action Items"></a>
  @@ -84,7 +89,7 @@
     </tr>
   
     <tr>
  -    <td><strong>Developer Documentation</strong>.  Create simple Developer's 
  +    <td><strong>Developer Documentation</strong>.  Create simple Developer's
           Guide documentation for this component.</td>
       <td align="center">&nbsp;</td>
     </tr>
  @@ -95,7 +100,7 @@
     </tr>
   
     <tr>
  -    <td><strong>Developer Documentation</strong>.  Create simple Developer's 
  +    <td><strong>Developer Documentation</strong>.  Create simple Developer's
           Guide documentation for this component.</td>
       <td align="center">&nbsp;</td>
     </tr>
  
  
  
  1.1                  jakarta-commons/httpclient/README.txt
  
  Index: README.txt
  ===================================================================
  Jakarta Commons HTTP Client
  ===========================
  
  Welcome to the httpclient component of the Jakarta Commons
  project.
  
  To compile the source, you'll want the excellent Ant utility.
  It can be found here :
  
    http://jakarta.apache.org/ant/
  
  You'll also need an implementation of the
  Java Secure Socket Extension, a standard Java
  extension available from :
  
    http://java.sun.com/products/jsse
  
  To let the build and test process use JSSE, you may make a
  copy of the build.properties.sample file, rename to
  build.properties, and modify it to reflect the location of
  the jsse.jar, jnet.jar and jcert.jar on your computer.
  
  You'll also need to configure your JRE to use JSSE as a
  security provider.  To do this, edit the java.security file
  (typically in [JAVA-HOME]/jre/lib/security) and add the line:
  
  security.provider.<n>=com.sun.net.ssl.internal.ssl.Provider
  
  where <n> is one greater than the existing security.provider.*
  properties.
  
  NOTE: On Windows, the standard JDK install will create two
  JRE installations, one in %JAVA_HOME% and the other in
  your Program Files folder.  Typically the one in Program Files
  is the one that matters.
  
  (Note that JSSE is only needed at runtime if you are going
  to be using HTTPS URLs.  You will need it to build from source,
  however.)
  
  
  For testing the project, you will also need JUnit :
  
    http://www.junit.org/
  
  To let the test process find JUnit, you may make a
  copy of the build.properties.sample file, rename to
  build.properties,  and modify it to reflect
  the location of the junit.jar on your computer.
  
  (Note that JUnit is only needed to build and execute
  the unit tests.  It is not needed to build the
  "regular" classes, nor is it needed at runtime.)
  
  Once you have Ant propertly installed, and the
  build.properties file correctly reflects the location
  of JUnit and JSSE, you are ready to build and test.
  
  To compile and test the component :
  
  $ ant test
  
  To build a jar :
  
  $ ant dist
  
  To build the API documentation :
  
  $ ant javadoc
  
  To build the jar and API doc at once :
  
  $ ant dist
  
  
  
  1.13      +89 -43    
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java
  
  Index: HttpClient.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- HttpClient.java   2001/05/13 20:31:11     1.12
  +++ HttpClient.java   2001/05/17 23:58:51     1.13
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
 1.12 2001/05/13 20:31:11 remm Exp $
  - * $Revision: 1.12 $
  - * $Date: 2001/05/13 20:31:11 $
  + * $Header: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
 1.13 2001/05/17 23:58:51 rwaldhoff Exp $
  + * $Revision: 1.13 $
  + * $Date: 2001/05/17 23:58:51 $
    *
    * ====================================================================
    *
  @@ -74,11 +74,28 @@
   import java.net.UnknownHostException;
   import java.net.URL;
   import java.lang.reflect.Method;
  +import javax.net.ssl.SSLSocket;
  +import javax.net.ssl.SSLSocketFactory;
   
   /**
    * HTTP client main class.
  + * <p>
  + * HTTPS URLs are now supported.  To use HTTPS, you'll
  + * need an implementation of the
  + * <a href="http://java.sun.com/products/jsse/";>Java Secure Sockets Extension</a>
  + * installed and configured.  Make sure that you've enabled
  + * the appropriate provider with your JRE (e.g., set
  + * <br>
  + * <tt>security.provider.<i>&lt;n&gt;</i>=com.sun.net.ssl.internal.ssl.Provider</tt>
  + * <br>
  + * in your JRE's <tt>java.security</tt> file) and with the
  + * VM that is running the HttpClient (e.g., set the
  + * system property <tt>java.protocol.handler.pkgs</tt>
  + * to include your provider, such as <tt>com.sun.net.ssl.internal.www.protocol</tt>
  + * for the reference implementation of JSSE).
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Rodney Waldhoff</a>
    */
   public class HttpClient {
   
  @@ -110,13 +127,13 @@
   
   
       /**
  -     * Preferred constructor for HttpClient.  Call 
  -     * {@link #startSession(URL)} or 
  +     * Preferred constructor for HttpClient.  Call
  +     * {@link #startSession(URL)} or
        * {@link #startSession(String, int)} to begin a
        * session.
  -     * 
  -     * <b>Note:</b> The HttpClient constructors used to 
  -     * implicitly start a session.  That behavior has been 
  +     *
  +     * <b>Note:</b> The HttpClient constructors used to
  +     * implicitly start a session.  That behavior has been
        * removed.
        */
       public HttpClient() {
  @@ -124,9 +141,9 @@
       }
   
       /**
  -     * 
  -     * <b>Note:</b> The HttpClient constructors used to 
  -     * implicitly start a session.  That behavior has been 
  +     *
  +     * <b>Note:</b> The HttpClient constructors used to
  +     * implicitly start a session.  That behavior has been
        * removed.
        * @param user
        * @param password
  @@ -141,9 +158,9 @@
        * <b>Note:</b> The HttpClient constructor used to
        * implicitly start a session.  That behavior has been
        * removed.
  -     * 
  +     *
        * @param url
  -     * @deprecated This constructor was considered misleading in 
  +     * @deprecated This constructor was considered misleading in
        *             conjunction with the {@link #startSession()}
        */
       public HttpClient(URL url) {
  @@ -152,11 +169,11 @@
   
   
       /**
  -     * 
  +     *
        * @param url
        * @param user
        * @param password
  -     * @deprecated This constructor was considered misleading in 
  +     * @deprecated This constructor was considered misleading in
        *             conjunction with the {@link #startSession()}
        */
       public HttpClient(URL url, String user, String password) {
  @@ -168,10 +185,10 @@
            */
           setCredentials(new Credentials(user, password));
       }
  -    
  -    
   
   
  +
  +
       // ----------------------------------------------------- Instance Variables
   
   
  @@ -223,6 +240,10 @@
        */
       protected boolean http11 = false;
   
  +    /**
  +     * HTTPS flag.
  +     */
  +    protected boolean https = false;
   
       /**
        * Stream interceptors.
  @@ -394,7 +415,7 @@
                   responseHeaders = null;
                   sentRequestBody = false;
   
  -                // Send the request header except if the 
  +                // Send the request header except if the
                   byte[] query = sendRequestHeader(method);
   
                   if ((!http11) || (!method.needExpectation())) {
  @@ -405,7 +426,7 @@
                   if (connectionInterceptor != null) {
                       connectionInterceptor.sentRequest();
                   }
  -                
  +
                   boolean closeOutput = needToCloseOutput();
                   if (closeOutput) {
                       try {
  @@ -431,12 +452,12 @@
                   responseHeaders = parseHeaders(input);
   
                   while (method.getStatusCode() < 200) {
  -                    
  +
                       if (connectionInterceptor != null) {
                           connectionInterceptor.info
                               (method.getStatusCode(), responseHeaders);
                       }
  -                    
  +
                       if (method.getStatusCode() == HttpStatus.SC_CONTINUE) {
                           if (!sentRequestBody) {
                               if (connectionInterceptor != null) {
  @@ -446,21 +467,21 @@
                               sentRequestBody = true;
                           }
                       }
  -                    
  +
                       statusLine = readLine(input);
                       if (statusLine == null)
                           throw new IOException("Couldn't parse status line");
                       parseStatusLine(statusLine, method);
  -                    
  +
                       // Parse headers
                       responseHeaders = parseHeaders(input);
  -                    
  +
                   }
   
                   if (connectionInterceptor != null) {
                       connectionInterceptor.recievedResponse();
                   }
  -                
  +
                   // Retrieve the authenticate challenge, if any
                   // (needed in case of a digest challenge, for which the
                   // header is not constant)
  @@ -473,7 +494,7 @@
                           connectionInterceptor.requiredAuthentication();
                       }
                   }
  -                
  +
                   if ((method.getStatusCode()
                        == HttpStatus.SC_MOVED_TEMPORARILY)
                       || (method.getStatusCode()
  @@ -584,7 +605,7 @@
           method.processResponseHeaders(responseHeaders);
           method.setUsed();
           // Parse response
  -        ResponseInputStream responseInputStream = 
  +        ResponseInputStream responseInputStream =
               new ResponseInputStream(input, responseHeaders);
           responseInputStream.setInterceptor(streamInterceptor);
   
  @@ -601,8 +622,8 @@
   
       /**
        * Start a session.
  -     * 
  -     * @deprecated This method opens a connection to 
  +     *
  +     * @deprecated This method opens a connection to
        *             localhost:80.  It will be removed in a future release
        *             to make usage more clear.
        */
  @@ -611,6 +632,7 @@
           state = new State();
           this.sessionHost = "localhost";
           this.sessionPort = 80;
  +        this.https = false;
   
       }
   
  @@ -619,14 +641,19 @@
        * Start a session.
        */
       public void startSession(String host, int port) {
  +        startSession(host,port,false);
  +    }
   
  +    public void startSession(String host, int port, boolean https) {
           if (debug > 0)
               System.out.println("Start session : Host:" + host
  -                               + " Port:" + port);
  +                               + " Port:" + port
  +                               + " HTTPS:" + https);
   
           state = new State();
           this.sessionHost = host;
           this.sessionPort = port;
  +        this.https = https;
   
       }
   
  @@ -634,35 +661,50 @@
        * Start a session.
        */
       public void startSession(String host, int port, Credentials creds) {
  +        startSession(host,port,creds,false);
  +    }
   
  +    /**
  +     * Start a session.
  +     */
  +    public void startSession(String host, int port, Credentials creds, boolean 
https) {
           if (debug > 0)
               System.out.println("Start session : Host:" + host
  -                               + " Port:" + port);
  +                                + " Port:" + port
  +                                + " Credentials:" + creds
  +                                + " HTTPS:" + https);
           setCredentials(creds);
           state = new State();
           this.sessionHost = host;
           this.sessionPort = port;
  +        this.https = https;
   
       }
   
       /**
        * Start a session.  When starting a session, only the
  -     * hostname and port are considered.  The path must still
  -     * be set when constructing an HttpMethod (GetMethod, 
  +     * protocol, hostname and port are considered.  The path must still
  +     * be set when constructing an HttpMethod (GetMethod,
        * PutMethod, etc.)
  -     * 
  +     *
        * @param url    URL object containing the target hostname and port
        */
       public void startSession(URL url) {
  -      startSession(url.getHost(), url.getPort() == -1 ? 80 : url.getPort());
  +      if("https".equalsIgnoreCase(url.getProtocol())) {
  +        startSession(url.getHost(), url.getPort() == -1 ? 443 : url.getPort(),true);
  +      } else if("http".equalsIgnoreCase(url.getProtocol())) {
  +        startSession(url.getHost(), url.getPort() == -1 ? 80 : url.getPort(),false);
  +      } else {
  +          throw new IllegalArgumentException("Protocol " + url.getProtocol() + " 
not supported in URL " + url);
  +      }
       }
   
       /**
        * Start a session.  When starting a session, only the
        * hostname and port are considered.  The path must still
  -     * be set when constructing an HttpMethod (GetMethod, 
  +     * be set when constructing an HttpMethod (GetMethod,
        * PutMethod, etc.)
  -     * 
  +     *
        * @param url    URL object containing the target hostname and port
        */
       public void startSession(URL url, Credentials creds) {
  @@ -684,6 +726,7 @@
           state = null;
           this.sessionHost = "";
           this.sessionPort = -1;
  +        this.https = false;
   
       }
   
  @@ -698,12 +741,15 @@
                   if (debug > 0)
                       System.out.println("Reopen connection : Host:"
                                          + sessionHost + " Port:" + sessionPort);
  -                socket = new Socket(this.sessionHost, this.sessionPort);
  +                if(https) {
  +                    socket = 
SSLSocketFactory.getDefault().createSocket(this.sessionHost, this.sessionPort);
  +                } else {
  +                    socket = new Socket(this.sessionHost, this.sessionPort);
  +                }
               }
               input = socket.getInputStream();
               output = socket.getOutputStream();
           } catch (IOException e) {
  -
               if (connectionInterceptor != null) {
                   connectionInterceptor.error(-1, e);
               }
  @@ -714,7 +760,7 @@
                   socket.close();
                   socket = null;
               }
  -            
  +
               if (debug > 0)
                   System.out.println("Reopen connection after IOException: Host:"
                       + sessionHost + " Port:" + sessionPort);
  @@ -866,7 +912,7 @@
   
           // Writing request body
   
  -        RequestOutputStream requestOutputStream = 
  +        RequestOutputStream requestOutputStream =
               new RequestOutputStream(output);
           requestOutputStream.setInterceptor(streamInterceptor);
   
  @@ -938,7 +984,7 @@
           if (statusLine == null)
               throw new HttpException
                   ("Error in parsing the response: " + statusLine);
  -        
  +
           int at = statusLine.indexOf(" ");
           if (at < 0)
               throw new HttpException
  @@ -1058,7 +1104,7 @@
               && (connectionHeader.getValue().equals("close")))
               return true;
   
  -        if ((method.getStatusCode() < 200) 
  +        if ((method.getStatusCode() < 200)
               || (method.getStatusCode() == HttpStatus.SC_NO_CONTENT)
               || (method.getStatusCode() == HttpStatus.SC_NOT_MODIFIED))
               return false;
  
  
  
  1.3       +5 -4      
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAll.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestAll.java      2001/05/01 07:39:34     1.2
  +++ TestAll.java      2001/05/17 23:58:51     1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAll.java,v
 1.2 2001/05/01 07:39:34 remm Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/05/01 07:39:34 $
  + * $Header: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAll.java,v
 1.3 2001/05/17 23:58:51 rwaldhoff Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/05/17 23:58:51 $
    *
    * ====================================================================
    *
  @@ -65,7 +65,7 @@
   
   /**
    * @author Remy Maucherat
  - * @version $Id: TestAll.java,v 1.2 2001/05/01 07:39:34 remm Exp $
  + * @version $Id: TestAll.java,v 1.3 2001/05/17 23:58:51 rwaldhoff Exp $
    */
   public class TestAll extends TestCase {
   
  @@ -77,6 +77,7 @@
           TestSuite suite = new TestSuite();
           suite.addTest(TestMethods.suite());
           suite.addTest(TestCookie.suite());
  +        suite.addTest(TestHttps.suite());
           return suite;
       }
   
  
  
  
  1.1                  
jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttps.java
  
  Index: TestHttps.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttps.java,v
 1.1 2001/05/17 23:58:51 rwaldhoff Exp $
   * $Revision: 1.1 $
   * $Date: 2001/05/17 23:58:51 $
   * ====================================================================
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  
  package org.apache.commons.httpclient;
  
  import java.io.IOException;
  import java.net.URL;
  import junit.framework.*;
  import org.apache.commons.httpclient.methods.*;
  
  /**
   * Simple tests for HTTPS support in HttpClient.
   *
   * To run this test you'll need:
   *  + a JSSE implementation installed (see README.txt)
   *  + the java.protocol.handler.pkgs system property set
   *    for your provider.  e.g.:
   *     -Djava.protocol.handler.pkgs=com.sun.net.ssl.internal.www.protocol
   *    (see build.xml)
   *
   * @author Rodney Waldhoff
   * @version $Id: TestHttps.java,v 1.1 2001/05/17 23:58:51 rwaldhoff Exp $
   */
  public class TestHttps extends TestCase {
      // ---------------------------------------------------------------- Members
      private URL _urlWithPort = null;
      private URL _urlWithoutPort = null;
  
      // ------------------------------------------------------------ Constructor
      public TestHttps(String testName) {
          super(testName);
      }
  
      // ------------------------------------------------------------------- Main
      public static void main(String args[]) {
          String[] testCaseName = { TestHttps.class.getName() };
          junit.textui.TestRunner.main(testCaseName);
      }
  
      // ------------------------------------------------------- TestCase Methods
      public static Test suite() {
          return new TestSuite(TestHttps.class);
      }
  
      public void setUp() throws Exception {
          _urlWithPort = new URL("https://www.verisign.com:443/";);
          _urlWithoutPort = new URL("https://www.verisign.com/";);
      }
  
      public void testHttpsGet() {
          HttpClient client = new HttpClient();
          client.startSession(_urlWithPort);
          GetMethod method = new GetMethod("/");
          method.setUseDisk(false);
          try {
              client.executeMethod(method);
          } catch (Throwable t) {
              t.printStackTrace();
              fail("Exception thrown during HTTPS GET: " + t.toString());
          }
  
          try {
              String data = method.getDataAsString();
              // This enumeration musn't be empty
              assert("No data returned.", (data.length() > 0));
          } catch (Throwable t) {
              t.printStackTrace();
              fail("Exception thrown while retrieving data : " + t.toString());
          }
      }
  
      public void testHttpsGetNoPort() {
          HttpClient client = new HttpClient();
          client.startSession(_urlWithoutPort);
          GetMethod method = new GetMethod("/");
          method.setUseDisk(false);
          try {
              client.executeMethod(method);
          } catch (Throwable t) {
              t.printStackTrace();
              fail("Exception thrown during HTTPS GET: " + t.toString());
          }
  
          try {
              String data = method.getDataAsString();
              // This enumeration musn't be empty
              assert("No data returned.", (data.length() > 0));
          } catch (Throwable t) {
              t.printStackTrace();
              fail("Exception thrown while retrieving data : " + t.toString());
          }
      }
  }
  
  
  

Reply via email to