commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: jakarta-commons/latka/src/java/org/apache/commons/latka/http RequestImpl.java
Date Thu, 11 Apr 2002 14:40:35 GMT
dion        02/04/11 07:40:35

  Modified:    latka/src/java/org/apache/commons/latka/http
                        RequestImpl.java
  Log:
  Fixed javadocs, cleaned up code
  
  Revision  Changes    Path
  1.19      +78 -56    jakarta-commons/latka/src/java/org/apache/commons/latka/http/RequestImpl.java
  
  Index: RequestImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/http/RequestImpl.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- RequestImpl.java	11 Apr 2002 13:40:47 -0000	1.18
  +++ RequestImpl.java	11 Apr 2002 14:40:34 -0000	1.19
  @@ -63,7 +63,6 @@
   // java imports
   import java.net.URL;
   import java.io.IOException;
  -import java.util.Date;
   import java.util.List;
   // latka imports
   import org.apache.commons.httpclient.UsernamePasswordCredentials;
  @@ -84,7 +83,7 @@
    * @author <a href="mailto:dsale@us.britannica.com">Doug Sale</a>
    * @author <a href="mailto:mdelagra@us.britannica.com">Morgan Delagrange</a>
    * @author dIon Gillard
  - * @version $Id: RequestImpl.java,v 1.18 2002/04/11 13:40:47 dion Exp $
  + * @version $Id: RequestImpl.java,v 1.19 2002/04/11 14:40:34 dion Exp $
    * @see Request
    */
   public class RequestImpl implements Request {
  @@ -134,7 +133,7 @@
        * @param state shared information across requests
        * @param session state shared across servers and requests
        */
  -    protected RequestImpl(URL url,int httpMethod, HttpState state,
  +    protected RequestImpl(URL url, int httpMethod, HttpState state,
           SessionImpl session) {
           this(null, url, httpMethod, state, session, true);
       }
  @@ -190,7 +189,8 @@
        * (get, post, etc.) being used by this request.  See
        * the Request interface for available constants.
        *
  -     * @return the underlying HttpMethod object representing the request/respose pair.
  +     * @return the underlying HttpMethod object representing the request/
  +     *      response pair.
        */
       protected HttpMethod getHttpMethod() {
           return _httpMethod;
  @@ -207,7 +207,7 @@
       
       /**
        * Defined in the implemented interface
  -     * @param new value for the headers property
  +     * @param requestHeaders new value for the headers property
        * @see Request#setHeaders(RequestHeaders)
        */
       public void setHeaders(RequestHeaders requestHeaders) {
  @@ -245,20 +245,25 @@
           _session._state.setCredentials(null, creds);
       }
       
  -    // defined in the interface
  +    /**
  +     * Execute the request - perform the http interaction 
  +     * @return a {@link Response} detailing the html etc
  +     * @throws IOException when there are problems reading and writing
  +     * @see Request#execute()
  +     */
       public Response execute() throws IOException {
           
           // set the request headers in HTTPClient
           List headers = _requestHeaders.getHeaders();
           for (int i = 0; i < headers.size(); ++i) {
               String[] header = (String[]) headers.get(i);
  -            _httpMethod.addRequestHeader(header[0],header[1]);
  +            _httpMethod.addRequestHeader(header[0], header[1]);
           }
           
           List parameters = _parameters.getParameters();
           for (int i = 0; i < parameters.size(); ++i) {
               String[] parameter = (String[]) parameters.get(i);
  -            addHttpClientParameter(parameter[0],parameter[1]);
  +            addHttpClientParameter(parameter[0], parameter[1]);
           }
           
           // for timing
  @@ -305,68 +310,77 @@
           _requestTiming = System.currentTimeMillis() - startDate;
           
           if (_log.isInfoEnabled()) {
  -            _log.info("response obtained (response logging disabled because "+
  +            _log.info("response obtained (response logging disabled because " +
                   "some responses are binary)");
           }
           
           return response;
       }
       
  -    // defined in the interface
  +    /**
  +     * Get the URL used for the request
  +     * @return the {@link URL} of the request
  +     * @see Request#getURL
  +     */
       public URL getURL() {
           return _targetURL;
       }
       
  -    // defined in the interface
  +    /**
  +     * Get the label used for the request
  +     * @return the label used to create the request
  +     * @see Request#getLabel
  +     */
       public String getLabel() {
           return _label;
       }
       
  -    // defined in the interface
  +    /**
  +     * Add a parameter (name and value) to the request
  +     * @param name the name of the parameter to be added
  +     * @param value the value of the parameter to be added
  +     * @see Request#addParameter(String,String)
  +     */
       public void addParameter(String name, String value) {
  -        _parameters.addParameter(name,value);
  +        _parameters.addParameter(name, value);
       }
       
       /**
        * Associate a parameter with this request.
        *
  -     * @param name  the lvalue of the parameter
  -     * @param name  the rvalue of the parameter
  -     *
  -     * @throws java.lang.IllegalArgumentException  if a parameter is null
  +     * @param name  the lvalue of the parameter - must not be null
  +     * @param value  the rvalue of the parameter - must not be null
        */
       protected void addHttpClientParameter(String name, String value) {
  +        if (name == null) {
  +            throw new NullPointerException("name parameter is null");
  +        }
           
  -        _log.info("adding parameter, name:");
  -        _log.info(name);
  -        _log.info("value:");
  -        _log.info(value);
  +        if (value == null) {
  +            throw new NullPointerException("value parameter is null");
  +        }
  +        _log.info("adding parameter, name: " + name + ", value: " + value);
           
  -        try {
  -            if (_httpMethod instanceof PostMethod) {
  -                // addParameter adds to POST Entity, not URL
  -                ((PostMethod) _httpMethod).addParameter(name, value);
  +        if (_httpMethod instanceof PostMethod) {
  +            // addParameter adds to POST Entity, not URL
  +            ((PostMethod) _httpMethod).addParameter(name, value);
  +        } else {
  +            StringBuffer query = new StringBuffer();
  +
  +            // setParameter adds to URL as query string
  +            if (_query == null || _query.equals("")) {
  +                query.append(name);
  +                query.append("=");
  +                query.append(value);
               } else {
  -                StringBuffer query = new StringBuffer();
  -                
  -                // setParameter adds to URL as query string
  -                if (_query == null || _query.equals("")) {
  -                    query.append(name);
  -                    query.append("=");
  -                    query.append(value);
  -                }
  -                else {
  -                    query.append(_query);
  -                    query.append("&");
  -                    query.append(name);
  -                    query.append("=");
  -                    query.append(value);
  -                }
  -                _query = query.toString();
  -                ((HttpMethod) _httpMethod).setQueryString(_query);
  +                query.append(_query);
  +                query.append("&");
  +                query.append(name);
  +                query.append("=");
  +                query.append(value);
               }
  -        } catch (NullPointerException nullX) {
  -            throw new IllegalArgumentException(nullX.toString());
  +            _query = query.toString();
  +            ((HttpMethod) _httpMethod).setQueryString(_query);
           }
       }
       
  @@ -377,7 +391,7 @@
        * @param headerValue value of that header
        */
       public void addHeader(String headerName, String headerValue) {
  -        _requestHeaders.addHeader(headerName,headerValue);
  +        _requestHeaders.addHeader(headerName, headerValue);
       }
       
       /**
  @@ -390,19 +404,17 @@
       }
       
       /**
  -     * @return the amount of time it took to execute this request (in milliseconds),
  +     * @return the time it took to execute this request in milliseconds
        * or -1 if the request has not yet been executed
        */
       public int getRequestTiming() {
  -        return(int) _requestTiming;
  +        return (int) _requestTiming;
       }
       
       /**
        * opens an HTTP connection.  This method is called
        * before executing the method.
        *
  -     * @param request Request containing the HttpClient object that will
  -     *                open the connection
        * @exception IOException
        *                   if the server could not be contacted
        */
  @@ -419,11 +431,9 @@
           if (port == -1) {
               if (protocol.equals("http")) {
                   port = HTTP_PORT;
  -            }
  -            else if (protocol.equals("https")) {
  +            } else if (protocol.equals("https")) {
                   port = HTTPS_PORT;
  -            }
  -            else {
  +            } else {
                   throw new IllegalArgumentException("Unsupported Protocol");
               }
           }
  @@ -439,20 +449,32 @@
           
       }
       
  +    /**
  +     * Closes the http connection associated with the request
  +     * @throws IOException if there are problems closing the connection
  +     */
       protected void closeConnection() throws IOException {
           _log.debug("closing connection");
           _httpClient.endSession();
           _log.debug("connection closed");
       }
       
  -    // defined in the interface
  +    /**
  +     * Defined in the interface
  +     * @return whether the request will honour http redirect status codes
  +     * @see Request#followRedirects()
  +     */
       public boolean followRedirects() {
           return _followRedirects;
       }
       
  -    // defined in interface
  +    /**
  +     * Defined in the interface
  +     * @return the http method being used for the request, as defined in the
  +     *      interface
  +     * @see Request#getMethod
  +     */
       public int getMethod() {
           return _method;
       }
  -    
   }
  
  
  

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


Mime
View raw message