rwaldhoff 01/08/16 08:04:50 Modified: httpclient/src/java/org/apache/commons/httpclient/methods Tag: rlwrefactoring GetMethod.java PutMethod.java httpclient/src/java/org/apache/commons/httpclient Tag: rlwrefactoring HttpMethod.java HttpMethodBase.java Log: removing clearQueryString method as redundant (use setQueryString(null) instead) some javadoc fixes Revision Changes Path No revision No revision 1.2.2.7 +35 -26 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/GetMethod.java Index: GetMethod.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/GetMethod.java,v retrieving revision 1.2.2.6 retrieving revision 1.2.2.7 diff -u -r1.2.2.6 -r1.2.2.7 --- GetMethod.java 2001/08/15 23:19:34 1.2.2.6 +++ GetMethod.java 2001/08/16 15:04:49 1.2.2.7 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/GetMethod.java,v 1.2.2.6 2001/08/15 23:19:34 rwaldhoff Exp $ - * $Revision: 1.2.2.6 $ - * $Date: 2001/08/15 23:19:34 $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/GetMethod.java,v 1.2.2.7 2001/08/16 15:04:49 rwaldhoff Exp $ + * $Revision: 1.2.2.7 $ + * $Date: 2001/08/16 15:04:49 $ * * ==================================================================== * @@ -314,15 +314,14 @@ setFollowRedirects(true); } + /** + * Return my response body, if any, + * as a byte array. + * Otherwise return <tt>null</tt>. + */ public byte[] getResponseBody() { - // should flip this around so AsString uses bytes - return getResponseBodyAsString().getBytes(); - } - - public String getResponseBodyAsString() { - // should flip this around so AsString uses bytes checkUsed(); - if (useDisk) { + if(useDisk) { try { InputStream is = new FileInputStream(fileData); byte[] buffer = new byte[4096]; @@ -335,37 +334,47 @@ os.write(buffer, 0, nb); } is.close(); - return os.toString(); + return os.toByteArray(); } catch(IOException e) { - log.error("Exception in GetMethod.getResponseBodyAsString() while retrieving data from file \"" + fileData + "\".",e); + log.error("Exception in GetMethod.getResponseBody() while retrieving data from file \"" + fileData + "\".",e); return null; } } else { - if (memoryData != null) { - return new String(memoryData); - } else { - return ""; - } + return memoryData; + } + } + + /** + * Return my response body, if any, + * as a {@link String}. + * Otherwise return <tt>null</tt>. + */ + public String getResponseBodyAsString() { + byte[] data = getResponseBody(); + if(null == data) { + return null; + } else { + return new String(data); } } /** - * Get read data. + * Return my response body, if any, + * as an {@link InputStream}. + * Otherwise return <tt>null</tt>. */ - public InputStream getResponseBodyAsStream() - throws IOException { - + public InputStream getResponseBodyAsStream() throws IOException { checkUsed(); - if (useDisk) { return new FileInputStream(fileData); } else { - if (memoryData == null) - throw new IOException("Data not found"); - return new ByteArrayInputStream(memoryData); + if(null == memoryData) { + return null; + } else { + return new ByteArrayInputStream(memoryData); + } } - } 1.3.2.8 +6 -6 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java Index: PutMethod.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java,v retrieving revision 1.3.2.7 retrieving revision 1.3.2.8 diff -u -r1.3.2.7 -r1.3.2.8 --- PutMethod.java 2001/08/15 23:19:34 1.3.2.7 +++ PutMethod.java 2001/08/16 15:04:49 1.3.2.8 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java,v 1.3.2.7 2001/08/15 23:19:34 rwaldhoff Exp $ - * $Revision: 1.3.2.7 $ - * $Date: 2001/08/15 23:19:34 $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java,v 1.3.2.8 2001/08/16 15:04:49 rwaldhoff Exp $ + * $Revision: 1.3.2.8 $ + * $Date: 2001/08/16 15:04:49 $ * * Copyright (C) The Apache Software Foundation. All rights reserved. * @@ -63,19 +63,19 @@ /** - * Send byte buffer. + * Request body content to be sent. */ private byte[] data = null; /** - * Send file contents. + * Request body content to be sent. */ private File file = null; /** - * Set content from URL. + * Request body content to be sent. */ private URL url = null; No revision No revision 1.5.2.8 +28 -12 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethod.java Index: HttpMethod.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethod.java,v retrieving revision 1.5.2.7 retrieving revision 1.5.2.8 diff -u -r1.5.2.7 -r1.5.2.8 --- HttpMethod.java 2001/08/15 23:19:34 1.5.2.7 +++ HttpMethod.java 2001/08/16 15:04:49 1.5.2.8 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethod.java,v 1.5.2.7 2001/08/15 23:19:34 rwaldhoff Exp $ - * $Revision: 1.5.2.7 $ - * $Date: 2001/08/15 23:19:34 $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethod.java,v 1.5.2.8 2001/08/16 15:04:49 rwaldhoff Exp $ + * $Revision: 1.5.2.8 $ + * $Date: 2001/08/16 15:04:49 $ * ==================================================================== * Copyright (C) The Apache Software Foundation. All rights reserved. * @@ -21,7 +21,7 @@ /** * A request to be applied to an {@link HttpConnection}, - * and a container for the associate response. + * and a container for the associated response. * * @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a> * @author Rod Waldhoff @@ -94,6 +94,7 @@ /** * Whether or not I should automatically follow * HTTP redirects (status code 302, etc.) + * @return <tt>true</tt> if I will automatically follow HTTP redirects */ public boolean followRedirects(); @@ -105,32 +106,32 @@ /** * Set my query string. + * @param queryString the query string */ public void setQueryString(String queryString); /** * Set my query string. + * @param params an array of {@link NameValuePair}s + * to add as query string parameterss */ public void setQueryString(NameValuePair[] params); /** * Set my query string. - * @param params A {@link Collection} of {@link NameValuePair}s + * @param params a {@link Collection} of {@link NameValuePair}s + * to add as query string parameterss */ public void setQueryString(Collection params); /** - * Clear query string. - */ - public void clearQueryString(); - - /** * Get my query string. + * @return my query string */ public String getQueryString(); /** - * Return an iterator over my headers. + * Return an iterator over my request headers. */ public Iterator getRequestHeaders(); @@ -157,14 +158,29 @@ public Iterator getResponseHeaders(); /** - * Return the specified response headers. + * Return the specified response header. */ public Header getResponseHeader(String headerName); + /** + * Return my response body, if any, + * as a byte array. + * Otherwise return <tt>null</tt>. + */ public byte[] getResponseBody(); + /** + * Return my response body, if any, + * as a {@link String}. + * Otherwise return <tt>null</tt>. + */ public String getResponseBodyAsString(); + /** + * Return my response body, if any, + * as an {@link InputStream}. + * Otherwise return <tt>null</tt>. + */ public InputStream getResponseBodyAsStream() throws IOException; /** 1.10.2.18 +33 -17 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java Index: HttpMethodBase.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v retrieving revision 1.10.2.17 retrieving revision 1.10.2.18 diff -u -r1.10.2.17 -r1.10.2.18 --- HttpMethodBase.java 2001/08/15 23:19:34 1.10.2.17 +++ HttpMethodBase.java 2001/08/16 15:04:49 1.10.2.18 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v 1.10.2.17 2001/08/15 23:19:34 rwaldhoff Exp $ - * $Revision: 1.10.2.17 $ - * $Date: 2001/08/15 23:19:34 $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v 1.10.2.18 2001/08/16 15:04:49 rwaldhoff Exp $ + * $Revision: 1.10.2.18 $ + * $Date: 2001/08/16 15:04:49 $ * ==================================================================== * Copyright (C) The Apache Software Foundation. All rights reserved. * @@ -47,12 +47,6 @@ * <dt>{@link #writeRequestBody}</dt> * <dd>to write the body</dd> * </dl></ul> - * When a method's response may contain a body, - * subclasses may want to override: - * <ul><dl> - * <dt>{@link #readResponseBody}</dt> - * <dd>to do something useful with the returned data</dd> - * </dl></ul> * When a method requires additional request headers, * subclasses will typically want to override: * <ul><dl> @@ -68,7 +62,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a> * @author Rodney Waldhoff - * @version $Id: HttpMethodBase.java,v 1.10.2.17 2001/08/15 23:19:34 rwaldhoff Exp $ + * @version $Id: HttpMethodBase.java,v 1.10.2.18 2001/08/16 15:04:49 rwaldhoff Exp $ */ public abstract class HttpMethodBase implements HttpMethod { @@ -107,7 +101,6 @@ return log.getLevel(); } - /** * Obtain the name of this method, suitable for use in the "request line", * for example <tt>GET</tt> or <tt>POST</tt>. @@ -174,6 +167,7 @@ /** * Whether or not I should automatically follow * HTTP redirects (status code 302, etc.) + * @return <tt>true</tt> if I will automatically follow HTTP redirects */ public boolean followRedirects() { return this.followRedirects; @@ -189,11 +183,17 @@ /** * Set my query string. + * @param queryString the query string */ public void setQueryString(String queryString) { this.queryString = queryString; } + /** + * Set my query string. + * @param params an array of {@link NameValuePair}s + * to add as query string parameterss + */ public void setQueryString(NameValuePair[] params) { StringBuffer buf = new StringBuffer(); boolean needAmp = false; @@ -214,6 +214,11 @@ queryString = buf.toString(); } + /** + * Set my query string. + * @param params a {@link Collection} of {@link NameValuePair}s + * to add as query string parameterss + */ public void setQueryString(Collection params) { StringBuffer buf = new StringBuffer(); Iterator it = params.iterator(); @@ -238,10 +243,6 @@ queryString = buf.toString(); } - public void clearQueryString() { - this.queryString = null; - } - /** * Get my query string. */ @@ -250,7 +251,7 @@ } /** - * Return an iterator over my headers. + * Return an iterator over my request headers. */ public Iterator getRequestHeaders() { return requestHeaders.values().iterator(); @@ -296,14 +297,29 @@ return (Header)(responseHeaders.get(headerName.toLowerCase())); } + /** + * Return my response body, if any, + * as a byte array. + * Otherwise return <tt>null</tt>. + */ public byte[] getResponseBody() { return responseBody; } + /** + * Return my response body, if any, + * as a {@link String}. + * Otherwise return <tt>null</tt>. + */ public String getResponseBodyAsString() { return null == responseBody ? null : new String(responseBody); } + /** + * Return my response body, if any, + * as an {@link InputStream}. + * Otherwise return <tt>null</tt>. + */ public InputStream getResponseBodyAsStream() throws IOException { return null == responseBody ? null : new ByteArrayInputStream(responseBody); } @@ -985,7 +1001,7 @@ requestHeaders.clear(); responseHeaders.clear(); statusCode = -1; - statusText = "Not executed"; + statusText = null; used = false; http11 = true; bodySent = false;