Index: httpclient/src/java/org/apache/commons/httpclient/Authenticator.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Authenticator.java,v retrieving revision 1.38 diff -u -r1.38 Authenticator.java --- httpclient/src/java/org/apache/commons/httpclient/Authenticator.java 27 Jan 2003 15:25:44 -0000 1.38 +++ httpclient/src/java/org/apache/commons/httpclient/Authenticator.java 27 Jan 2003 22:36:48 -0000 @@ -100,7 +100,7 @@ * @author Ortwin Glück * @author Sean C. Sullivan * @author Adrian Sutton - * @author Mike Bowler * @version $Revision: 1.38 $ $Date: 2003/01/27 15:25:44 $ */ public class Authenticator { Index: httpclient/src/java/org/apache/commons/httpclient/AutoCloseInputStream.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/AutoCloseInputStream.java,v retrieving revision 1.6 diff -u -r1.6 AutoCloseInputStream.java --- httpclient/src/java/org/apache/commons/httpclient/AutoCloseInputStream.java 27 Jan 2003 15:25:45 -0000 1.6 +++ httpclient/src/java/org/apache/commons/httpclient/AutoCloseInputStream.java 27 Jan 2003 22:36:48 -0000 @@ -73,7 +73,7 @@ * * @author Ortwin Glück * @author Eric Johnson - * @author Mike Bowler * * @since 2.0 */ Index: httpclient/src/java/org/apache/commons/httpclient/ChunkedInputStream.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ChunkedInputStream.java,v retrieving revision 1.11 diff -u -r1.11 ChunkedInputStream.java --- httpclient/src/java/org/apache/commons/httpclient/ChunkedInputStream.java 27 Jan 2003 15:57:54 -0000 1.11 +++ httpclient/src/java/org/apache/commons/httpclient/ChunkedInputStream.java 27 Jan 2003 22:36:47 -0000 @@ -83,7 +83,7 @@ * @author Sean C. Sullivan * @author Martin Elwin * @author Eric Johnson - * @author Mike Bowler * * @since 2.0 * Index: httpclient/src/java/org/apache/commons/httpclient/ChunkedOutputStream.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ChunkedOutputStream.java,v retrieving revision 1.6 diff -u -r1.6 ChunkedOutputStream.java --- httpclient/src/java/org/apache/commons/httpclient/ChunkedOutputStream.java 27 Jan 2003 15:57:54 -0000 1.6 +++ httpclient/src/java/org/apache/commons/httpclient/ChunkedOutputStream.java 27 Jan 2003 22:36:47 -0000 @@ -77,7 +77,7 @@ * @author Sean C. Sullivan * @author dIon Gillard * @author Oleg Kalnichevski - * @author Mike Bowler * @version $Revision: 1.6 $ $Date: 2003/01/27 15:57:54 $ * * @see ChunkedInputStream Index: httpclient/src/java/org/apache/commons/httpclient/ConnectMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ConnectMethod.java,v retrieving revision 1.6 diff -u -r1.6 ConnectMethod.java --- httpclient/src/java/org/apache/commons/httpclient/ConnectMethod.java 27 Jan 2003 15:25:45 -0000 1.6 +++ httpclient/src/java/org/apache/commons/httpclient/ConnectMethod.java 27 Jan 2003 22:36:47 -0000 @@ -72,7 +72,7 @@ * * @author Ortwin Glück * @author dIon Gillard - * @author Mike Bowler * @since 2.0 * @version $Revision: 1.6 $ $Date: 2003/01/27 15:25:45 $ */ Index: httpclient/src/java/org/apache/commons/httpclient/ContentLengthInputStream.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ContentLengthInputStream.java,v retrieving revision 1.5 diff -u -r1.5 ContentLengthInputStream.java --- httpclient/src/java/org/apache/commons/httpclient/ContentLengthInputStream.java 27 Jan 2003 15:25:45 -0000 1.5 +++ httpclient/src/java/org/apache/commons/httpclient/ContentLengthInputStream.java 27 Jan 2003 22:36:47 -0000 @@ -72,7 +72,7 @@ * * @author Ortwin Glück * @author Eric Johnson - * @author Mike Bowler * @since 2.0 */ Index: httpclient/src/java/org/apache/commons/httpclient/Cookie.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Cookie.java,v retrieving revision 1.34 diff -u -r1.34 Cookie.java --- httpclient/src/java/org/apache/commons/httpclient/Cookie.java 27 Jan 2003 15:25:45 -0000 1.34 +++ httpclient/src/java/org/apache/commons/httpclient/Cookie.java 27 Jan 2003 22:36:48 -0000 @@ -76,8 +76,8 @@ /** *
An HTTP "magic-cookie", as specified in RFC 2109.
- * - * @author B.C. Holmes + * + * @author B.C. Holmes * @author Park, Sung-Gu * @author Doug Sale * @author Rod Waldhoff @@ -86,7 +86,8 @@ * @author John Evans * @author Marc A. Saegesser * @author Oleg Kalnichevski - * @author Mike Bowler + * * @version $Revision: 1.34 $ $Date: 2003/01/27 15:25:45 $ */ @@ -112,7 +113,7 @@ * @param domain the host this cookie will be sent to */ public Cookie(String domain, String name, String value) { - this(domain,name,value,null,null,false); + this(domain, name, value, null, null, false); } /** @@ -125,9 +126,12 @@ * @param expires the {@link Date} at which this cookie expires, * or null if the cookie expires at the end * of the session - * @param secure if true this cookie will only be sent over secure connections + * @param secure if true this cookie will only be sent over secure + * connections */ - public Cookie(String domain, String name, String value, String path, Date expires, boolean secure) { + public Cookie(String domain, String name, String value, + String path, Date expires, boolean secure) { + super(name, value); LOG.trace("enter Cookie(String, String, String, String, Date, boolean)"); if (name == null) { @@ -151,15 +155,19 @@ /** * Create a cookie. * - * @param name the cookie name - * @param value the cookie value - * @param domain the host this cookie will be sent to - * @param path the path prefix for which this cookie will be sent - * @param maxAge the number of seconds for which this cookie is valid - * @param secure if true this cookie will only be sent over secure connections + * @param name the cookie name + * @param value the cookie value + * @param domain the host this cookie will be sent to + * @param path the path prefix for which this cookie will be sent + * @param maxAge the number of seconds for which this cookie is valid + * @param secure if true this cookie will only be sent over secure + * connections */ - public Cookie(String domain, String name, String value, String path, int maxAge, boolean secure) { - this(domain,name,value,path,new Date(System.currentTimeMillis() + maxAge*1000L),secure); + public Cookie(String domain, String name, String value, String path, + int maxAge, boolean secure) { + + this(domain, name, value, path, + new Date(System.currentTimeMillis() + maxAge * 1000L), secure); } /** @@ -338,21 +346,22 @@ } /** - * + * Return true if this cookie has expired. * @return true if I have expired. */ public boolean isExpired() { - return (_expiryDate != null && - _expiryDate.getTime() <= System.currentTimeMillis()); + return (_expiryDate != null + && _expiryDate.getTime() <= System.currentTimeMillis()); } /** - * + * Return true if this cookie has expired according to the time passed in. + * @param now The current time. * @return true if I have expired. */ public boolean isExpired(Date now) { - return (_expiryDate != null && - _expiryDate.getTime() <= now.getTime()); + return (_expiryDate != null + && _expiryDate.getTime() <= now.getTime()); } @@ -367,8 +376,7 @@ * @see #isPathAttributeSpecified * @param value True if the cookie's path came from a Path attribute. */ - public void setPathAttributeSpecified(boolean value) - { + public void setPathAttributeSpecified(boolean value) { _hasPathAttribute = value; } @@ -379,8 +387,7 @@ * @see #setPathAttributeSpecified * @return True if cookie's path was specified in the set-cookie header. */ - public boolean isPathAttributeSpecified() - { + public boolean isPathAttributeSpecified() { return _hasPathAttribute; } @@ -395,8 +402,7 @@ * @see #isDomainAttributeSpecified * @param value True if the cookie's domain came from a Domain attribute. */ - public void setDomainAttributeSpecified(boolean value) - { + public void setDomainAttributeSpecified(boolean value) { _hasDomainAttribute = value; } @@ -407,32 +413,42 @@ * @see #setDomainAttributeSpecified * @return True if cookie's domain was specified in the set-cookie header. */ - public boolean isDomainAttributeSpecified() - { + public boolean isDomainAttributeSpecified() { return _hasDomainAttribute; } /** * Returns a hash code in keeping with the - * {@link Object#hashCode general hashCode contract}. + * {@link Object#hashCode} general hashCode contract. + * @return A hash code */ public int hashCode() { - return super.hashCode() ^ - (null == _path ? 0 : _path.hashCode()) ^ - (null == _domain ? 0 : _domain.hashCode()); + return super.hashCode() + ^ (null == _path ? 0 : _path.hashCode()) + ^ (null == _domain ? 0 : _domain.hashCode()); } /** * Two cookies are equal if the name, path and domain match. + * @param obj The object to compare against. + * @return true if the two objects are equal. */ public boolean equals(Object obj) { LOG.trace("enter Cookie.equals(Object)"); + if ((obj != null) && (obj instanceof Cookie)) { Cookie that = (Cookie) obj; - return (null == this.getName() ? null == that.getName() : this.getName().equals(that.getName())) && - (null == this.getPath() ? null == that.getPath() : this.getPath().equals(that.getPath())) && - (null == this.getDomain() ? null == that.getDomain() : this.getDomain().equals(that.getDomain())); + return + (null == this.getName() + ? null == that.getName() + : this.getName().equals(that.getName())) + && (null == this.getPath() + ? null == that.getPath() + : this.getPath().equals(that.getPath())) + && (null == this.getDomain() + ? null == that.getDomain() + : this.getDomain().equals(that.getDomain())); } else { return false; } @@ -444,37 +460,44 @@ * @return a string suitable for sending in a Cookie header. */ public String toExternalForm() { - return CookiePolicy.getSpecByVersion(getVersion()).formatCookie(this); + return CookiePolicy.getSpecByVersion( + getVersion()).formatCookie(this); } /** - * Return true if I should be submitted with a request with - * given attributes, false otherwise. + * Return true if I should be submitted with a request with given + * attributes, false otherwise. * @param domain the host to which the request is being submitted - * @param port the port to which the request is being submitted (currenlty ignored) + * @param port the port to which the request is being submitted (currently + * ignored) * @param path the path to which the request is being submitted * @param secure true if the request is using the HTTPS protocol * @param date the time at which the request is submitted + * @return true if the cookie matches * * @deprecated use {@link CookieSpec} interface */ - public boolean matches(String domain, int port, String path, boolean secure, Date date) - { + public boolean matches( + String domain, int port, String path, boolean secure, Date date) { + LOG.trace("enter Cookie.matches(Strinng, int, String, boolean, Date"); CookieSpec matcher = CookiePolicy.getDefaultSpec(); return matcher.match(domain, port, path, secure, this); } /** - * Return true if I should be submitted with a request with - * given attributes, false otherwise. + * Return true if I should be submitted with a request with given + * attributes, false otherwise. * @param domain the host to which the request is being submitted - * @param port the port to which the request is being submitted (currenlty ignored) + * @param port the port to which the request is being submitted (currently + * ignored) * @param path the path to which the request is being submitted - * + * @param secure True if this cookie has the secure flag set + * @return true if I should be submitted as above. * @deprecated use {@link CookieSpec} interface */ - public boolean matches(String domain, int port, String path, boolean secure) { + public boolean matches( + String domain, int port, String path, boolean secure) { LOG.trace("enter Cookie.matches(String, int, String, boolean"); return matches(domain, port, path, secure, new Date()); } @@ -488,11 +511,17 @@ ** If no cookies match, returns null. * + * @param domain The domain + * @param path The path + * @param cookies The cookies to use + * @return The new header. * @deprecated use {@link CookieSpec} interface */ - public static Header createCookieHeader(String domain, String path, Cookie[] cookies) { - LOG.trace("enter Cookie.createCookieHeader(String, String, Cookie[])"); - return Cookie.createCookieHeader(domain,path,false,cookies); + public static Header createCookieHeader(String domain, String path, + Cookie[] cookies) { + + LOG.trace("enter Cookie.createCookieHeader(String,String,Cookie[])"); + return Cookie.createCookieHeader(domain, path, false, cookies); } /** @@ -502,30 +531,43 @@ * https setting. *
* If no cookies match, returns null. - * @exception java.lang.IllegalArgumentException if domain or path is null + * + * @param domain The domain + * @param path The path + * @param secure True if this cookie has the secure flag set + * @param cookies The cookies to use. + * @return The new header + * @exception IllegalArgumentException if domain or path is null * * @deprecated use {@link CookieSpec} interface */ - public static Header createCookieHeader(String domain, String path, boolean secure, Cookie[] cookies) - throws IllegalArgumentException { - LOG.trace("enter Cookie.createCookieHeader(String, String, boolean, Cookie[])"); - - // Make sure domain isn't null here. Path will be validated in subsequent call to createCookieHeader - if(domain == null){ - throw new IllegalArgumentException("null domain in createCookieHeader."); + public static Header createCookieHeader(String domain, String path, + boolean secure, Cookie[] cookies) + throws IllegalArgumentException { + + LOG.trace("enter Cookie.createCookieHeader(" + + "String, String, boolean, Cookie[])"); + + // Make sure domain isn't null here. Path will be validated in + // subsequent call to createCookieHeader + if (domain == null) { + throw new IllegalArgumentException("null domain in " + + "createCookieHeader."); } // parse port from domain, if any int port = secure ? 443 : 80; int ndx = domain.indexOf(":"); if (ndx != -1) { try { - port = Integer.parseInt(domain.substring(ndx+1,domain.length())); - } catch(NumberFormatException e){ + port = Integer.parseInt(domain.substring(ndx + 1, + domain.length())); + } catch (NumberFormatException e) { // ignore?, but at least LOG - LOG.warn("Cookie.createCookieHeader(): Invalid port number in domain " + domain); + LOG.warn("Cookie.createCookieHeader(): " + + "Invalid port number in domain " + domain); } } - return Cookie.createCookieHeader(domain,port,path,secure,cookies); + return Cookie.createCookieHeader(domain, port, path, secure, cookies); } /** @@ -535,13 +577,21 @@ * path and https setting. *
* If no cookies match, returns null. - * @exception java.lang.IllegalArgumentException if domain or path is null + * + * @param domain The domain + * @param port The port + * @param path The path + * @param secure True if this cookie has the secure flag set + * @param cookies The cookies to use. + * @return The new header + * @throws IllegalArgumentException if domain or path is null * * @deprecated use {@link CookieSpec} interface */ - public static Header createCookieHeader(String domain, int port, String path, boolean secure, Cookie[] cookies) - throws IllegalArgumentException { - LOG.trace("enter Cookie.createCookieHeader(String, int, String, boolean, Cookie[])"); + public static Header createCookieHeader(String domain, int port, + String path, boolean secure, Cookie[] cookies) + throws IllegalArgumentException { + LOG.trace("enter Cookie.createCookieHeader(String, int, String, boolean, Cookie[])"); return Cookie.createCookieHeader(domain, port, path, secure, new Date(), cookies); } @@ -560,7 +610,7 @@ * @param now The date to check for expiry * @param cookies The cookies to use. * @return The new header - * @exception IllegalArgumentException if domain or path is null + * @throws IllegalArgumentException if domain or path is null * * @deprecated use {@link CookieSpec} interface */ @@ -575,8 +625,7 @@ cookies = matcher.match(domain, port, path, secure, cookies); if ((cookies != null) && (cookies.length > 0)) { return matcher.formatCookieHeader(cookies); - } - else { + } else { return null; } } @@ -654,7 +703,7 @@ throws HttpException, IllegalArgumentException { LOG.trace("enter Cookie.parse(String, int, String, Header)"); - return Cookie.parse(domain,port,path,false,setCookie); + return Cookie.parse(domain, port, path, false, setCookie); } /** Index: httpclient/src/java/org/apache/commons/httpclient/Credentials.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Credentials.java,v retrieving revision 1.6 diff -u -r1.6 Credentials.java --- httpclient/src/java/org/apache/commons/httpclient/Credentials.java 23 Jan 2003 22:47:45 -0000 1.6 +++ httpclient/src/java/org/apache/commons/httpclient/Credentials.java 27 Jan 2003 22:36:48 -0000 @@ -65,9 +65,11 @@ /** *
Authentication credentials.
*- * This is just a marker interface, the - * current implementation has no methods. + * This is just a marker interface, the current implementation has no methods. *
+ * @author Unascribed + * @author Mike Bowler + * * @version $Revision: 1.6 $ $Date: 2003/01/23 22:47:45 $ */ public interface Credentials { Index: httpclient/src/java/org/apache/commons/httpclient/Header.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Header.java,v retrieving revision 1.9 diff -u -r1.9 Header.java --- httpclient/src/java/org/apache/commons/httpclient/Header.java 23 Jan 2003 22:47:45 -0000 1.9 +++ httpclient/src/java/org/apache/commons/httpclient/Header.java 27 Jan 2003 22:36:47 -0000 @@ -66,6 +66,7 @@ *An HTTP header.
* * @author Remy Maucherat + * @author Mike Bowler * @version $Revision: 1.9 $ $Date: 2003/01/23 22:47:45 $ */ public class Header extends NameValuePair { @@ -76,7 +77,7 @@ * Default constructor. */ public Header() { - this(null,null); + this(null, null); } /** @@ -98,10 +99,10 @@ * @return string value for a HTTP HEAD */ public String toExternalForm() { - return ((null == getName() ? "" : getName()) + - ": " + - (null == getValue() ? "" : getValue()) + - "\r\n"); + return ((null == getName() ? "" : getName()) + + ": " + + (null == getValue() ? "" : getValue()) + + "\r\n"); } /** Index: httpclient/src/java/org/apache/commons/httpclient/HeaderElement.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HeaderElement.java,v retrieving revision 1.13 diff -u -r1.13 HeaderElement.java --- httpclient/src/java/org/apache/commons/httpclient/HeaderElement.java 23 Jan 2003 22:47:45 -0000 1.13 +++ httpclient/src/java/org/apache/commons/httpclient/HeaderElement.java 27 Jan 2003 22:36:47 -0000 @@ -112,6 +112,8 @@ * * @author B.C. Holmes * @author Park, Sung-Gu + * @author Mike Bowler + * * @version $Revision: 1.13 $ $Date: 2003/01/23 22:47:45 $ */ public class HeaderElement extends NameValuePair { @@ -122,7 +124,7 @@ * Default constructor. */ public HeaderElement() { - this(null,null,null); + this(null, null, null); } /** @@ -131,7 +133,7 @@ * @param value my (possibly null) value */ public HeaderElement(String name, String value) { - this(name,value,null); + this(name, value, null); } /** @@ -144,13 +146,13 @@ public HeaderElement(String name, String value, NameValuePair[] parameters) { super(name, value); - this.parameters = parameters; + setParameters(parameters); } // -------------------------------------------------------- Constants /** Log object for this class. */ - private static final Log log = LogFactory.getLog(HeaderElement.class); + private static final Log LOG = LogFactory.getLog(HeaderElement.class); /** * Map of numeric values to whether or not the @@ -229,7 +231,7 @@ // ----------------------------------------------------- Instance Variables /** My parameters, if any. */ - protected NameValuePair[] parameters = null; + private NameValuePair[] _parameters = null; // ------------------------------------------------------------- Properties @@ -239,9 +241,16 @@ * @return parameters as an array of {@link NameValuePair}s */ public NameValuePair[] getParameters() { - return this.parameters; + return this._parameters; } + /** + * + * @param pairs The new parameters. May be null. + */ + protected void setParameters(final NameValuePair[] pairs) { + _parameters = pairs; + } // --------------------------------------------------------- Public Methods /** @@ -253,9 +262,10 @@ * @return the header elements containingHeader elements.
* @throws HttpException if the above syntax rules are violated.
*/
- public final static HeaderElement[] parse(String headerValue)
- throws HttpException {
- log.trace("enter HeaderElement.parse(String)");
+ public static final HeaderElement[] parse(String headerValue)
+ throws HttpException {
+
+ LOG.trace("enter HeaderElement.parse(String)");
if (headerValue == null) {
return null;
@@ -289,20 +299,20 @@
* For the general cases, rfc1123-date, rfc850-date.
*/
if (tokenizer.hasMoreTokens()) {
- if (nextToken.endsWith("Mon") ||
- nextToken.endsWith("Tue") ||
- nextToken.endsWith("Wed") ||
- nextToken.endsWith("Thu") ||
- nextToken.endsWith("Fri") ||
- nextToken.endsWith("Sat") ||
- nextToken.endsWith("Sun") ||
- nextToken.endsWith("Monday") ||
- nextToken.endsWith("Tuesday") ||
- nextToken.endsWith("Wednesday") ||
- nextToken.endsWith("Thursday") ||
- nextToken.endsWith("Friday") ||
- nextToken.endsWith("Saturday") ||
- nextToken.endsWith("Sunday" )) {
+ if (nextToken.endsWith("Mon")
+ || nextToken.endsWith("Tue")
+ || nextToken.endsWith("Wed")
+ || nextToken.endsWith("Thu")
+ || nextToken.endsWith("Fri")
+ || nextToken.endsWith("Sat")
+ || nextToken.endsWith("Sun")
+ || nextToken.endsWith("Monday")
+ || nextToken.endsWith("Tuesday")
+ || nextToken.endsWith("Wednesday")
+ || nextToken.endsWith("Thursday")
+ || nextToken.endsWith("Friday")
+ || nextToken.endsWith("Saturday")
+ || nextToken.endsWith("Sunday")) {
nextToken += "," + tokenizer.nextToken();
}
@@ -328,8 +338,8 @@
NameValuePair pair = parsePair(header, startPos, i);
if (pair == null) {
throw new HttpException(
- "Bad header format: empty name/value pair in" +
- nextToken);
+ "Bad header format: empty name/value pair in"
+ + nextToken);
// the first name/value pair are handled differently
} else if (startPos == 0) {
@@ -339,8 +349,8 @@
paramlist.addElement(pair);
}
startPos = i + 1;
- } else if (header[i] == '"' &&
- !(inAString && i > 0 && header[i-1] == '\\')) {
+ } else if (header[i] == '"'
+ && !(inAString && i > 0 && header[i - 1] == '\\')) {
inAString = !inAString;
}
}
@@ -349,7 +359,7 @@
if (paramlist.size() > 0) {
NameValuePair[] tmp2 = new NameValuePair[paramlist.size()];
paramlist.copyInto((NameValuePair[]) tmp2);
- element.parameters = tmp2;
+ element.setParameters (tmp2);
paramlist.removeAllElements();
}
@@ -370,10 +380,10 @@
* @return true if there are an odd number of quotation marks, false
* otherwise
*/
- private final static boolean hasOddNumberOfQuotationMarks(String string) {
+ private static final boolean hasOddNumberOfQuotationMarks(String string) {
boolean odd = false;
int start = -1;
- while ((start = string.indexOf('"', start+1)) != -1) {
+ while ((start = string.indexOf('"', start + 1)) != -1) {
odd = !odd;
}
return odd;
@@ -387,10 +397,11 @@
* @param end the end position of the text within the array
* @return a {@link NameValuePair} representing the header
*/
- private final static NameValuePair parsePair(char[] header, int start, int end) {
- log.trace("enter HeaderElement.parsePair(char[], int, int)");
+ private static final NameValuePair parsePair(char[] header,
+ int start, int end) {
+
+ LOG.trace("enter HeaderElement.parsePair(char[], int, int)");
- boolean done = false;
NameValuePair pair = null;
String name = new String(header, start, end - start).trim();
String value = null;
@@ -399,13 +410,13 @@
int index = name.indexOf("=");
if (index >= 0) {
if ((index + 1) < name.length()) {
- value = name.substring(index+1).trim();
+ value = name.substring(index + 1).trim();
// strip quotation marks
if (value.startsWith("\"") && value.endsWith("\"")) {
- value = value.substring(1,value.length()-1);
+ value = value.substring(1, value.length() - 1);
}
}
- name = name.substring(0,index).trim();
+ name = name.substring(0, index).trim();
}
pair = new NameValuePair(name, value);
@@ -418,6 +429,7 @@
* Returns parameter with the given name, if found. Otherwise null
* is returned
*
+ * @param name The name to search by.
* @return NameValuePair parameter with the given name
*/
@@ -426,9 +438,10 @@
throw new NullPointerException("Name is null");
}
NameValuePair found = null;
- if (this.parameters != null) {
- for(int i = 0; i < this.parameters.length; i ++) {
- NameValuePair current = this.parameters[ i ];
+ NameValuePair parameters[] = getParameters();
+ if (parameters != null) {
+ for (int i = 0; i < parameters.length; i++) {
+ NameValuePair current = parameters[ i ];
if (current.getName().equalsIgnoreCase(name)) {
found = current;
break;
Index: httpclient/src/java/org/apache/commons/httpclient/HostConfiguration.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HostConfiguration.java,v
retrieving revision 1.7
diff -u -r1.7 HostConfiguration.java
--- httpclient/src/java/org/apache/commons/httpclient/HostConfiguration.java 23 Jan 2003 22:47:46 -0000 1.7
+++ httpclient/src/java/org/apache/commons/httpclient/HostConfiguration.java 27 Jan 2003 22:36:47 -0000
@@ -67,17 +67,30 @@
/**
*
* @author Michael Becke
+ * @author Mike Bowler
* @since 2.0
*/
-public class HostConfiguration implements Cloneable{
+public class HostConfiguration implements Cloneable {
+ /** The host to use. */
private String host;
+
+ /** The port to use. */
private int port;
+
+ /** The protocol */
private Protocol protocol;
+
+ /** True if a host has been set */
private boolean hostSet;
-
+
+ /** The host name of the proxy server */
private String proxyHost;
+
+ /** The port number of the proxy server */
private int proxyPort;
+
+ /** True if a proxy server has been set */
private boolean proxySet;
/**
@@ -101,11 +114,11 @@
*
* @param hostConfiguration the hostConfiguration to copy
*/
- public HostConfiguration( HostConfiguration hostConfiguration ) {
+ public HostConfiguration (HostConfiguration hostConfiguration) {
// wrap all of the assignments in a synchronized block to avoid
// having to negotiate the monitor for each method call
- synchronized( hostConfiguration ) {
+ synchronized (hostConfiguration) {
this.host = hostConfiguration.getHost();
this.port = hostConfiguration.getPort();
this.protocol = hostConfiguration.getProtocol();
@@ -138,13 +151,10 @@
*/
public synchronized boolean hostEquals(HttpConnection connection) {
- if ( hostSet ) {
-
- return (
- host.equalsIgnoreCase(connection.getHost())
+ if (hostSet) {
+ return (host.equalsIgnoreCase(connection.getHost())
&& port == connection.getPort()
- && protocol.equals(connection.getProtocol())
- );
+ && protocol.equals(connection.getProtocol()));
} else {
return false;
@@ -164,7 +174,7 @@
*/
public synchronized boolean proxyEquals(HttpConnection connection) {
- if ( proxyHost == null ) {
+ if (proxyHost == null) {
return connection.getProxyHost() == null;
} else {
return (
@@ -175,16 +185,22 @@
}
+ /**
+ * Return true if the host is set.
+ * @return boolean True if the host is set.
+ */
public synchronized boolean isHostSet() {
return hostSet;
}
- public synchronized void setHost(
- String host,
- int port,
- String protocol
- ) {
- setHost( host, port, Protocol.getProtocol(protocol) );
+ /**
+ * Set the host
+ * @param host The host.
+ * @param port The port
+ * @param protocol The protocol.
+ */
+ public synchronized void setHost(String host, int port, String protocol) {
+ setHost(host, port, Protocol.getProtocol(protocol));
}
/**
@@ -194,16 +210,14 @@
* @param port the host port or -1 to use protocol default
* @param protocol the protocol
*/
- public synchronized void setHost(
- String host,
- int port,
- Protocol protocol
- ) {
- if ( host == null ) {
- throw new IllegalArgumentException( "host must not be null" );
+ public synchronized void setHost(String host, int port,
+ Protocol protocol) {
+
+ if (host == null) {
+ throw new IllegalArgumentException("host must not be null");
}
- if ( protocol == null ) {
- throw new IllegalArgumentException( "protocol must not be null" );
+ if (protocol == null) {
+ throw new IllegalArgumentException("protocol must not be null");
}
this.host = host;
@@ -221,22 +235,27 @@
public synchronized void setHost(URI uri) {
try {
setHost(uri.getHost(), uri.getPort(), uri.getScheme());
- } catch(URIException e) {
+ } catch (URIException e) {
throw new IllegalArgumentException(e.toString());
}
}
+ /**
+ * Return the host url.
+ *
+ * @return String The host url.
+ */
public synchronized String getHostURL() {
- if ( !hostSet ) {
- throw new IllegalStateException(
- "a default host must be set to create a host URL"
+ if (!hostSet) {
+ throw new IllegalStateException("a default host must be set to "
+ + "create a host URL"
);
}
String url = protocol.getScheme() + "://" + host;
- if ( port != -1 && port != protocol.getDefaultPort() ) {
+ if (port != -1 && port != protocol.getDefaultPort()) {
url += ":" + port;
}
@@ -262,23 +281,30 @@
/**
* Returns the protocol.
- * @return String
+ * @return String The protocol.
*/
public synchronized Protocol getProtocol() {
return protocol;
}
-
+
+ /**
+ * @return boolean True if a proxy server has been set.
+ */
public synchronized boolean isProxySet() {
return proxySet;
}
- public synchronized void setProxy( String proxyHost, int proxyPort ) {
+ /**
+ * Set the proxy settings.
+ * @param proxyHost The proxy host
+ * @param proxyPort The proxy port
+ */
+ public synchronized void setProxy(String proxyHost, int proxyPort) {
this.proxyHost = proxyHost;
this.proxyPort = proxyPort;
this.proxySet = true;
-
}
/**
@@ -302,34 +328,32 @@
*/
public synchronized boolean equals(Object o) {
- if ( o instanceof HostConfiguration ) {
+ if (o instanceof HostConfiguration) {
// shortcut if we're comparing with ourselves
- if ( o == this ) return true;
+ if (o == this) {
+ return true;
+ }
- HostConfiguration config = (HostConfiguration)o;
+ HostConfiguration config = (HostConfiguration) o;
- if ( hostSet ) {
- if (
- !host.equalsIgnoreCase( config.getHost() )
+ if (hostSet) {
+ if (!host.equalsIgnoreCase(config.getHost())
|| port != config.getPort()
- || !protocol.equals( config.getProtocol() )
- ) {
+ || !protocol.equals(config.getProtocol())) {
// either host, port or protocol don't match
return false;
}
- } else if ( config.isHostSet() ) {
+ } else if (config.isHostSet()) {
return false;
}
- if ( proxyHost != null ) {
- if (
- !proxyHost.equalsIgnoreCase( config.getProxyHost() )
- || proxyPort != config.getProxyPort()
- ) {
+ if (proxyHost != null) {
+ if (!proxyHost.equalsIgnoreCase (config.getProxyHost())
+ || proxyPort != config.getProxyPort()) {
// either proxyHost or proxyPort don't match
return false;
}
- } else if ( config.getProxyHost() != null ) {
+ } else if (config.getProxyHost() != null) {
return false;
}
@@ -347,14 +371,12 @@
*/
public int hashCode() {
- if ( host != null ) {
+ if (host != null) {
return host.hashCode();
- } else if ( proxyHost != null ) {
+ } else if (proxyHost != null) {
return proxyHost.hashCode();
} else {
return super.hashCode();
}
-
}
-
}
Index: httpclient/src/java/org/apache/commons/httpclient/HttpClient.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v
retrieving revision 1.67
diff -u -r1.67 HttpClient.java
--- httpclient/src/java/org/apache/commons/httpclient/HttpClient.java 23 Jan 2003 22:47:46 -0000 1.67
+++ httpclient/src/java/org/apache/commons/httpclient/HttpClient.java 27 Jan 2003 22:36:47 -0000
@@ -82,6 +82,7 @@
* @author dIon Gillard
* @author Ortwin Glück
* @author Michael Becke
+ * @author Mike Bowler
*
* @version $Revision: 1.67 $ $Date: 2003/01/23 22:47:46 $
*/
@@ -92,7 +93,7 @@
// -------------------------------------------------------------- Constants
/** Log object for this class. */
- private static final Log log = LogFactory.getLog(HttpClient.class);
+ private static final Log LOG = LogFactory.getLog(HttpClient.class);
// ----------------------------------------------------------- Constructors
@@ -102,22 +103,23 @@
* @see SimpleHttpConnectionManager
*/
public HttpClient() {
- this( new SimpleHttpConnectionManager() );
+ this(new SimpleHttpConnectionManager());
}
/**
* Creates an HttpClient with a user specified connection manager.
+ * @param httpConnectionManager The connection manager to use.
*
* @since 2.0
*/
- public HttpClient( HttpConnectionManager httpConnectionManager ) {
+ public HttpClient(HttpConnectionManager httpConnectionManager) {
- if ( httpConnectionManager == null ) {
+ if (httpConnectionManager == null) {
throw new IllegalArgumentException("httpConnectionManager cannot be null");
}
this.state = new HttpState();
- this.state.setHttpConnectionManager( httpConnectionManager );
+ this.state.setHttpConnectionManager(httpConnectionManager);
this.hostConfiguration = new HostConfiguration();
@@ -133,12 +135,16 @@
/** the timout when waiting for a connection from the connectionManager */
private long httpConnectionTimeout = 0;
+ /** The timeout in milliseconds*/
private int timeoutInMilliseconds = 0;
+ /** The connection timeout. */
private int connectionTimeout = 0;
+ /** The host configuration to use */
private HostConfiguration hostConfiguration;
+ /** True if strict mode is enabled. */
private boolean strictMode = false;
// ------------------------------------------------------------- Properties
@@ -205,7 +211,7 @@
*
* @see HttpConnectionManager#getConnection(HostConfiguration, long)
*/
- public synchronized void setHttpConnectionFactoryTimeout( long timeout ) {
+ public synchronized void setHttpConnectionFactoryTimeout(long timeout) {
this.httpConnectionTimeout = timeout;
}
@@ -233,7 +239,7 @@
* @see #getHostConfiguration()
*/
public void startSession(String host, int port) {
- log.trace("enter HttpClient.startSession(String, int)");
+ LOG.trace("enter HttpClient.startSession(String, int)");
startSession(host, port, false);
}
@@ -249,18 +255,14 @@
* @see #getHostConfiguration()
*/
public void startSession(String host, int port, boolean https) {
- log.trace("enter HttpClient.startSession(String, int, boolean)");
+ LOG.trace("enter HttpClient.startSession(String, int, boolean)");
- if (log.isDebugEnabled()) {
- log.debug("HttpClient.startSession(String,int,boolean): Host:"
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("HttpClient.startSession(String,int,boolean): Host:"
+ host + " Port:" + port + " HTTPS:" + https);
}
- this.hostConfiguration.setHost(
- host,
- port,
- https ? "https" : "http"
- );
+ this.hostConfiguration.setHost(host, port, https ? "https" : "http");
}
/**
@@ -278,7 +280,7 @@
* @see #startSession(String, int, Credentials, boolean)
*/
public void startSession(String host, int port, Credentials creds) {
- log.trace("enter HttpClient.startSession(String, int, Credentials)");
+ LOG.trace("enter HttpClient.startSession(String, int, Credentials)");
startSession(host, port, creds, false);
}
@@ -295,12 +297,12 @@
*
* @see #getHostConfiguration()
* @see #getState()
- */
+ */
public void startSession(String host, int port, Credentials creds, boolean https) {
- log.trace("enter HttpClient.startSession(String, int, Credentials, boolean)");
+ LOG.trace("enter HttpClient.startSession(String, int, Credentials, boolean)");
- if (log.isDebugEnabled()) {
- log.debug(
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(
"Starting HttpClient session"
+ " Host:" + host
+ " Port:" + port + " Credentials:" + creds
@@ -327,21 +329,24 @@
* {@link URI URI} from which the scheme, userinfo, host and port of the
* session are determined
*
- * @exception IllegalStateException not enough information to process
+ * @throws IllegalStateException not enough information to process
+ * @throws URIException If the URI is bad.
*
* @see #getHostConfiguration()
* @see #getState()
*/
- public void startSession(URI uri) throws URIException {
- log.trace("enter HttpClient.startSession(URI)");
+ public void startSession(URI uri)
+ throws URIException, IllegalStateException {
+
+ LOG.trace("enter HttpClient.startSession(URI)");
String scheme = uri.getScheme();
if (scheme == null) { // it may a URI instance or abs_path
- log.error("no scheme to start a session");
+ LOG.error("no scheme to start a session");
throw new IllegalStateException("no scheme to start a session");
}
- Protocol protocol = Protocol.getProtocol( scheme );
+ Protocol protocol = Protocol.getProtocol(scheme);
String userinfo = uri.getUserinfo();
if (userinfo != null) {
@@ -350,16 +355,16 @@
}
String host = uri.getHost();
if (host == null || host.length() == 0) {
- log.error("no host to start a session");
+ LOG.error("no host to start a session");
throw new IllegalStateException("no host to start a session");
}
int port = uri.getPort();
if (port == -1) { // neither HttpURL or HttpsURL instance
- log.error("HttpURL or HttpsURL instance required");
+ LOG.error("HttpURL or HttpsURL instance required");
throw new IllegalStateException
("HttpURL or HttpsURL instance required");
}
- this.hostConfiguration.setHost( host, port, protocol );
+ this.hostConfiguration.setHost(host, port, protocol);
}
/**
@@ -377,18 +382,13 @@
*
* @see #getHostConfiguration()
*/
- public void startSession(URL url) {
- log.trace("enter HttpClient.startSession(String, int, Credentials, boolean)");
+ public void startSession(URL url) throws IllegalArgumentException {
+ LOG.trace("enter HttpClient.startSession(String, int, Credentials, boolean)");
int port = url.getPort();
- Protocol protocol = Protocol.getProtocol( url.getProtocol() );
-
- hostConfiguration.setHost(
- url.getHost(),
- port,
- protocol
- );
+ Protocol protocol = Protocol.getProtocol(url.getProtocol());
+ hostConfiguration.setHost(url.getHost(), port, protocol);
}
/**
@@ -409,8 +409,10 @@
* @see #getHostConfiguration()
* @see #getState()
*/
- public void startSession(URL url, Credentials creds) {
- log.trace("enter HttpClient.startSession(URL, Credentials)");
+ public void startSession(URL url, Credentials creds)
+ throws IllegalArgumentException {
+
+ LOG.trace("enter HttpClient.startSession(URL, Credentials)");
getState().setCredentials(null, creds);
startSession(url);
}
@@ -429,7 +431,7 @@
* @see #getHostConfiguration()
*/
public void startSession(String host, int port, String proxyhost, int proxyport) {
- log.trace("enter HttpClient.startSession(String, int, String, int)");
+ LOG.trace("enter HttpClient.startSession(String, int, String, int)");
startSession(host, port, proxyhost, proxyport, false);
}
@@ -447,14 +449,13 @@
*
* @see #getHostConfiguration()
*/
- public void startSession(String host, int port, String proxyhost, int proxyport, boolean secure) {
- log.trace("enter HttpClient.startSession(String, int, String, int, boolean)");
- this.hostConfiguration.setHost(
- host,
- port,
- secure ? "https" : "http"
- );
- this.hostConfiguration.setProxy( proxyhost, proxyport );
+ public void startSession(String host, int port,
+ String proxyhost, int proxyport, boolean secure) {
+
+ LOG.trace("enter HttpClient.startSession("
+ + "String, int, String, int, boolean)");
+ this.hostConfiguration.setHost (host, port, secure ? "https" : "http");
+ this.hostConfiguration.setProxy(proxyhost, proxyport);
}
/**
@@ -463,13 +464,13 @@
* @param method the {@link HttpMethod} to execute.
* @return the method's response code
*
- * @throws java.io.IOException if an I/O error occurs
+ * @throws IOException if an I/O error occurs
* @throws HttpException if a protocol exception occurs
*/
public int executeMethod(HttpMethod method)
throws IOException, HttpException {
- log.trace("enter HttpClient.executeMethod(HttpMethod)");
+ LOG.trace("enter HttpClient.executeMethod(HttpMethod)");
// execute this method and use its host configuration, if it has one
return executeMethod(
method.getHostConfiguration() != null
@@ -483,17 +484,19 @@
/**
* Executes the given method.
*
+ * @param hostConfiguration The configuration to use.
* @param method the {@link HttpMethod} to execute.
* @return the method's response code
*
- * @throws java.io.IOException if an I/O error occurs
+ * @throws IOException if an I/O error occurs
* @throws HttpException if a protocol exception occurs
- *
* @since 2.0
*/
- public int executeMethod(HostConfiguration hostConfiguration, HttpMethod method)
+ public int executeMethod(HostConfiguration hostConfiguration,
+ HttpMethod method)
throws IOException, HttpException {
- log.trace("enter HttpClient.executeMethod(HostConfiguration,HttpMethod)");
+
+ LOG.trace("enter HttpClient.executeMethod(HostConfiguration,HttpMethod)");
if (null == method) {
throw new NullPointerException("HttpMethod parameter");
@@ -510,7 +513,7 @@
* from accessing data asynchronously as well having to regain the lock
* for each item.
*/
- synchronized ( this ) {
+ synchronized (this) {
soTimeout = this.timeoutInMilliseconds;
strictMode = this.strictMode;
connectionTimeout = this.connectionTimeout;
@@ -519,18 +522,21 @@
defaultHostConfiguration = getHostConfiguration();
}
- HostConfiguration methodConfiguration = new HostConfiguration(hostConfiguration);
+ HostConfiguration methodConfiguration
+ = new HostConfiguration(hostConfiguration);
- if ( hostConfiguration != defaultHostConfiguration ) {
+ if (hostConfiguration != defaultHostConfiguration) {
// we may need to apply some defaults
- if ( !methodConfiguration.isHostSet() ) {
+ if (!methodConfiguration.isHostSet()) {
methodConfiguration.setHost(
defaultHostConfiguration.getHost(),
defaultHostConfiguration.getPort(),
defaultHostConfiguration.getProtocol()
);
}
- if ( !methodConfiguration.isProxySet() && defaultHostConfiguration.isProxySet() ) {
+ if (!methodConfiguration.isProxySet()
+ && defaultHostConfiguration.isProxySet()) {
+
methodConfiguration.setProxy(
defaultHostConfiguration.getProxyHost(),
defaultHostConfiguration.getProxyPort()
Index: httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java,v
retrieving revision 1.37
diff -u -r1.37 HttpConnection.java
--- httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java 27 Jan 2003 15:25:45 -0000 1.37
+++ httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java 27 Jan 2003 22:36:47 -0000
@@ -77,8 +77,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
-
/**
* An abstraction of an HTTP {@link InputStream} and {@link OutputStream}
* pair, together with the relevant attributes.
@@ -103,7 +101,9 @@
* @author Sean C. Sullivan
* @author Ortwin Glück
* @author Jeff Dever
- * @version $Revision: 1.37 $ $Date: 2003/01/27 15:25:45 $
+ * @author Mike Bowler
+ *
+ * @version $Revision: 1.37 $ $Date: 2003/01/27 15:25:45 $
*/
public class HttpConnection {
// ----------------------------------------------------------- Constructors
@@ -153,7 +153,11 @@
* @param host the host I should connect to
* @param port the port I should connect to
*/
- public HttpConnection(String proxyHost, int proxyPort, String host, int port) {
+ public HttpConnection(
+ String proxyHost,
+ int proxyPort,
+ String host,
+ int port) {
this(proxyHost, proxyPort, host, port, false);
}
@@ -171,15 +175,18 @@
* @see #HttpConnection(String, int, String, int, Protocol)
*
*/
- public HttpConnection(String proxyHost, int proxyPort, String host,
- int port, boolean secure) {
- this(
- proxyHost,
- proxyPort,
- host,
- port,
- Protocol.getProtocol( secure ? "https" : "http" )
- );
+ public HttpConnection(
+ String proxyHost,
+ int proxyPort,
+ String host,
+ int port,
+ boolean secure) {
+ this(
+ proxyHost,
+ proxyPort,
+ host,
+ port,
+ Protocol.getProtocol(secure ? "https" : "http"));
}
/**
@@ -187,45 +194,59 @@
*
* @param hostConfiguration the host/proxy/protocol to use
*/
- public HttpConnection( HostConfiguration hostConfiguration ) {
+ public HttpConnection(HostConfiguration hostConfiguration) {
this(
hostConfiguration.getProxyHost(),
hostConfiguration.getProxyPort(),
hostConfiguration.getHost(),
hostConfiguration.getPort(),
- hostConfiguration.getProtocol()
- );
+ hostConfiguration.getProtocol());
}
+ /**
+ * Create an instance
+ *
+ * @param proxyHost the host I should proxy via
+ * @param proxyPort the port I should proxy via
+ * @param host the host I should connect to. Parameter value must be non-null.
+ * @param port the port I should connect to
+ * @param protocol The protocol to use.
+ */
public HttpConnection(
- String proxyHost,
- int proxyPort,
+ String proxyHost,
+ int proxyPort,
String host,
- int port,
- Protocol protocol
- ) {
+ int port,
+ Protocol protocol) {
- if( log.isDebugEnabled() ){
- log.debug(
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(
"HttpConnectionManager.getConnection: creating "
- + " connection for " + host + ":" + port + " via " + proxyHost
- + ":" + proxyPort + " using protocol: " + protocol
- );
+ + " connection for "
+ + host
+ + ":"
+ + port
+ + " via "
+ + proxyHost
+ + ":"
+ + proxyPort
+ + " using protocol: "
+ + protocol);
}
-
- if ( host == null ) {
+
+ if (host == null) {
throw new IllegalArgumentException("host parameter is null");
- }
- if ( protocol == null ) {
- throw new IllegalArgumentException( "protocol is null" );
}
-
+ if (protocol == null) {
+ throw new IllegalArgumentException("protocol is null");
+ }
+
_proxyHost = proxyHost;
_proxyPort = proxyPort;
_host = host;
- _port = protocol.resolvePort( port );
+ _port = protocol.resolvePort(port);
_protocol = protocol;
-
+
}
// ------------------------------------------ Attribute Setters and Getters
@@ -296,8 +317,8 @@
* @throws IllegalStateException if I am already connected
*/
public void setProxyHost(String host) throws IllegalStateException {
- assertNotOpen();
- _proxyHost = host;
+ assertNotOpen();
+ _proxyHost = host;
}
/**
@@ -316,8 +337,8 @@
* @throws IllegalStateException if I am already connected
*/
public void setProxyPort(int port) throws IllegalStateException {
- assertNotOpen();
- _proxyPort = port;
+ assertNotOpen();
+ _proxyPort = port;
}
/**
@@ -351,27 +372,26 @@
*/
public void setSecure(boolean secure) throws IllegalStateException {
assertNotOpen();
- _protocol = (
- secure
- ? Protocol.getProtocol( "https" )
- : Protocol.getProtocol( "http" )
- );
+ _protocol =
+ (secure
+ ? Protocol.getProtocol("https")
+ : Protocol.getProtocol("http"));
}
/**
* Sets the protocol used by this connection.
*
- * @param protocol
+ * @param protocol The new protocol.
*/
- public void setProtocol( Protocol protocol ) {
+ public void setProtocol(Protocol protocol) {
assertNotOpen();
-
- if ( protocol == null ) {
- throw new IllegalArgumentException( "protocol is null" );
+
+ if (protocol == null) {
+ throw new IllegalArgumentException("protocol is null");
}
-
+
_protocol = protocol;
-
+
}
/**
@@ -441,10 +461,10 @@
* @throws IllegalStateException if I am not connected
*/
public void setSoTimeout(int timeout)
- throws SocketException, IllegalStateException {
- log.debug("HttpConnection.setSoTimeout("+ timeout +")");
- _so_timeout = timeout;
- if(_socket != null){
+ throws SocketException, IllegalStateException {
+ LOG.debug("HttpConnection.setSoTimeout(" + timeout + ")");
+ soTimeout = timeout;
+ if (_socket != null) {
_socket.setSoTimeout(timeout);
}
}
@@ -456,7 +476,7 @@
* @param timeout The timeout in milliseconds. 0 means timeout is not used.
*/
public void setConnectionTimeout(int timeout) {
- this.connect_timeout = timeout;
+ this.connectTimeout = timeout;
}
/**
@@ -467,38 +487,40 @@
* @throws IOException when there are errors opening the connection
*/
public void open() throws IOException {
- log.trace("enter HttpConnection.open()");
+ LOG.trace("enter HttpConnection.open()");
assertNotOpen(); // ??? is this worth doing?
try {
if (null == _socket) {
-
+
final String host = (null == _proxyHost) ? _host : _proxyHost;
final int port = (null == _proxyHost) ? _port : _proxyPort;
-
- _usingSecureSocket = isSecure() && !isProxied();
-
- final ProtocolSocketFactory socketFactory = (
- isSecure() && !isProxied()
- ? _protocol.getSocketFactory()
- : new DefaultProtocolSocketFactory()
- );
-
- if (connect_timeout == 0) {
- _socket = socketFactory.createSocket(host,port);
+
+ _usingSecureSocket = isSecure() && !isProxied();
+
+ final ProtocolSocketFactory socketFactory =
+ (isSecure()
+ && !isProxied()
+ ? _protocol.getSocketFactory()
+ : new DefaultProtocolSocketFactory());
+
+ if (connectTimeout == 0) {
+ _socket = socketFactory.createSocket(host, port);
} else {
SocketTask task = new SocketTask() {
public void doit() throws IOException {
- s = socketFactory.createSocket(host,port);
+ setSocket(socketFactory.createSocket(host, port));
}
};
- TimeoutController.execute(task, connect_timeout);
- _socket = task.s;
- if (task.exception != null) throw task.exception;
+ TimeoutController.execute(task, connectTimeout);
+ _socket = task.getSocket();
+ if (task.exception != null) {
+ throw task.exception;
+ }
}
-
+
}
-
+
/*
"Nagling has been broadly implemented across networks,
including the Internet, and is generally performed by default
@@ -506,9 +528,9 @@
highly interactive environments, such as some client/server
situations. In such cases, nagling may be turned off through
use of the TCP_NODELAY sockets option." */
-
- _socket.setTcpNoDelay(_so_nodelay);
- _socket.setSoTimeout(_so_timeout);
+
+ _socket.setTcpNoDelay(soNodelay);
+ _socket.setSoTimeout(soTimeout);
_input = _socket.getInputStream();
_output = _socket.getOutputStream();
_open = true;
@@ -518,49 +540,59 @@
closeSocketAndStreams();
throw e;
} catch (TimeoutController.TimeoutException e) {
- if (log.isWarnEnabled()) {
- log.warn("The host "+ _host +":"+ _port +" (or proxy "+
- _proxyHost +":"+ _proxyPort +") did not accept the connection "+
- "within timeout of "+ connect_timeout +" milliseconds");
+ if (LOG.isWarnEnabled()) {
+ LOG.warn(
+ "The host "
+ + _host
+ + ":"
+ + _port
+ + " (or proxy "
+ + _proxyHost
+ + ":"
+ + _proxyPort
+ + ") did not accept the connection "
+ + "within timeout of "
+ + connectTimeout
+ + " milliseconds");
}
throw new ConnectionTimeoutException();
}
}
/**
- * Calling this method indicates that the proxy has successfully created
- * the tunnel to the host. The socket will be switched to the secure socket.
- * Subsequent communication is done via the secure socket. The method can only
- * be called once on a proxied secure connection.
+ * Calling this method indicates that the proxy has successfully created the
+ * tunnel to the host. The socket will be switched to the secure socket.
+ * Subsequent communication is done via the secure socket. The method can
+ * only be called once on a proxied secure connection.
*
* @throws IllegalStateException if connection is not secure and proxied or
* if the socket is already secure.
* @throws IOException if an error occured creating the secure socket
*/
- public void tunnelCreated()
- throws IllegalStateException, IOException {
- log.trace("enter HttpConnection.tunnelCreated()");
+ public void tunnelCreated() throws IllegalStateException, IOException {
+ LOG.trace("enter HttpConnection.tunnelCreated()");
if (!isSecure() || !isProxied()) {
- throw new IllegalStateException("Connection must be secure and proxied to use this feature");
+ throw new IllegalStateException(
+ "Connection must be secure "
+ + "and proxied to use this feature");
}
-
+
if (_usingSecureSocket) {
throw new IllegalStateException("Already using a secure socket");
}
- SecureProtocolSocketFactory socketFactory = (SecureProtocolSocketFactory)
- _protocol.getSocketFactory();
+ SecureProtocolSocketFactory socketFactory =
+ (SecureProtocolSocketFactory) _protocol.getSocketFactory();
_socket = socketFactory.createSocket(_socket, _host, _port, true);
_input = _socket.getInputStream();
_output = _socket.getOutputStream();
_usingSecureSocket = true;
_tunnelEstablished = true;
- log.debug("Secure tunnel created");
+ LOG.debug("Secure tunnel created");
}
-
/**
* Indicates if the connection is completely transparent from end to end.
*
@@ -580,8 +612,8 @@
* @return a stream to write the request to
*/
public OutputStream getRequestOutputStream()
- throws IOException, IllegalStateException {
- log.trace("enter HttpConnection.getRequestOutputStream()");
+ throws IOException, IllegalStateException {
+ LOG.trace("enter HttpConnection.getRequestOutputStream()");
assertOpen();
return _output;
}
@@ -599,7 +631,7 @@
*/
public OutputStream getRequestOutputStream(boolean useChunking)
throws IOException, IllegalStateException {
- log.trace("enter HttpConnection.getRequestOutputStream(boolean)");
+ LOG.trace("enter HttpConnection.getRequestOutputStream(boolean)");
assertOpen();
if (useChunking) {
@@ -625,14 +657,20 @@
* @deprecated Use getResponseInputStream() instead.
*/
public InputStream getResponseInputStream(HttpMethod method)
- throws IOException, IllegalStateException {
- log.trace("enter HttpConnection.getResponseInputStream(HttpMethod)");
+ throws IOException, IllegalStateException {
+ LOG.trace("enter HttpConnection.getResponseInputStream(HttpMethod)");
return getResponseInputStream();
}
+ /**
+ * Return the response input stream
+ * @return InputStream The response input stream.
+ * @throws IOException If an IO problem occurs
+ * @throws IllegalStateException If the connection isn't open.
+ */
public InputStream getResponseInputStream()
- throws IOException, IllegalStateException {
- log.trace("enter HttpConnection.getResponseInputStream()");
+ throws IOException, IllegalStateException {
+ LOG.trace("enter HttpConnection.getResponseInputStream()");
assertOpen();
return _input;
}
@@ -647,12 +685,11 @@
* @see #write(byte[],int,int)
*/
public void write(byte[] data)
- throws IOException, IllegalStateException, HttpRecoverableException {
- log.trace("enter HttpConnection.write(byte[])");
+ throws IOException, IllegalStateException, HttpRecoverableException {
+ LOG.trace("enter HttpConnection.write(byte[])");
this.write(data, 0, data.length);
}
-
/**
* Write length bytes in data starting at
* offset to my output stream.
@@ -670,38 +707,42 @@
* @throws IOException if an I/O problem occurs
*/
public void write(byte[] data, int offset, int length)
- throws IOException, IllegalStateException, HttpRecoverableException {
- log.trace("enter HttpConnection.write(byte[], int, int)");
+ throws IOException, IllegalStateException, HttpRecoverableException {
+ LOG.trace("enter HttpConnection.write(byte[], int, int)");
- if (offset+length > data.length){
- throw new HttpRecoverableException("Unable to write:" +
- " offset=" + offset +
- " length=" + length +
- " data.length=" + data.length);
- }else if (data.length <= 0){
- throw new HttpRecoverableException("Unable to write:" +
- " data.length=" + data.length);
+ if (offset + length > data.length) {
+ throw new HttpRecoverableException(
+ "Unable to write:"
+ + " offset="
+ + offset
+ + " length="
+ + length
+ + " data.length="
+ + data.length);
+ } else if (data.length <= 0) {
+ throw new HttpRecoverableException(
+ "Unable to write:" + " data.length=" + data.length);
}
assertOpen();
- if(wireLog.isDebugEnabled()) {
- String data_str = new String(data, offset, length, "ISO-8859-1");
- wireLog.debug(">> \"" + data_str + "\" [\\r\\n]" );
+ if (WIRE_LOG.isDebugEnabled()) {
+ String dataString = new String(data, offset, length, "ISO-8859-1");
+ WIRE_LOG.debug(">> \"" + dataString + "\" [\\r\\n]");
}
try {
_output.write(data, offset, length);
- } catch(SocketException se){
- log.debug("HttpConnection: Socket exception while writing data", se);
+ } catch (SocketException se) {
+ LOG.debug(
+ "HttpConnection: Socket exception while writing data",
+ se);
throw new HttpRecoverableException(se.toString());
- } catch(IOException ioe) {
- log.debug("HttpConnection: Exception while writing data", ioe);
+ } catch (IOException ioe) {
+ LOG.debug("HttpConnection: Exception while writing data", ioe);
throw ioe;
}
}
-
-
/**
* Write the specified bytes, followed by "\r\n".getBytes() to my
* output stream.
@@ -712,22 +753,22 @@
* @throws IOException if an I/O problem occurs
*/
public void writeLine(byte[] data)
- throws IOException, IllegalStateException, HttpRecoverableException {
- log.trace("enter HttpConnection.writeLine(byte[])");
+ throws IOException, IllegalStateException, HttpRecoverableException {
+ LOG.trace("enter HttpConnection.writeLine(byte[])");
assertOpen();
- if(wireLog.isDebugEnabled() && (data.length > 0)) {
- String data_str = HttpConstants.getContentString(data);
- wireLog.debug(">> \"" + data_str.trim() + "\" [\\r\\n]" );
+ if (WIRE_LOG.isDebugEnabled() && (data.length > 0)) {
+ String dataString = HttpConstants.getContentString(data);
+ WIRE_LOG.debug(">> \"" + dataString.trim() + "\" [\\r\\n]");
}
- try{
+ try {
_output.write(data);
writeLine();
- } catch(SocketException se){
- log.info("SocketException while writing data to output", se);
+ } catch (SocketException se) {
+ LOG.info("SocketException while writing data to output", se);
throw new HttpRecoverableException(se.toString());
- } catch(IOException ioe){
- log.info("IOException while writing data to output", ioe);
+ } catch (IOException ioe) {
+ LOG.info("IOException while writing data to output", ioe);
throw ioe;
}
}
@@ -741,22 +782,21 @@
* @throws IOException if an I/O problem occurs
*/
public void writeLine()
- throws IOException, IllegalStateException, HttpRecoverableException {
- log.trace("enter HttpConnection.writeLine()");
+ throws IOException, IllegalStateException, HttpRecoverableException {
+ LOG.trace("enter HttpConnection.writeLine()");
- wireLog.debug(">> [\\r\\n]");
- try{
+ WIRE_LOG.debug(">> [\\r\\n]");
+ try {
_output.write(CRLF);
- } catch(SocketException se){
- log.warn("HttpConnection: Socket exception while writing data", se);
+ } catch (SocketException se) {
+ LOG.warn("HttpConnection: Socket exception while writing data", se);
throw new HttpRecoverableException(se.toString());
- } catch(IOException ioe){
- log.warn("HttpConnection: IO exception while writing data", ioe);
+ } catch (IOException ioe) {
+ LOG.warn("HttpConnection: IO exception while writing data", ioe);
throw ioe;
}
}
-
/**
* Write the specified String (as bytes) to my output stream.
*
@@ -767,8 +807,8 @@
* @throws IOException if an I/O problem occurs
*/
public void print(String data)
- throws IOException, IllegalStateException, HttpRecoverableException {
- log.trace("enter HttpConnection.print(String)");
+ throws IOException, IllegalStateException, HttpRecoverableException {
+ LOG.trace("enter HttpConnection.print(String)");
write(HttpConstants.getBytes(data));
}
@@ -783,8 +823,8 @@
* @throws IOException if an I/O problem occurs
*/
public void printLine(String data)
- throws IOException, IllegalStateException, HttpRecoverableException {
- log.trace("enter HttpConnection.printLine(String)");
+ throws IOException, IllegalStateException, HttpRecoverableException {
+ LOG.trace("enter HttpConnection.printLine(String)");
writeLine(HttpConstants.getBytes(data));
}
@@ -797,8 +837,8 @@
* @throws IOException if an I/O problem occurs
*/
public void printLine()
- throws IOException, IllegalStateException, HttpRecoverableException {
- log.trace("enter HttpConnection.printLine()");
+ throws IOException, IllegalStateException, HttpRecoverableException {
+ LOG.trace("enter HttpConnection.printLine()");
writeLine();
}
@@ -809,31 +849,30 @@
* @throws IOException if an I/O problem occurs
* @return a line from the response
*/
- public String readLine()
- throws IOException, IllegalStateException {
- log.trace("enter HttpConnection.readLine()");
+ public String readLine() throws IOException, IllegalStateException {
+ LOG.trace("enter HttpConnection.readLine()");
assertOpen();
StringBuffer buf = new StringBuffer();
- for(;;) {
+ while (true) {
int ch = _input.read();
- if(ch < 0) {
- if(buf.length() == 0) {
+ if (ch < 0) {
+ if (buf.length() == 0) {
return null;
} else {
break;
}
} else if (ch == '\r') {
-// LOG.debug("HttpConnection.readLine() found \\r, continuing");
+ // LOG.debug("HttpConnection.readLine() found \\r, continuing");
continue;
} else if (ch == '\n') {
-// LOG.debug("HttpConnection.readLine() found \\n, breaking");
+ // LOG.debug("HttpConnection.readLine() found \\n, breaking");
break;
}
- buf.append((char)ch);
+ buf.append((char) ch);
}
- if(wireLog.isDebugEnabled() && buf.length() > 0) {
- wireLog.debug("<< \"" + buf.toString() + "\" [\\r\\n]");
+ if (WIRE_LOG.isDebugEnabled() && buf.length() > 0) {
+ WIRE_LOG.debug("<< \"" + buf.toString() + "\" [\\r\\n]");
}
return (buf.toString());
}
@@ -842,19 +881,19 @@
* Shutdown my {@link Socket}'s output, via {@link Socket#shutdownOutput}.
*/
public void shutdownOutput() {
- log.trace("enter HttpConnection.shutdownOutput()");
+ LOG.trace("enter HttpConnection.shutdownOutput()");
try {
// Socket.shutdownOutput is a JDK 1.3
// method. We'll use reflection in case
// we're running in an older VM
Class[] paramsClasses = new Class[0];
- Method shutdownOutput = _socket.getClass().getMethod
- ("shutdownOutput", paramsClasses);
+ Method shutdownOutput =
+ _socket.getClass().getMethod("shutdownOutput", paramsClasses);
Object[] params = new Object[0];
shutdownOutput.invoke(_socket, params);
} catch (Exception ex) {
- log.debug("Unexpected Exception caught", ex);
+ LOG.debug("Unexpected Exception caught", ex);
// Ignore, and hope everything goes right
}
// close output stream?
@@ -864,7 +903,7 @@
* Close my socket and streams.
*/
public void close() {
- log.trace("enter HttpConnection.close()");
+ LOG.trace("enter HttpConnection.close()");
closeSocketAndStreams();
}
@@ -883,22 +922,24 @@
public void setHttpConnectionManager(HttpConnectionManager httpConnectionManager) {
this.httpConnectionManager = httpConnectionManager;
}
-
+
+ /**
+ * Release the connection.
+ */
public void releaseConnection() {
- log.trace("enter HttpConnection.releaseConnection()");
- if ( httpConnectionManager != null ) {
- httpConnectionManager.releaseConnection( this );
- }
+ LOG.trace("enter HttpConnection.releaseConnection()");
+ if (httpConnectionManager != null) {
+ httpConnectionManager.releaseConnection(this);
+ }
}
// ------------------------------------------------------ Protected Methods
-
/**
* Close everything out.
*/
protected void closeSocketAndStreams() {
- log.trace("enter HttpConnection.closeSockedAndStreams()");
+ LOG.trace("enter HttpConnection.closeSockedAndStreams()");
// no longer care about previous responses...
_lastResponseInput = null;
@@ -906,8 +947,8 @@
if (null != _input) {
try {
_input.close();
- } catch(Exception ex) {
- log.debug("Exception caught when closing input", ex);
+ } catch (Exception ex) {
+ LOG.debug("Exception caught when closing input", ex);
// ignored
}
_input = null;
@@ -916,8 +957,8 @@
if (null != _output) {
try {
_output.close();
- } catch(Exception ex) {
- log.debug("Exception caught when closing output", ex);
+ } catch (Exception ex) {
+ LOG.debug("Exception caught when closing output", ex);
// ignored
}
_output = null;
@@ -926,8 +967,8 @@
if (null != _socket) {
try {
_socket.close();
- } catch(Exception ex) {
- log.debug("Exception caught when closing socket", ex);
+ } catch (Exception ex) {
+ LOG.debug("Exception caught when closing socket", ex);
// ignored
}
_socket = null;
@@ -942,9 +983,8 @@
*
* @throws IllegalStateException if connected
*/
- protected void assertNotOpen()
- throws IllegalStateException {
- if(_open) {
+ protected void assertNotOpen() throws IllegalStateException {
+ if (_open) {
throw new IllegalStateException("Connection is open");
}
}
@@ -954,9 +994,8 @@
*
* @throws IllegalStateException if not connected
*/
- protected void assertOpen()
- throws IllegalStateException {
- if(!_open) {
+ protected void assertOpen() throws IllegalStateException {
+ if (!_open) {
throw new IllegalStateException("Connection is not open");
}
}
@@ -966,32 +1005,56 @@
* Signals that a timeout occured while opening the socket.
*/
public class ConnectionTimeoutException extends IOException {
+ /** Create an instance */
public ConnectionTimeoutException() {
}
}
- // -- Helper
+ /**
+ * Helper class for wrapping socket based tasks.
+ */
private abstract class SocketTask implements Runnable {
- public Socket s;
- public IOException exception;
-
+ /** The socket */
+ private Socket socket;
+ /** The exception */
+ private IOException exception;
+
+ /**
+ * Set the socket.
+ * @param newSocket The new socket.
+ */
+ protected void setSocket(final Socket newSocket) {
+ socket = newSocket;
+ }
+ /**
+ * Return the socket.
+ * @return Socket The socket.
+ */
+ protected Socket getSocket() {
+ return socket;
+ }
+ /**
+ * Perform the logic.
+ * @throws IOException If an IO problem occurs
+ */
public abstract void doit() throws IOException;
+ /** Execute the logic in this object and keep track of any exceptions. */
public void run() {
try {
doit();
- } catch(IOException e) {
+ } catch (IOException e) {
exception = e;
}
}
}
-
+
// ------------------------------------------------------------- Attributes
/** Log object for this class. */
- private static final Log log = LogFactory.getLog(HttpConnection.class);
+ private static final Log LOG = LogFactory.getLog(HttpConnection.class);
/** Log for any wire messages. */
- private static final Log wireLog = LogFactory.getLog("httpclient.wire");
+ private static final Log WIRE_LOG = LogFactory.getLog("httpclient.wire");
/** My host. */
private String _host = null;
/** My port. */
@@ -1015,15 +1078,15 @@
/** "\r\n", as bytes. */
private static final byte[] CRLF = HttpConstants.getBytes("\r\n");
/** SO_TIMEOUT socket value */
- private int _so_timeout = 0;
+ private int soTimeout = 0;
/** TCP_NODELAY socket value */
- private boolean _so_nodelay = true;
+ private boolean soNodelay = true;
/** Whether or not the _socket is a secure one. Note the difference to _ssl */
private boolean _usingSecureSocket = false;
/** Whether I am tunneling a proxy or not */
private boolean _tunnelEstablished = false;
/** Timeout until connection established (Socket created). 0 means no timeout. */
- private int connect_timeout = 0;
+ private int connectTimeout = 0;
/** the connection manager that created this connection or null */
private HttpConnectionManager httpConnectionManager;
}
Index: httpclient/src/java/org/apache/commons/httpclient/HttpConnectionManager.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnectionManager.java,v
retrieving revision 1.14
diff -u -r1.14 HttpConnectionManager.java
--- httpclient/src/java/org/apache/commons/httpclient/HttpConnectionManager.java 23 Jan 2003 22:47:46 -0000 1.14
+++ httpclient/src/java/org/apache/commons/httpclient/HttpConnectionManager.java 27 Jan 2003 22:36:48 -0000
@@ -68,6 +68,9 @@
*
* @see org.apache.commons.httpclient.HttpConnection
* @see org.apache.commons.httpclient.HttpClient#HttpClient(HttpConnectionManager)
+ *
+ * @author Unascribed
+ * @author Mike Bowler
*
* @since 2.0
*/
@@ -87,7 +90,7 @@
*
* @see HttpConnection#setHttpConnectionManager(HttpConnectionManager)
*/
- public HttpConnection getConnection(HostConfiguration hostConfiguration);
+ HttpConnection getConnection(HostConfiguration hostConfiguration);
/**
* Gets an HttpConnection for a given host configuration. If a connection is
@@ -104,12 +107,12 @@
*
* @return an HttpConnection for the given configuraiton
*
- * @exception org.apache.commons.httpclient.HttpException if no connection
- * becomes available before the timeout expires
+ * @throws HttpException if no connection becomes available before the
+ * timeout expires
*
* @see HttpConnection#setHttpConnectionManager(HttpConnectionManager)
*/
- public HttpConnection getConnection(HostConfiguration hostConfiguration, long timeout)
+ HttpConnection getConnection(HostConfiguration hostConfiguration, long timeout)
throws HttpException;
/**
@@ -117,6 +120,5 @@
*
* @param conn - The HttpConnection to make available.
*/
- public void releaseConnection(HttpConnection conn);
-
+ void releaseConnection(HttpConnection conn);
}
Index: httpclient/src/java/org/apache/commons/httpclient/HttpConstants.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConstants.java,v
retrieving revision 1.3
diff -u -r1.3 HttpConstants.java
--- httpclient/src/java/org/apache/commons/httpclient/HttpConstants.java 23 Jan 2003 22:47:46 -0000 1.3
+++ httpclient/src/java/org/apache/commons/httpclient/HttpConstants.java 27 Jan 2003 22:36:47 -0000
@@ -72,6 +72,7 @@
* DOCUMENT ME!
*
* @author Oleg Kalnichevski
+ * @author Mike Bowler
*/
public class HttpConstants {
@@ -82,16 +83,17 @@
protected static final String DEFAULT_CONTENT_CHARSET = "ISO-8859-1";
/** Log object for this class. */
- private static final Log log = LogFactory.getLog(HttpConstants.class);
+ private static final Log LOG = LogFactory.getLog(HttpConstants.class);
/**
* Converts the specified string to a byte array of HTTP element characters.
- * This method is to be used when encoding content of HTTP elements (such as request headers)
+ * This method is to be used when encoding content of HTTP elements (such as
+ * request headers)
*
* @param data the string to be encoded
+ * @return The resulting byte array.
*/
public static byte[] getBytes(final String data) {
-
if (data == null) {
throw new IllegalArgumentException("Parameter may not be null");
}
@@ -100,8 +102,10 @@
return data.getBytes(HTTP_ELEMENT_CHARSET);
} catch (UnsupportedEncodingException e) {
- if (log.isWarnEnabled()) {
- log.warn("Unsupported encoding: " + HTTP_ELEMENT_CHARSET + ". System default encoding used");
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Unsupported encoding: "
+ + HTTP_ELEMENT_CHARSET
+ + ". System default encoding used");
}
return data.getBytes();
@@ -109,10 +113,12 @@
}
/**
- * Converts the byte array of HTTP element characters to a string
- * This method is to be used when decoding content of HTTP elements (such as response headers)
+ * Converts the byte array of HTTP element characters to a string This
+ * method is to be used when decoding content of HTTP elements (such as
+ * response headers)
*
* @param data the byte array to be encoded
+ * @return The resulting string.
*/
public static String getString(final byte[] data) {
@@ -124,8 +130,10 @@
return new String(data, HTTP_ELEMENT_CHARSET);
} catch (UnsupportedEncodingException e) {
- if (log.isWarnEnabled()) {
- log.warn("Unsupported encoding: " + HTTP_ELEMENT_CHARSET + ". System default encoding used");
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Unsupported encoding: "
+ + HTTP_ELEMENT_CHARSET
+ + ". System default encoding used");
}
return new String(data);
@@ -140,6 +148,7 @@
*
* @param data the string to be encoded
* @param charset the desired character encoding
+ * @return The resulting byte array.
*/
public static byte[] getContentBytes(final String data, String charset) {
@@ -155,16 +164,20 @@
return data.getBytes(charset);
} catch (UnsupportedEncodingException e) {
- if (log.isWarnEnabled()) {
- log.warn("Unsupported encoding: " + charset + ". HTTP default encoding used");
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Unsupported encoding: "
+ + charset
+ + ". HTTP default encoding used");
}
try {
return data.getBytes(DEFAULT_CONTENT_CHARSET);
} catch (UnsupportedEncodingException e2) {
- if (log.isWarnEnabled()) {
- log.warn("Unsupported encoding: " + DEFAULT_CONTENT_CHARSET + ". System encoding used");
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Unsupported encoding: "
+ + DEFAULT_CONTENT_CHARSET
+ + ". System encoding used");
}
return data.getBytes();
@@ -173,13 +186,14 @@
}
/**
- * Converts the byte array of HTTP content characters to a string
- * This method is to be used when decoding content of HTTP request/response
- * If the specified charset is not supported, default HTTP content encoding
+ * Converts the byte array of HTTP content characters to a string This
+ * method is to be used when decoding content of HTTP request/response If
+ * the specified charset is not supported, default HTTP content encoding
* (ISO-8859-1) is applied
*
* @param data the byte array to be encoded
* @param charset the desired character encoding
+ * @return The result of the conversion.
*/
public static String getContentString(final byte[] data, String charset) {
@@ -195,16 +209,20 @@
return new String(data, charset);
} catch (UnsupportedEncodingException e) {
- if (log.isWarnEnabled()) {
- log.warn("Unsupported encoding: " + DEFAULT_CONTENT_CHARSET + ". Default HTTP encoding used");
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Unsupported encoding: "
+ + DEFAULT_CONTENT_CHARSET
+ + ". Default HTTP encoding used");
}
try {
return new String(data, DEFAULT_CONTENT_CHARSET);
} catch (UnsupportedEncodingException e2) {
- if (log.isWarnEnabled()) {
- log.warn("Unsupported encoding: " + DEFAULT_CONTENT_CHARSET + ". System encoding used");
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Unsupported encoding: "
+ + DEFAULT_CONTENT_CHARSET
+ + ". System encoding used");
}
return new String(data);
@@ -213,22 +231,24 @@
}
/**
- * Converts the specified string to a byte array of HTTP content charachetrs
- * using default HTTP content encoding (ISO-8859-1)
- * This method is to be used when encoding content of HTTP request/response
+ * Converts the specified string to a byte array of HTTP content characters
+ * using default HTTP content encoding (ISO-8859-1) This method is to be
+ * used when encoding content of HTTP request/response
*
* @param data the string to be encoded
+ * @return The byte array as above.
*/
public static byte[] getContentBytes(final String data) {
return getContentBytes(data, null);
}
/**
- * Converts the byte array of HTTP content characters to a string using default
- * HTTP content encoding (ISO-8859-1)
- * This method is to be used when decoding content of HTTP request/response
+ * Converts the byte array of HTTP content characters to a string using
+ * default HTTP content encoding (ISO-8859-1) This method is to be used when
+ * decoding content of HTTP request/response
*
* @param data the byte array to be encoded
+ * @return The string representation of the byte array.
*/
public static String getContentString(final byte[] data) {
return getContentString(data, null);
@@ -238,6 +258,7 @@
* Converts the specified string to byte array of ASCII characters.
*
* @param data the string to be encoded
+ * @return The string as a byte array.
*/
public static byte[] getAsciiBytes(final String data) {
@@ -253,10 +274,12 @@
}
/**
- * Converts the byte array of ASCII characters to a string
- * This method is to be used when decoding content of HTTP elements (such as response headers)
+ * Converts the byte array of ASCII characters to a string. This method is
+ * to be used when decoding content of HTTP elements (such as response
+ * headers)
*
* @param data the byte array to be encoded
+ * @return The string representation of the byte array
*/
public static String getAsciiString(final byte[] data) {
Index: httpclient/src/java/org/apache/commons/httpclient/HttpException.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpException.java,v
retrieving revision 1.12
diff -u -r1.12 HttpException.java
--- httpclient/src/java/org/apache/commons/httpclient/HttpException.java 23 Jan 2003 22:47:46 -0000 1.12
+++ httpclient/src/java/org/apache/commons/httpclient/HttpException.java 27 Jan 2003 22:36:47 -0000
@@ -81,6 +81,7 @@
* - * A request to be applied to an {@link HttpConnection}, - * and a container for the associated response. + * A request to be applied to an {@link HttpConnection}, and a container for the + * associated response. *
* @author Remy Maucherat * @author Rod Waldhoff * @author Jeff Dever + * @author Mike Bowler * * @version $Revision: 1.22 $ $Date: 2003/01/23 22:47:46 $ * @since 1.0 @@ -86,20 +87,20 @@ * for example "GET" or "POST". * @return the name of this method */ - public String getName(); + String getName(); /** * Gets the host configuration for this method. * * @return the HostConfiguration ornull if none is set
*/
- public HostConfiguration getHostConfiguration();
+ HostConfiguration getHostConfiguration();
/**
* Set the path part of my request.
* @param path the path to request
*/
- public void setPath(String path);
+ void setPath(String path);
/**
* Get the path part of my request.
@@ -111,7 +112,7 @@
* case, HttpClient returns the 301 or 302 status code).
* @return the path to request
*/
- public String getPath();
+ String getPath();
/**
* Gets the URI for this method. The URI will be absolute if the host
@@ -121,18 +122,20 @@
*
* @throws URIException if a URI cannot be constructed
*/
- public URI getURI() throws URIException;
+ URI getURI() throws URIException;
/**
- * Turns strict mode on or off. In strict mode (the default)
- * we following the letter of RFC 2616, the Http 1.1 specification.
- * If strict mode is turned off we attempt to violate the specification
- * in the same way that most Http user agent's do (and many HTTP servers
- * expect.
+ * Turns strict mode on or off. In strict mode (the default) we + * following the letter of RFC 2616, the Http 1.1 specification. If strict + * mode is turned off we attempt to violate the specification in the same + * way that most Http user agent's do (and many HTTP servers expect.
* - * NOTE: StrictMode is currently experimental and its functionlaity may change in the future. + *NOTE: StrictMode is currently experimental and its functionaity may + * change in the future.
+ * + * @param strictMode True to enable strict mode. */ - public void setStrictMode(boolean strictMode); + void setStrictMode(boolean strictMode); /** * Returns the value of strictMode. @@ -141,7 +144,7 @@ * * @return true if strict mode is enabled. */ - public boolean isStrictMode(); + boolean isStrictMode(); /** * Set the specified request header, overwriting any @@ -150,7 +153,7 @@ * @param headerName the header's name * @param headerValue the header's value */ - public void setRequestHeader(String headerName, String headerValue); + void setRequestHeader(String headerName, String headerValue); /** * Set the specified request header, overwriting any @@ -158,7 +161,7 @@ * Note that header-name matching is case insensitive. * @param header the header */ - public void setRequestHeader(Header header); + void setRequestHeader(Header header); /** * Adds the specified request header, NOT overwriting any @@ -167,7 +170,7 @@ * @param headerName the header's name * @param headerValue the header's value */ - public void addRequestHeader(String headerName, String headerValue); + void addRequestHeader(String headerName, String headerValue); /** * Adds the specified request header, NOT overwriting any @@ -175,7 +178,7 @@ * Note that header-name matching is case insensitive. * @param header the header */ - public void addRequestHeader(Header header); + void addRequestHeader(Header header); /** * Get the request header associated with the given name. @@ -183,118 +186,131 @@ * @param headerName the header name * @return the header */ - public Header getRequestHeader(String headerName); + Header getRequestHeader(String headerName); /** * Remove all request headers associated with the given name. * Note that header-name matching is case insensitive. * @param headerName the header name */ - public void removeRequestHeader(String headerName); + void removeRequestHeader(String headerName); /** * Whether or not I should automatically follow * HTTP redirects (status code 302, etc.) * @return true if I will automatically follow HTTP redirects */ - public boolean getFollowRedirects(); + boolean getFollowRedirects(); /** - * Set whether or not I should automatically follow - * HTTP redirects (status code 302, etc.) + * Set whether or not I should automatically follow HTTP redirects (status + * code 302, etc.) + * @param followRedirects True if I should automatically follow redirects. */ - public void setFollowRedirects(boolean followRedirects); + void setFollowRedirects(boolean followRedirects); /** * Set my query string. * @param queryString the query string */ - public void setQueryString(String queryString); + 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); + void setQueryString(NameValuePair[] params); /** * Get my query string. * @return my query string */ - public String getQueryString(); + String getQueryString(); /** * Return an array of my request headers. + * @return an array of request headers. */ - public Header[] getRequestHeaders(); + Header[] getRequestHeaders(); // ---------------------------------------------------------------- Queries /** * Confirm that I am ready to execute. + * @return True if I am ready to execute. */ - public boolean validate(); + boolean validate(); /** * Return the status code associated with the latest response. + * @return the status code. */ - public int getStatusCode(); + int getStatusCode(); /** - * Return the status text (or "reason phrase") associated with the latest response. + * Return the status text (or "reason phrase") associated with the latest + * response. + * @return The status text. */ - public String getStatusText(); + String getStatusText(); /** * Return an array of my response headers. + * @return An array of all the response headers. */ - public Header[] getResponseHeaders(); + Header[] getResponseHeaders(); /** - * Return the specified response header. - * Note that header-name matching is case insensitive. + * Return the specified response header. Note that header-name matching is + * case insensitive. + * @param headerName The name of the header to be returned. + * @return The specified response header. */ - public Header getResponseHeader(String headerName); + Header getResponseHeader(String headerName); /** * Return an array of my response footers * @return null if no footers are available */ - public Header[] getResponseFooters(); + Header[] getResponseFooters(); /** - * Return the specified response footer. - * Note that footer-name matching is case insensitive. + * Return the specified response footer. Note that footer-name matching is + * case insensitive. + * @param footerName The name of the footer. + * @return The response footer. */ - public Header getResponseFooter(String footerName); + Header getResponseFooter(String footerName); /** - * Return my response body, if any, - * as a byte array. - * Otherwise return null. + * Return my response body, if any, as a byte array. Otherwise return + * null. + * @return The response body. */ - public byte[] getResponseBody(); + byte[] getResponseBody(); /** - * Return my response body, if any, - * as a {@link String}. - * Otherwise return null. + * Return my response body, if any, as a {@link String}. Otherwise return + * null. + * @return response body. */ - public String getResponseBodyAsString(); + String getResponseBodyAsString(); /** - * Return my response body, if any, - * as an {@link InputStream}. - * Otherwise return null. + * Return my response body, if any, as an {@link InputStream}. Otherwise + * return null. + * @return As above. + * @throws IOException If an IO problem occurs. */ - public InputStream getResponseBodyAsStream() throws IOException; + InputStream getResponseBodyAsStream() throws IOException; /** * Return true if I have been {@link #execute executed} * but not recycled. + * @return true if this has been used. */ - public boolean hasBeenUsed(); + boolean hasBeenUsed(); // --------------------------------------------------------- Action Methods @@ -309,34 +325,36 @@ * * @return the integer status code if one was obtained, or -1 */ - public int execute(HttpState state, HttpConnection connection) - throws HttpException, IOException; + int execute(HttpState state, HttpConnection connection) + throws HttpException, IOException; /** * Recycle this method so that it can be used again. * Note that all of my instance variables will be reset * once this method has been called. */ - public void recycle(); + void recycle(); /** * Releases the connection being used by this method. In particular the * connection is used to read the response(if there is one) and will be held * until the response has been read. */ - public void releaseConnection(); + void releaseConnection(); /** * Use this method internally to add footers. + * @param footer The footer to add. * @since 2.0 */ - public void addResponseFooter(Header footer); + void addResponseFooter(Header footer); /** * Return the Status-Line from the response. + * @return The status line * @since 2.0 */ - public StatusLine getStatusLine(); + StatusLine getStatusLine(); /** * Whether or not I should automatically process responses where @@ -345,7 +363,7 @@ * @return true if authentications will be processed automatically * @since 2.0 */ - public boolean getDoAuthentication(); + boolean getDoAuthentication(); /** * Set whether or not I should automatically process responses where @@ -354,6 +372,6 @@ * @param doAuthentication true to process authentications * @since 2.0 */ - public void setDoAuthentication(boolean doAuthentication); + void setDoAuthentication(boolean doAuthentication); } Index: httpclient/src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java,v retrieving revision 1.5 diff -u -r1.5 CookiePolicy.java --- httpclient/src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java 27 Jan 2003 15:25:47 -0000 1.5 +++ httpclient/src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java 27 Jan 2003 22:36:49 -0000 @@ -83,7 +83,7 @@ * COMPATIBILITY, NETSCAPE_DRAFT, RFC2109. * * @author Oleg Kalnichevski - * @author Mike Bowler * * @since 2.0 */ Index: httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java,v retrieving revision 1.8 diff -u -r1.8 CookieSpecBase.java --- httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java 27 Jan 2003 15:25:47 -0000 1.8 +++ httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java 27 Jan 2003 22:36:49 -0000 @@ -91,7 +91,7 @@ * @author John Evans * @author Marc A. Saegesser * @author Oleg Kalnichevski - * @author Mike Bowler * * @since 2.0 */ Index: httpclient/src/java/org/apache/commons/httpclient/cookie/NetscapeDraftSpec.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/NetscapeDraftSpec.java,v retrieving revision 1.6 diff -u -r1.6 NetscapeDraftSpec.java --- httpclient/src/java/org/apache/commons/httpclient/cookie/NetscapeDraftSpec.java 27 Jan 2003 15:25:47 -0000 1.6 +++ httpclient/src/java/org/apache/commons/httpclient/cookie/NetscapeDraftSpec.java 27 Jan 2003 22:36:49 -0000 @@ -84,7 +84,7 @@ * @author John Evans * @author Marc A. Saegesser * @author Oleg Kalnichevski - * @author Mike Bowler * * @since 2.0 */ Index: httpclient/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java,v retrieving revision 1.7 diff -u -r1.7 RFC2109Spec.java --- httpclient/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java 27 Jan 2003 15:57:55 -0000 1.7 +++ httpclient/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java 27 Jan 2003 22:36:49 -0000 @@ -79,7 +79,7 @@ * @author John Evans * @author Marc A. Saegesser * @author Oleg Kalnichevski - * @author Mike Bowler * * @since 2.0 */