dion        02/02/17 03:46:15

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpClient.java
  Log:
  Added patches from Sean C Sullivan which included javadoc and parameter/
  state checking in execute method.
  Fixed some code formatting as well
  
  Revision  Changes    Path
  1.44      +57 -9     
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.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- HttpClient.java   12 Feb 2002 01:50:54 -0000      1.43
  +++ HttpClient.java   17 Feb 2002 11:46:15 -0000      1.44
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
 1.43 2002/02/12 01:50:54 dion Exp $
  - * $Revision: 1.43 $
  - * $Date: 2002/02/12 01:50:54 $
  + * $Header: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
 1.44 2002/02/17 11:46:15 dion Exp $
  + * $Revision: 1.44 $
  + * $Date: 2002/02/17 11:46:15 $
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
  @@ -79,7 +79,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a>
    * @author Rodney Waldhoff
    * @author Sean C. Sullivan
  - * @version $Revision: 1.43 $ $Date: 2002/02/12 01:50:54 $
  + * @version $Revision: 1.44 $ $Date: 2002/02/17 11:46:15 $
    */
   public class HttpClient {
   
  @@ -113,9 +113,12 @@
   
       /**
        * Get my {@link HttpState state}.
  +     *
  +     * @see #setState(HttpState)
  +     *
        */
       public HttpState getState() {
  -        if(null == state) {
  +        if (null == state) {
               state = new HttpState();
           }
           return state;
  @@ -123,6 +126,9 @@
   
       /**
        * Set my {@link HttpState state}.
  +     *
  +     * @see #getState()
  +     *
        */
       public void setState(HttpState state) {
           this.state = state;
  @@ -135,6 +141,9 @@
        * <i>host</i> and <i>port</i>.
        * @param host the host to connect to
        * @param port the port to connect to
  +     *
  +     * @see #endSession()
  +     *
        */
       public void startSession(String host, int port) {
           startSession(host,port,false);
  @@ -146,6 +155,9 @@
        * @param host the host to connect to
        * @param port the port to connect to
        * @param https when <code>true</code>, create an HTTPS session
  +     *
  +     * @see #endSession()
  +     *
        */
       public void startSession(String host, int port, boolean https) {
           if (log.isDebugEnabled()) {
  @@ -162,6 +174,9 @@
        * @param host the host to connect to
        * @param port the port to connect to
        * @param creds the default credentials to use
  +     *
  +     * @see #endSession()
  +     *
        */
       public void startSession(String host, int port, Credentials creds) {
           startSession(host,port,creds,false);
  @@ -176,6 +191,9 @@
        * @param port the port to connect to
        * @param creds the default credentials to use
        * @param https when <code>true</code>, create an HTTPS session
  +     *
  +     * @see #endSession()
  +     *
        */
       public void startSession(String host, int port, Credentials creds,
                                boolean https) {
  @@ -199,12 +217,15 @@
        * </p>
        * @param url the {@link URL URL} from which the protocol, host,
        *            and port of the session are determined
  +     *
  +     * @see #endSession()
  +     *
        */
       public void startSession(URL url) {
  -      if("https".equalsIgnoreCase(url.getProtocol())) {
  +      if ("https".equalsIgnoreCase(url.getProtocol())) {
           startSession(url.getHost(), url.getPort() == -1 ? 443
                        : url.getPort(),true);
  -      } else if("http".equalsIgnoreCase(url.getProtocol())) {
  +      } else if ("http".equalsIgnoreCase(url.getProtocol())) {
           startSession(url.getHost(), url.getPort() == -1 ? 80
                        : url.getPort(),false);
         } else {
  @@ -224,6 +245,9 @@
        * @param creds the default credentials to use
        * @param url the {@link URL URL} from which the protocol, host,
        *            and port of the session are determined
  +     *
  +     * @see #endSession()
  +     *
        */
       public void startSession(URL url, Credentials creds) {
           getState().setCredentials(null,creds);
  @@ -239,6 +263,9 @@
        * @param port the port to connect to
        * @param proxyhost the proxy host to connect via
        * @param proxyport the proxy port to connect via
  +     *
  +     * @see #endSession()
  +     *
        */
       public void startSession(String host, int port,
                                String proxyhost, int proxyport) {
  @@ -254,9 +281,20 @@
        *
        * @throws IOException if an I/O error occurs
        * @throws HttpException if a protocol exception occurs
  +     * @throws IllegalStateException if the session has not been started
        */
       public synchronized int executeMethod(HttpMethod method) throws IOException, 
HttpException  {
  -        if(!connection.isOpen()) {
  +
  +        if (null == method) {
  +            throw new NullPointerException("HttpMethod parameter");
  +        }
  +
  +        if (null == connection) {
  +            throw new IllegalStateException(
  +                "The startSession method must be called before executeMethod");
  +             }
  +
  +        if (!connection.isOpen()) {
               connection.open();
           }
           return method.execute(getState(),connection);
  @@ -265,12 +303,22 @@
       /**
        * End the current session, closing my the associated
        * {@link HttpConnection connection} if any.
  +     *
  +     *
  +     * @see #startSession(String, int)
  +     * @see #startSession(String, int, boolean)
  +     * @see #startSession(String, int, Credentials)
  +     * @see #startSession(String, int, Credentials, boolean)
  +     * @see #startSession(java.net.URL)
  +     * @see #startSession(java.net.URL, Credentials)
  +     * @see #startSession(String, int, String, int)
  +     *
        */
       public void endSession() throws IOException {
           if (log.isDebugEnabled()) {
                log.debug("HttpClient.endSession()");
           }
  -        if(null != connection) {
  +        if (null != connection) {
               connection.close();
               connection = null;
           }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to