commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsde...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util HttpURLConnection.java
Date Mon, 02 Sep 2002 15:13:40 GMT
jsdever     2002/09/02 08:13:40

  Modified:    httpclient/src/java/org/apache/commons/httpclient/util
                        HttpURLConnection.java
  Log:
  Minor fixes to getHeaderFiledKey and getHeaderField.
  
  Contributed by: Vincent Massol
  
  Revision  Changes    Path
  1.3       +64 -40    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/HttpURLConnection.java
  
  Index: HttpURLConnection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/HttpURLConnection.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HttpURLConnection.java	29 Jul 2002 04:54:47 -0000	1.2
  +++ HttpURLConnection.java	2 Sep 2002 15:13:40 -0000	1.3
  @@ -155,7 +155,7 @@
        * @see java.net.HttpURLConnection#getErrorStream()
        */
       public InputStream getErrorStream() {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.getErrorStream()");
           throw new RuntimeException("Not implemented yet");
       }
   
  @@ -164,7 +164,7 @@
        * @see java.net.HttpURLConnection#disconnect()
        */
       public void disconnect() {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.disconnect()");
           throw new RuntimeException("Not implemented yet");
       }
   
  @@ -173,7 +173,7 @@
        * @see java.net.HttpURLConnection#connect()
        */
       public void connect() throws IOException {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.connect()");
           throw new RuntimeException("This class can only be used with already"
               + "retrieved data");
       }
  @@ -183,7 +183,7 @@
        * @see java.net.HttpURLConnection#usingProxy()
        */
       public boolean usingProxy() {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.usingProxy()");
           throw new RuntimeException("Not implemented yet");
       }
   
  @@ -192,7 +192,7 @@
        * @see org.apache.commons.httpclient.HttpMethod#getName()
        */
       public String getRequestMethod() {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.getRequestMethod()");
           return this.method.getName();
       }
   
  @@ -201,7 +201,7 @@
        * @see org.apache.commons.httpclient.HttpMethod#getStatusCode()
        */
       public int getResponseCode() throws IOException {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.getResponseCode()");
           return this.method.getStatusCode();
       }
   
  @@ -210,7 +210,7 @@
        * @see org.apache.commons.httpclient.HttpMethod#getStatusText()
        */
       public String getResponseMessage() throws IOException {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.getResponseMessage()");
           return this.method.getStatusText();
       }
   
  @@ -219,7 +219,7 @@
        * @see org.apache.commons.httpclient.HttpMethod#getResponseHeaders()
        */
       public String getHeaderField(String name) {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.getHeaderField(String)");
           // Note: Return the last matching header in the Header[] array, as in
           // the JDK implementation.
           Header[] headers = this.method.getResponseHeaders();
  @@ -237,16 +237,25 @@
        * @see org.apache.commons.httpclient.HttpMethod#getResponseHeaders()
        */
       public String getHeaderFieldKey(int keyPosition) {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.getHeaderFieldKey(int)");
  +
  +        // Note: HttpClient does not consider the returned Status Line as
  +        // a response header. However, getHeaderFieldKey(0) is supposed to 
  +        // return null. Hence the special case below ...
  +        
  +        if (theKeyPosition == 0) {
  +            return null;
  +        }
  +
           // Note: I hope the header fields are kept in the correct order when
           // calling getRequestHeaders.
   
           Header[] headers = this.method.getResponseHeaders();
  -        if (keyPosition < 0 || keyPosition >= headers.length) {
  +        if (theKeyPosition < 0 || theKeyPosition >= headers.length) {
               return null;
           }
   
  -        return headers[keyPosition].getName();
  +        return headers[theKeyPosition - 1].getName();
       }
   
       /**
  @@ -254,23 +263,38 @@
        * @see org.apache.commons.httpclient.HttpMethod#getResponseHeaders()
        */
       public String getHeaderField(int position) {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.getHeaderField(int)");
  +
  +        // Note: HttpClient does not consider the returned Status Line as
  +        // a response header. However, getHeaderField(0) is supposed to 
  +        // return the status line. Hence the special case below ...
  +        
  +        if (thePosition == 0) {
  +            if (((HttpMethodBase) this.method).isHttp11()) {
  +                return "HTTP/1.1 " + this.method.getStatusCode() 
  +                    + " " + this.method.getStatusText();
  +            } else {
  +                return "HTTP/1.0 " + this.method.getStatusCode() 
  +                    + " " + this.method.getStatusText();
  +            }
  +        }
  +
           // Note: I hope the header fields are kept in the correct order when
           // calling getRequestHeaders.
   
           Header[] headers = this.method.getResponseHeaders();
  -        if (position < 0 || position >= headers.length) {
  +        if (thePosition < 0 || thePosition >= headers.length) {
               return null;
           }
   
  -        return headers[position].getValue();
  +        return headers[thePosition - 1].getValue();
       }
   
       /**
        * @see java.net.HttpURLConnection#getURL()
        */
       public URL getURL() {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.getURL()");
           return this.url;
       }
   
  @@ -292,7 +316,7 @@
        * @see java.net.HttpURLConnection#setInstanceFollowRedirects(boolean)
        */
       public void setInstanceFollowRedirects(boolean isFollowingRedirects) {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.setInstanceFollowRedirects(boolean)");
           throw new RuntimeException("This class can only be used with already"
               + "retrieved data");
       }
  @@ -302,7 +326,7 @@
        * @see java.net.HttpURLConnection#getInstanceFollowRedirects()
        */
       public boolean getInstanceFollowRedirects() {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.getInstanceFollowRedirects()");
           throw new RuntimeException("Not implemented yet");
       }
   
  @@ -311,7 +335,7 @@
        * @see java.net.HttpURLConnection#setRequestMethod(String)
        */
       public void setRequestMethod(String method) throws ProtocolException {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.setRequestMethod(String)");
           throw new RuntimeException("This class can only be used with already"
               + "retrieved data");
       }
  @@ -321,7 +345,7 @@
        * @see java.net.HttpURLConnection#getPermission()
        */
       public Permission getPermission() throws IOException {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.getPermission()");
           throw new RuntimeException("Not implemented yet");
       }
   
  @@ -330,7 +354,7 @@
        * @see java.net.HttpURLConnection#getContent()
        */
       public Object getContent() throws IOException {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.getContent()");
           throw new RuntimeException("Not implemented yet");
       }
   
  @@ -339,7 +363,7 @@
        * @see java.net.HttpURLConnection#getContent(Class[])
        */
       public Object getContent(Class[] classes) throws IOException {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.getContent(Class[])");
           throw new RuntimeException("Not implemented yet");
       }
   
  @@ -347,7 +371,7 @@
        * @see java.net.HttpURLConnection#getOutputStream()
        */
       public OutputStream getOutputStream() throws IOException {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.getOutputStream()");
           throw new RuntimeException("This class can only be used with already"
               + "retrieved data");
       }
  @@ -357,7 +381,7 @@
        * @see java.net.HttpURLConnection#setDoInput(boolean)
        */
       public void setDoInput(boolean isInput) {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.setDoInput()");
           throw new RuntimeException("This class can only be used with already"
               + "retrieved data");
       }
  @@ -367,7 +391,7 @@
        * @see java.net.HttpURLConnection#getDoInput()
        */
       public boolean getDoInput() {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.getDoInput()");
           throw new RuntimeException("Not implemented yet");
       }
   
  @@ -376,7 +400,7 @@
        * @see java.net.HttpURLConnection#setDoOutput(boolean)
        */
       public void setDoOutput(boolean isOutput) {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.setDoOutput()");
           throw new RuntimeException("This class can only be used with already"
               + "retrieved data");
       }
  @@ -386,7 +410,7 @@
        * @see java.net.HttpURLConnection#getDoOutput()
        */
       public boolean getDoOutput() {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.getDoOutput()");
           throw new RuntimeException("Not implemented yet");
       }
   
  @@ -395,7 +419,7 @@
        * @see java.net.HttpURLConnection#setAllowUserInteraction(boolean)
        */
       public void setAllowUserInteraction(boolean isAllowInteraction) {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.setAllowUserInteraction(boolean)");
           throw new RuntimeException("This class can only be used with already"
               + "retrieved data");
       }
  @@ -405,7 +429,7 @@
        * @see java.net.HttpURLConnection#getAllowUserInteraction()
        */
       public boolean getAllowUserInteraction() {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.getAllowUserInteraction()");
           throw new RuntimeException("Not implemented yet");
       }
   
  @@ -414,7 +438,7 @@
        * @see java.net.HttpURLConnection#setUseCaches(boolean)
        */
       public void setUseCaches(boolean isUsingCaches) {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.setUseCaches(boolean)");
           throw new RuntimeException("This class can only be used with already"
               + "retrieved data");
       }
  @@ -424,7 +448,7 @@
        * @see java.net.HttpURLConnection#getUseCaches()
        */
       public boolean getUseCaches() {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.getUseCaches()");
           throw new RuntimeException("Not implemented yet");
       }
   
  @@ -433,7 +457,7 @@
        * @see java.net.HttpURLConnection#setIfModifiedSince(long)
        */
       public void setIfModifiedSince(long modificationDate) {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.setIfModifiedSince(long)");
           throw new RuntimeException("This class can only be used with already"
               + "retrieved data");
       }
  @@ -443,7 +467,7 @@
        * @see java.net.HttpURLConnection#getIfModifiedSince()
        */
       public long getIfModifiedSince() {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.getIfmodifiedSince()");
           throw new RuntimeException("Not implemented yet");
       }
   
  @@ -452,7 +476,7 @@
        * @see java.net.HttpURLConnection#getDefaultUseCaches()
        */
       public boolean getDefaultUseCaches() {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.getDefaultUseCaches()");
           throw new RuntimeException("Not implemented yet");
       }
   
  @@ -461,7 +485,7 @@
        * @see java.net.HttpURLConnection#setDefaultUseCaches(boolean)
        */
       public void setDefaultUseCaches(boolean isUsingCaches) {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.setDefaultUseCaches(boolean)");
           throw new RuntimeException("This class can only be used with already"
               + "retrieved data");
       }
  @@ -471,7 +495,7 @@
        * @see java.net.HttpURLConnection#setRequestProperty(String,String)
        */
       public void setRequestProperty(String key, String value) {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.setRequestProperty()");
           throw new RuntimeException("This class can only be used with already"
               + "retrieved data");
       }
  @@ -481,7 +505,7 @@
        * @see java.net.HttpURLConnection#getRequestProperty(String)
        */
       public String getRequestProperty(String key) {
  -        log.trace("enter HttpURLConnection.getInputStream()");
  +        log.trace("enter HttpURLConnection.getRequestProperty()");
           throw new RuntimeException("Not implemented yet");
       }
   
  
  
  

--
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