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.37
diff -u -r1.37 Authenticator.java
--- httpclient/src/java/org/apache/commons/httpclient/Authenticator.java 23 Jan 2003 22:47:43 -0000 1.37
+++ httpclient/src/java/org/apache/commons/httpclient/Authenticator.java 27 Jan 2003 01:56:46 -0000
@@ -98,6 +98,7 @@
* @author Ortwin Glück
* @author Sean C. Sullivan
* @author Adrian Sutton
+ * @author Authorization header for the given
* Challenge and state to the given method.
*
+ * @param challenge The challenge.
* @param method the {@link HttpMethod request} requiring the ntlm
* @param state a {@link HttpState} object providing
* {@link Credentials}
@@ -343,7 +347,7 @@
private static Header ntlm(String challenge, HttpMethod method,
HttpState state, String responseHeader) throws HttpException {
- log.trace("enter Authenticator.ntlm(String, HttpMethod, HttpState, "
+ LOG.trace("enter Authenticator.ntlm(String, HttpMethod, HttpState, "
+ "String)");
boolean proxy = PROXY_AUTH_RESP.equals(responseHeader);
@@ -353,9 +357,9 @@
if (method.getRequestHeader("Host") != null) {
String host = method.getRequestHeader("Host").getValue();
try {
- credentials = (NTCredentials) (proxy ?
- state.getProxyCredentials(host) :
- state.getCredentials(host));
+ credentials = (NTCredentials) (proxy
+ ? state.getProxyCredentials(host)
+ : state.getCredentials(host));
} catch (ClassCastException e) {
throw new HttpException("NTCredentials required "
+ "for NTLM authentication.");
@@ -363,12 +367,12 @@
}
if (credentials == null) {
- log.info("No credentials for specific host, " +
- "attempting to use default credentials.");
+ LOG.info("No credentials for specific host, "
+ + "attempting to use default credentials.");
try {
- credentials = (NTCredentials) (proxy ?
- state.getProxyCredentials(null) :
- state.getCredentials(null));
+ credentials = (NTCredentials) (proxy
+ ? state.getProxyCredentials(null)
+ : state.getCredentials(null));
} catch (ClassCastException e) {
throw new HttpException(
"NTCredentials required for NTLM authentication.");
@@ -377,8 +381,8 @@
try {
challenge =
- challenge.substring(challenge.toLowerCase().indexOf("ntlm") +
- "ntlm".length()).trim();
+ challenge.substring(challenge.toLowerCase().indexOf("ntlm")
+ + "ntlm".length()).trim();
} catch (IndexOutOfBoundsException e) {
throw new HttpException("Invalid NTLM challenge.");
}
@@ -391,8 +395,8 @@
String response = "NTLM " + ntlm.getResponseFor(challenge,
credentials.getUserName(), credentials.getPassword(),
credentials.getHost(), credentials.getDomain());
- if (log.isDebugEnabled()) {
- log.debug("Replying to challenge with: " + response);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Replying to challenge with: " + response);
}
return new Header(responseHeader, response);
}
@@ -415,31 +419,31 @@
private static Header digest(String realm, HttpMethod method,
HttpState state, String responseHeader) throws HttpException {
- log.trace("enter Authenticator.digest(String, HttpMethod, HttpState, "
+ LOG.trace("enter Authenticator.digest(String, HttpMethod, HttpState, "
+ "String)");
boolean proxy = PROXY_AUTH_RESP.equals(responseHeader);
UsernamePasswordCredentials credentials = null;
try {
- credentials = (UsernamePasswordCredentials) (proxy ?
- state.getProxyCredentials(realm) :
- state.getCredentials(realm));
+ credentials = (UsernamePasswordCredentials) (proxy
+ ? state.getProxyCredentials(realm)
+ : state.getCredentials(realm));
} catch (ClassCastException e) {
throw new HttpException("UsernamePasswordCredentials required for "
+ "Digest authentication.");
}
if (credentials == null) {
- if (log.isInfoEnabled()) {
- log.info("No credentials found for realm \"" + realm + "\", "
+ if (LOG.isInfoEnabled()) {
+ LOG.info("No credentials found for realm \"" + realm + "\", "
+ "attempting to use default credentials.");
}
try {
- credentials = (UsernamePasswordCredentials) (proxy ?
- state.getProxyCredentials(null) :
- state.getCredentials(null));
+ credentials = (UsernamePasswordCredentials) (proxy
+ ? state.getProxyCredentials(null)
+ : state.getCredentials(null));
} catch (ClassCastException e) {
throw new HttpException("UsernamePasswordCredentials required "
+ "for Digest authentication.");
@@ -467,14 +471,14 @@
* UsernamePasswordCredentials}.
*
* @param credentials Credentials to create the digest with
- * @param headers The headers for the current request
+ * @param mapHeaders The headers for the current request
* @return a string containing the authorization header for digest
* @throws HttpException When a recoverable error occurs
*/
private static String digest(UsernamePasswordCredentials credentials,
Map mapHeaders) throws HttpException {
- log.trace("enter Authenticator.digest(UsernamePasswordCredentials, "
+ LOG.trace("enter Authenticator.digest(UsernamePasswordCredentials, "
+ "Map)");
String digest = createDigest(credentials.getUserName(),
@@ -503,7 +507,7 @@
*/
private static Map getHTTPDigestCredentials(HttpMethod method,
boolean proxy) {
- log.trace("enter Authenticator.getHTTPDigestCredentials(HttpMethod, "
+ LOG.trace("enter Authenticator.getHTTPDigestCredentials(HttpMethod, "
+ "boolean)");
//Determine wether to use proxy or www header
@@ -549,10 +553,10 @@
*/
private static Map parseAuthenticateHeader(Header authHeader) {
- log.trace("enter parseAuthenticateHeader(Header)");
+ LOG.trace("enter parseAuthenticateHeader(Header)");
- if (log.isDebugEnabled()) {
- log.debug("Attempting to parse authenticate header: '"
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Attempting to parse authenticate header: '"
+ authHeader + "'");
}
if (authHeader == null || authHeader.getValue() == null) {
@@ -579,8 +583,8 @@
atComma = authValue.indexOf(',', atStart);
// skip any commas in quotes
- while (atComma > atQuote1 && atComma < atQuote2 &&
- atComma > 0) {
+ while (atComma > atQuote1 && atComma < atQuote2
+ && atComma > 0) {
atComma = authValue.indexOf(',', atComma + 1);
}
@@ -589,10 +593,10 @@
atComma = authValueLength;
}
- if (log.isDebugEnabled()) {
- log.debug("atStart =" + atStart + ", atQuote1 =" +
- atQuote1 + ", atQuote2=" + atQuote2 + ", atComma ="
- + atComma);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("atStart =" + atStart + ", atQuote1 ="
+ + atQuote1 + ", atQuote2=" + atQuote2 + ", atComma ="
+ + atComma);
}
try {
@@ -602,24 +606,24 @@
//find the blank and parse out the scheme
atSpace = challenge.indexOf(' ');
- scheme = (atSpace > 0) ?
- challenge.substring(0, atSpace).trim() : challenge;
+ scheme = (atSpace > 0)
+ ? challenge.substring(0, atSpace).trim() : challenge;
//store the challenge keyed on the scheme
challengeMap.put(scheme.toLowerCase(), challenge);
- if (log.isDebugEnabled()) {
- log.debug(scheme.toLowerCase() + "=>" + challenge);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(scheme.toLowerCase() + "=>" + challenge);
}
} catch (StringIndexOutOfBoundsException e) {
- log.warn("Parsing authorization challenge'" + challenge +
- "' failed", e);
+ LOG.warn("Parsing authorization challenge'" + challenge
+ + "' failed", e);
}
} // end of while
} catch (StringIndexOutOfBoundsException e) {
- log.warn("Parsing authorization header value'" + authValue +
- "' failed", e);
+ LOG.warn("Parsing authorization header value'" + authValue
+ + "' failed", e);
}
return challengeMap;
@@ -649,7 +653,7 @@
Header authenticateHeader, String responseHeader)
throws HttpException, UnsupportedOperationException {
- log.trace("enter Authenticator.authenticate(HttpMethod, HttpState, "
+ LOG.trace("enter Authenticator.authenticate(HttpMethod, HttpState, "
+ "Header, String)");
// check the preemptive policy
@@ -661,7 +665,7 @@
if (!(preemptiveDefault.equals("true")
|| preemptiveDefault.equals("false"))) { // property problem
- log.warn("Configuration property " + PREEMPTIVE_PROPERTY
+ LOG.warn("Configuration property " + PREEMPTIVE_PROPERTY
+ " must be either true or false. Using default: "
+ PREEMPTIVE_DEFAULT);
preemptiveDefault = PREEMPTIVE_DEFAULT;
@@ -672,7 +676,7 @@
//if there is no challenge, attempt to use preemptive authorization
if (authenticateHeader == null) {
if (preemptive) {
- log.debug("Preemptively sending default basic credentials");
+ LOG.debug("Preemptively sending default basic credentials");
try {
Header requestHeader = Authenticator.basic(null, state,
@@ -680,8 +684,8 @@
method.addRequestHeader(requestHeader);
return true;
} catch (HttpException httpe) {
- if (log.isDebugEnabled()) {
- log.debug(
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(
"No default credentials to preemptively send");
}
return false;
@@ -736,7 +740,7 @@
* TODO: + Add createCnonce() method
*/
private static String createCnonce() throws HttpException {
- log.trace("enter Authenticator.createCnonce()");
+ LOG.trace("enter Authenticator.createCnonce()");
String cnonce;
final String digAlg = "MD5";
@@ -745,7 +749,7 @@
try {
md5Helper = MessageDigest.getInstance(digAlg);
} catch (Exception e) {
- log.error("ERROR! Unsupported algorithm in HTTP Digest "
+ LOG.error("ERROR! Unsupported algorithm in HTTP Digest "
+ "authentication: " + digAlg);
throw new HttpException("Unsupported algorithm in HTTP Digest "
+ "authentication: " + digAlg);
@@ -772,7 +776,7 @@
private static String createDigestHeader(String uname, Map mapCredentials,
String digest) {
- log.trace("enter Authenticator.createDigestHeader(String, Map, "
+ LOG.trace("enter Authenticator.createDigestHeader(String, Map, "
+ "String)");
StringBuffer sb = new StringBuffer();
@@ -814,9 +818,11 @@
* TODO: + Add encode() method
*/
private static String encode(byte[] binaryData) {
- log.trace("enter Authenticator.encode(byte[])");
+ LOG.trace("enter Authenticator.encode(byte[])");
- if (binaryData.length != 16) return null;
+ if (binaryData.length != 16) {
+ return null;
+ }
char[] buffer = new char[32];
for (int i = 0; i < 16; i++) {
@@ -853,8 +859,8 @@
realm = realm.substring(atFirst + 1, atLast);
}
- if (log.isDebugEnabled()) {
- log.debug("Parsed realm '" + realm + "' from challenge '"
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Parsed realm '" + realm + "' from challenge '"
+ challenge + "'");
}
@@ -877,7 +883,7 @@
* TODO: + Add processDigestToken() method
*/
private static void processDigestToken(String token, Map tokens) {
- log.trace("enter Authenticator.processDigestToken(String, Map)");
+ LOG.trace("enter Authenticator.processDigestToken(String, Map)");
int atEqual = token.indexOf("=");
@@ -900,15 +906,17 @@
* is same as Note that this class NEVER closes the underlying stream, even when close
+ * gets called. Instead, it will read until the "end" of its chunking on close,
+ * which allows for the seamless invocation of subsequent HTTP 1.1 calls, while
+ * not requiring the client to remember to read the entire contents of the
+ * response.str
*/
private static String removeQuotes(String str) {
- log.trace("enter Authenticator.removeQuotes(String)");
+ LOG.trace("enter Authenticator.removeQuotes(String)");
- if (str == null) return null;
+ if (str == null) {
+ return null;
+ }
int atFirst = str.indexOf("\"") + 1;
int atLast = str.lastIndexOf("\"");
- return (atFirst > 0 && atLast > atFirst) ?
- str.substring(atFirst, atLast) : str;
+ return (atFirst > 0 && atLast > atFirst)
+ ? str.substring(atFirst, atLast) : str;
}
}
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.5
diff -u -r1.5 AutoCloseInputStream.java
--- httpclient/src/java/org/apache/commons/httpclient/AutoCloseInputStream.java 23 Jan 2003 22:47:43 -0000 1.5
+++ httpclient/src/java/org/apache/commons/httpclient/AutoCloseInputStream.java 27 Jan 2003 01:56:46 -0000
@@ -72,18 +72,26 @@
*
* @author Ortwin Glück
* @author Eric Johnson
+ * @author
+ *
Footers are read automcatically at the end of the stream and can be + * obtained with the getFooters() method.
+ * + * @return -1 of the end of the stream has been reached or the next data + * byte + * @throws IOException If an IO problem occurs */ public int read() throws IOException { - if (closed) + if (closed) { throw new IOException("Attempted read from closed stream."); - if (eof) return -1; + } + if (eof) { + return -1; + } if (pos >= chunkSize) { nextChunk(); - if (eof) return -1; + if (eof) { + return -1; + } } pos++; return in.read(); } - public int read(byte[] b, int off, int len) throws java.io.IOException { + /** + * Read some bytes from the stream. + * @param b The byte array that will hold the contents from the stream. + * @param off The offset into the byte array at which bytes will start to be + * placed. + * @param len the maximum number of bytes that can be returned. + * @return The number of bytes returned or -1 if the end of stream has been + * reached. + * @see java.io.InputStream#read(byte[], int, int) + * @throws IOException if an IO problem occurs. + */ + public int read (byte[] b, int off, int len) throws IOException { - if (closed) + if (closed) { throw new IOException("Attempted read from closed stream."); + } - if (eof) return -1; + if (eof) { + return -1; + } if (pos >= chunkSize) { nextChunk(); - if (eof) return -1; + if (eof) { + return -1; + } } len = Math.min(len, chunkSize - pos); int count = in.read(b, off, len); @@ -157,15 +196,29 @@ return count; } - public int read(byte[] b) throws java.io.IOException { + /** + * Read some bytes from the stream. + * @param b The byte array that will hold the contents from the stream. + * @return The number of bytes returned or -1 if the end of stream has been + * reached. + * @see java.io.InputStream#read(byte[]) + * @throws IOException if an IO problem occurs. + */ + public int read (byte[] b) throws IOException { return read(b, 0, b.length); } + /** + * Read the next chunk. + * @throws IOException If an IO error occurs. + */ private void nextChunk() throws IOException { int cr = in.read(); int lf = in.read(); - if ((cr != '\r') || - (lf != '\n')) throw new IOException("CRLF expected at end of chunk: "+cr+"/"+lf); + if ((cr != '\r') || (lf != '\n')) { + throw new IOException( + "CRLF expected at end of chunk: " + cr + "/" + lf); + } chunkSize = getChunkSizeFromInputStream(in); pos = 0; if (chunkSize == 0) { @@ -175,30 +228,31 @@ } /** - * Expects the stream to start with a chunksize in hex with optional comments - * after a semicolon. The line must end with a CRLF: - * "a3; some comment\r\n" - * Positions the stream at the start of the next line. + * Expects the stream to start with a chunksize in hex with optional + * comments after a semicolon. The line must end with a CRLF: "a3; some + * comment\r\n" Positions the stream at the start of the next line. * + * @param in The new input stream. * @return the chunk size as integer - * * @throws IOException when the chunk size could not be parsed - * @throws java.lang.RuntimeException - * - * */ - private static int getChunkSizeFromInputStream(final InputStream in) throws IOException { + private static int getChunkSizeFromInputStream( + final InputStream in) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); - int state = 0; //0: normal, 1: \r was scanned, 2: inside quoted string, -1: end + // States: 0=normal, 1=\r was scanned, 2=inside quoted string, -1=end + int state = 0; while (state != -1) { int b = in.read(); - if (b == -1) throw new IOException("chunked stream ended unexpectedly"); + if (b == -1) { + throw new IOException("chunked stream ended unexpectedly"); + } switch (state) { - case 0: + case 0: switch (b) { case '\r': state = 1; - break; + break; case '\"': state = 2; /* fall through */ @@ -212,7 +266,8 @@ state = -1; } else { // this was not CRLF - throw new IOException("Protocol violation: Unexpected single newline character in chunk size"); + throw new IOException("Protocol violation: Unexpected" + + " single newline character in chunk size"); } break; @@ -243,14 +298,15 @@ int result; try { result = Integer.parseInt(dataString.trim(), 16); - } catch(NumberFormatException e) { - throw new IOException("Bad chunk size: "+dataString); + } catch (NumberFormatException e) { + throw new IOException ("Bad chunk size: " + dataString); } return result; } /** * Stores the footers into map of Headers + * @throws IOException If an IO problem occurs */ private void parseFooters() throws IOException { String line = readLine(); @@ -258,7 +314,7 @@ int colonPos = line.indexOf(':'); if (colonPos != -1) { String key = line.substring(0, colonPos).trim(); - String val = line.substring(colonPos+1).trim(); + String val = line.substring(colonPos + 1).trim(); Header footer = new Header(key, val); method.addResponseFooter(footer); } @@ -266,12 +322,17 @@ } } + /** + * Read the next line from {@link #in}. + * @return String The next line. + * @throws IOException If an IO problem occurs. + */ private String readLine() throws IOException { StringBuffer buf = new StringBuffer(); - for(;;) { + while (true) { int ch = in.read(); - if(ch < 0) { - if(buf.length() == 0) { + if (ch < 0) { + if (buf.length() == 0) { return null; } else { break; @@ -281,7 +342,7 @@ } else if (ch == '\n') { break; } - buf.append((char)ch); + buf.append((char) ch); } return (buf.toString()); } @@ -290,6 +351,7 @@ * Upon close, this reads the remainder of the chunked message, * leaving the underlying socket at a position to start reading the * next response without scanning. + * @throws IOException If an IO problem occurs. */ public void close() throws IOException { if (!closed) { @@ -297,8 +359,7 @@ if (!eof) { exhaustInputStream(this); } - } - finally { + } finally { eof = true; closed = true; } @@ -314,11 +375,12 @@ * shared that way. * * @param inStream The {@link InputStream} to exhaust. + * @throws IOException If an IO problem occurs */ static void exhaustInputStream(InputStream inStream) throws IOException { // read and discard the remainder of the message byte buffer[] = new byte[1024]; - while ( inStream.read(buffer) >= 0) { + while (inStream.read(buffer) >= 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.4 diff -u -r1.4 ChunkedOutputStream.java --- httpclient/src/java/org/apache/commons/httpclient/ChunkedOutputStream.java 23 Jan 2003 22:09:33 -0000 1.4 +++ httpclient/src/java/org/apache/commons/httpclient/ChunkedOutputStream.java 27 Jan 2003 01:56:45 -0000 @@ -63,9 +63,10 @@ package org.apache.commons.httpclient; +import java.io.IOException; +import java.io.OutputStream; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import java.io.*; @@ -78,6 +79,7 @@ * @author Sean C. Sullivan * @author dIon Gillard * @author Oleg Kalnichevski + * @author > byte 1 \\r\\n (chunk length \"header\")"); - wireLog.debug(">> byte " + b + "\\r\\n (chunked byte)"); + if (WIRE_LOG.isDebugEnabled()) { + WIRE_LOG.debug(">> byte 1 \\r\\n (chunk length \"header\")"); + WIRE_LOG.debug(">> byte " + b + "\\r\\n (chunked byte)"); } } @@ -204,20 +206,21 @@ * @param len the length of data withinb to write
* @throws IOException when errors occur writing output
*/
- public void write(byte[] b, int off, int len) throws IOException {
- log.trace("enter ChunckedOutputStream.write(byte[], int, int)");
+ public void write (byte[] b, int off, int len) throws IOException {
+ LOG.trace("enter ChunckedOutputStream.write(byte[], int, int)");
- if (closed){
+ if (closed) {
throw new IllegalStateException("Output stream already closed");
}
- byte chunkHeader[] = HttpConstants.getBytes(Integer.toHexString(len) + "\r\n");
+ byte chunkHeader[] = HttpConstants.getBytes (
+ Integer.toHexString(len) + "\r\n");
stream.write(chunkHeader, 0, chunkHeader.length);
stream.write(b, off, len);
stream.write(ENDCHUNK, 0, ENDCHUNK.length);
- if (wireLog.isDebugEnabled()) {
- wireLog.debug(">> byte(s)" + len + " \\r\\n (chunk length "
+ if (WIRE_LOG.isDebugEnabled()) {
+ WIRE_LOG.debug(">> byte(s)" + len + " \\r\\n (chunk length "
+ "\"header\")");
- wireLog.debug(">> \"" + new String(b, off, len)
+ WIRE_LOG.debug(">> \"" + new String(b, off, len)
+ "\"\\r\\n (chunked bytes)");
}
}
@@ -230,7 +233,7 @@
* @throws IOException if an error occurs closing the stream
*/
public void writeClosingChunk() throws IOException {
- log.trace("enter ChunkedOutputStream.writeClosingChunk()");
+ LOG.trace("enter ChunkedOutputStream.writeClosingChunk()");
if (!closed) {
try {
@@ -238,9 +241,10 @@
stream.write(ZERO, 0, ZERO.length);
stream.write(CRLF, 0, CRLF.length);
stream.write(ENDCHUNK, 0, ENDCHUNK.length);
- wireLog.debug(">> byte 0 \\r\\n\\r\\n (final chunk)");
+ WIRE_LOG.debug(">> byte 0 \\r\\n\\r\\n (final chunk)");
} catch (IOException e) {
- log.debug("Unexpected exception caught when closing output stream", e);
+ LOG.debug("Unexpected exception caught when closing "
+ + "output stream", e);
throw e;
} finally {
// regardless of what happens, mark the stream as closed.
@@ -253,8 +257,9 @@
/**
* Flushes the underlying stream.
+ * @throws IOException If an IO problem occurs.
*/
- public void flush() throws java.io.IOException {
+ public void flush() throws IOException {
stream.flush();
}
@@ -266,7 +271,7 @@
* @throws IOException if an error occurs closing the stream
*/
public void close() throws IOException {
- log.trace("enter ChunkedOutputStream.close()");
+ LOG.trace("enter ChunkedOutputStream.close()");
writeClosingChunk();
super.close();
}
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.5
diff -u -r1.5 ConnectMethod.java
--- httpclient/src/java/org/apache/commons/httpclient/ConnectMethod.java 23 Jan 2003 22:47:45 -0000 1.5
+++ httpclient/src/java/org/apache/commons/httpclient/ConnectMethod.java 27 Jan 2003 01:56:45 -0000
@@ -63,7 +63,6 @@
package org.apache.commons.httpclient;
import java.io.IOException;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -72,6 +71,7 @@
*
* @author Ortwin Glück
* @author dIon Gillard
+ * @author = 200) && (code < 300)) {
conn.tunnelCreated();
code = method.execute(state, conn);
@@ -131,7 +131,7 @@
*/
protected void writeRequestHeaders(HttpState state, HttpConnection conn)
throws HttpException, IOException {
- log.trace("enter ConnectMethod.writeRequestHeaders(HttpState, "
+ LOG.trace("enter ConnectMethod.writeRequestHeaders(HttpState, "
+ "HttpConnection)");
if (method instanceof HttpMethodBase) {
@@ -168,7 +168,7 @@
/** Log object for this class. */
- private static final Log log = LogFactory.getLog(ConnectMethod.class);
+ private static final Log LOG = LogFactory.getLog(ConnectMethod.class);
/** The wrapped method */
private HttpMethod method;
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.4
diff -u -r1.4 ContentLengthInputStream.java
--- httpclient/src/java/org/apache/commons/httpclient/ContentLengthInputStream.java 23 Jan 2003 22:47:45 -0000 1.4
+++ httpclient/src/java/org/apache/commons/httpclient/ContentLengthInputStream.java 27 Jan 2003 01:56:46 -0000
@@ -62,20 +62,31 @@
package org.apache.commons.httpclient;
-import java.io.*;
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
/**
* Cuts the wrapped InputStream off after a specified number of bytes.
*
* @author Ortwin Glück
* @author Eric Johnson
+ * @author = contentLength)
+ if (pos >= contentLength) {
return -1;
+ }
pos++;
return super.read();
}
@@ -130,12 +151,14 @@
*
* @throws java.io.IOException Should an error occur on the wrapped stream.
*/
- public int read(byte[] b, int off, int len) throws java.io.IOException {
- if (closed)
+ public int read (byte[] b, int off, int len) throws java.io.IOException {
+ if (closed) {
throw new IOException("Attempted read from closed stream.");
+ }
- if (pos >= contentLength)
+ if (pos >= contentLength) {
return -1;
+ }
if (pos + len > contentLength) {
len = contentLength - pos;
@@ -146,7 +169,14 @@
}
- public int read(byte[] b) throws java.io.IOException {
+ /**
+ * Read more bytes from the stream.
+ * @param b The byte array to put the new data in.
+ * @return The number of bytes read into the buffer.
+ * @throws IOException If an IO problem occurs
+ * @see java.io.InputStream#read(byte[])
+ */
+ public int read(byte[] b) throws IOException {
return read(b, 0, b.length);
}
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.33
diff -u -r1.33 Cookie.java
--- httpclient/src/java/org/apache/commons/httpclient/Cookie.java 23 Jan 2003 22:47:45 -0000 1.33
+++ httpclient/src/java/org/apache/commons/httpclient/Cookie.java 27 Jan 2003 01:56:47 -0000
@@ -86,6 +86,7 @@
* @author John Evans
* @author Marc A. Saegesser
* @author Oleg Kalnichevski
+ * @author Cookie header containing
- * all cookies in cookies,
- * associated with the given domain, port,
- * path and https setting, and which are
- * not expired according to the given date.
+ * Create a Cookie header containing all cookies in cookies,
+ * associated with the given domain, port, path and
+ * https setting, and which are not expired according to the given
+ * date.
* * 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 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 * * @deprecated use {@link CookieSpec} interface */ - public static Header createCookieHeader(String domain, int port, String path, boolean secure, Date now, Cookie[] cookies) - throws IllegalArgumentException { - log.trace("enter Cookie.createCookieHeader(String, int, String, boolean, Date, Cookie[])"); + public static Header createCookieHeader( + String domain, int port, String path, boolean secure, + Date now, Cookie[] cookies) + throws IllegalArgumentException { + + LOG.trace("enter Cookie.createCookieHeader(String, int, String, boolean, Date, Cookie[])"); CookieSpec matcher = CookiePolicy.getDefaultSpec(); cookies = matcher.match(domain, port, path, secure, cookies); - if ((cookies != null) && (cookies.length > 0)) - { + if ((cookies != null) && (cookies.length > 0)) { return matcher.formatCookieHeader(cookies); } - else - { + else { return null; } } @@ -580,9 +589,12 @@ * createCookieHeader method.
*The compare only compares the path of the cookie, see section 4.3.4 * of RFC2109
+ * @param o1 The first object to be compared + * @param o2 The second object to be compared + * @return See {@link java.util.Comparator#compare(Object,Object)} */ public int compare(Object o1, Object o2) { - log.trace("enter Cookie.compare(Object, Object)"); + LOG.trace("enter Cookie.compare(Object, Object)"); if (!(o1 instanceof Cookie)) { throw new ClassCastException(o1.getClass().getName()); @@ -590,8 +602,8 @@ if (!(o2 instanceof Cookie)) { throw new ClassCastException(o2.getClass().getName()); } - Cookie c1 = (Cookie)o1; - Cookie c2 = (Cookie)o2; + Cookie c1 = (Cookie) o1; + Cookie c2 = (Cookie) o2; if (c1.getPath() == null && c2.getPath() == null) { return 0; } else if (c1.getPath() == null) { @@ -609,7 +621,7 @@ return 1; } } else { - return stringCollator.compare(c1.getPath(), c2.getPath()); + return STRING_COLLATOR.compare(c1.getPath(), c2.getPath()); } } @@ -627,16 +639,21 @@ * on an insecure channel. * * @param domain the domain from which the {@link Header} was received - * @param port the port from which the {@link Header} was received (currently ignored) + * @param port the port from which the {@link Header} was received + * (currently ignored) * @param path the path from which the {@link Header} was received - * @param setCookie the Set-Cookie {@link Header} received from the server - * @return an array of Cookies parsed from the Set-Cookie {@link Header} + * @param setCookie the Set-Cookie {@link Header} received from the + * server + * @return an array of Cookies parsed from the Set-Cookie {@link + * Header} * @throws HttpException if an exception occurs during parsing - * @throws java.lang.IllegalArgumentException if domain or path are null + * @throws IllegalArgumentException if domain or path are null */ - public static Cookie[] parse(String domain, int port, String path, Header setCookie) - throws HttpException, IllegalArgumentException { - log.trace("enter Cookie.parse(String, int, String, Header)"); + public static Cookie[] parse( + String domain, int port, String path, Header setCookie) + throws HttpException, IllegalArgumentException { + + LOG.trace("enter Cookie.parse(String, int, String, Header)"); return Cookie.parse(domain,port,path,false,setCookie); } @@ -647,17 +664,19 @@ * * @param domain the domain from which the {@link Header} was received * @param path the path from which the {@link Header} was received - * @param setCookie the Set-Cookie {@link Header} received from the server - * @return an array of Cookies parsed from the Set-Cookie {@link Header} + * @param setCookie the Set-Cookie {@link Header} received from the + * server + * @return an array of Cookies parsed from the Set-Cookie {@link + * Header} * @throws HttpException if an exception occurs during parsing - * @throws java.lang.IllegalArgumentException if domain or path are null + * @throws IllegalArgumentException if domain or path are null * * @deprecated use {@link CookieSpec} interface */ public static Cookie[] parse(String domain, String path, Header setCookie) throws HttpException, IllegalArgumentException { - log.trace("enter Cookie.parse(String, String, Header)"); - return Cookie.parse(domain,80,path,false,setCookie); + LOG.trace("enter Cookie.parse(String, String, Header)"); + return Cookie.parse (domain, 80, path, false, setCookie); } /** @@ -666,18 +685,24 @@ * * @param domain the domain from which the {@link Header} was received * @param path the path from which the {@link Header} was received - * @param secure true when the header was recieved over a secure channel - * @param setCookie the Set-Cookie {@link Header} received from the server - * @return an array of Cookies parsed from the Set-Cookie {@link Header} + * @param secure true when the header was recieved over a secure + * channel + * @param setCookie the Set-Cookie {@link Header} received from the + * server + * @return an array of Cookies parsed from the Set-Cookie {@link + * Header} * @throws HttpException if an exception occurs during parsing - * @throws java.lang.IllegalArgumentException if domain or path are null + * @throws IllegalArgumentException if domain or path are null * * @deprecated use {@link CookieSpec} interface */ - public static Cookie[] parse(String domain, String path, boolean secure, Header setCookie) - throws HttpException { - log.trace("enter Cookie.parse(String, String, boolean, Header)"); - return Cookie.parse(domain,(secure ? 443 : 80),path,secure,setCookie); + public static Cookie[] parse(String domain, String path, + boolean secure, Header setCookie) + throws HttpException, IllegalArgumentException { + + LOG.trace ("enter Cookie.parse(String, String, boolean, Header)"); + return Cookie.parse ( + domain, (secure ? 443 : 80), path, secure, setCookie); } /** @@ -701,26 +726,31 @@ * * * @param domain the domain from which the {@link Header} was received + * @param port The port from which the {@link Header} was received. * @param path the path from which the {@link Header} was received - * @param secure true when the {@link Header} was received over HTTPS - * @param setCookie the Set-Cookie {@link Header} received from the server - * @return an array of Cookies parsed from the Set-Cookie {@link Header} + * @param secure true when the {@link Header} was received over + * HTTPS + * @param setCookie the Set-Cookie {@link Header} received from + * the server + * @return an array of Cookies parsed from the Set-Cookie {@link + * Header} * @throws HttpException if an exception occurs during parsing - * @throws java.lang.IllegalArgumentException if domain or path are null * * @deprecated use {@link CookieSpec} interface */ - public static Cookie[] parse(String domain, int port, String path, boolean secure, Header setCookie) - throws HttpException, IllegalArgumentException { - log.trace("enter Cookie.parse(String, int, String, boolean, Header)"); + public static Cookie[] parse(String domain, int port, String path, + boolean secure, Header setCookie) + throws HttpException { + + LOG.trace("enter Cookie.parse(String, int, String, boolean, Header)"); CookieSpec parser = CookiePolicy.getDefaultSpec(); Cookie[] cookies = parser.parse(domain, port, path, secure, setCookie); - for (int i = 0; i < cookies.length; i++) - { - Cookie cookie = cookies[i]; - CookieSpec validator = CookiePolicy.getSpecByVersion(cookie.getVersion()); + for (int i = 0; i < cookies.length; i++) { + final Cookie cookie = cookies[i]; + final CookieSpec validator + = CookiePolicy.getSpecByVersion(cookie.getVersion()); validator.validate(domain, port, path, secure, cookie); } return cookies; @@ -743,10 +773,16 @@ /** My secure flag. */ private boolean _secure; - /** Specifies if the set-cookie header included a Path attribute for this cookie */ + /** + * Specifies if the set-cookie header included a Path attribute for this + * cookie + */ private boolean _hasPathAttribute = false; - /** Specifies if the set-cookie header included a Domain attribute for this cookie */ + /** + * Specifies if the set-cookie header included a Domain attribute for this + * cookie + */ private boolean _hasDomainAttribute = false; /** The version of the cookie specification I was created from. */ @@ -754,13 +790,16 @@ // -------------------------------------------------------------- Constants - /** Collator for Cookie comparisons. Could be replaced with references to specific Locales. */ - private static final RuleBasedCollator stringCollator = - (RuleBasedCollator)RuleBasedCollator.getInstance( + /** + * Collator for Cookie comparisons. Could be replaced with references to + * specific Locales. + */ + private static final RuleBasedCollator STRING_COLLATOR = + (RuleBasedCollator) RuleBasedCollator.getInstance( new Locale("en", "US", "")); /** Log object for this class */ - private static final Log log = LogFactory.getLog(Cookie.class); + private static final Log LOG = LogFactory.getLog(Cookie.class); } 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.36 diff -u -r1.36 HttpConnection.java --- httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java 25 Jan 2003 04:46:39 -0000 1.36 +++ httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java 27 Jan 2003 01:56:47 -0000 @@ -824,10 +824,10 @@ 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); Index: httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v retrieving revision 1.99 diff -u -r1.99 HttpMethodBase.java --- httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java 25 Jan 2003 22:52:16 -0000 1.99 +++ httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java 27 Jan 2003 01:56:46 -0000 @@ -928,7 +928,7 @@ //check to see if we have visited this url before if (visited.contains(generateVisitedKey(conn))) { - log.error("Link " + generateVisitedKey(conn) + "' revisited"); + LOG.error("Link " + generateVisitedKey(conn) + "' revisited"); return statusCode; } visited.add(generateVisitedKey(conn)); @@ -1015,7 +1015,7 @@ try{ checkValidRedirect(currentUrl, redirectUrl); } catch (HttpException ex) { - //log the error and let the client handle the redirect + //LOG the error and let the client handle the redirect log.warn(ex.getMessage()); return false; } Index: httpclient/src/java/org/apache/commons/httpclient/WireLogInputStream.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/WireLogInputStream.java,v retrieving revision 1.5 diff -u -r1.5 WireLogInputStream.java --- httpclient/src/java/org/apache/commons/httpclient/WireLogInputStream.java 23 Jan 2003 22:47:49 -0000 1.5 +++ httpclient/src/java/org/apache/commons/httpclient/WireLogInputStream.java 27 Jan 2003 01:56:45 -0000 @@ -66,7 +66,7 @@ import org.apache.commons.logging.*; /** - * Logs all data read to the wire log. + * Logs all data read to the wire LOG. * * @author Ortwin Glück * 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.4 diff -u -r1.4 CookiePolicy.java --- httpclient/src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java 26 Jan 2003 06:59:20 -0000 1.4 +++ httpclient/src/java/org/apache/commons/httpclient/cookie/CookiePolicy.java 27 Jan 2003 01:56:47 -0000 @@ -82,6 +82,7 @@ * COMPATIBILITY, NETSCAPE_DRAFT, RFC2109. * * @author Oleg Kalnichevski + * @author John Evans * @author Marc A. Saegesser * @author Oleg Kalnichevski + * @author * - * @param host the host from which the Set-Cookie value was received - * @param port the port from which the Set-Cookie value was received - * @param path the path from which the Set-Cookie value was received - * @param secure true when the Set-Cookie value was received over secure conection + * @param host the host from which the Set-Cookie value was + * received + * @param port the port from which the Set-Cookie value was + * received + * @param path the path from which the Set-Cookie value was + * received + * @param secure true when the Set-Cookie value was + * received over secure conection * @param header the Set-Cookie received from the server * @return an array of Cookies parsed from the Set-Cookie value * @throws MalformedCookieException if an exception occurs during parsing - * @throws java.lang.IllegalArgumentException if an input parameter is illegal */ - - public Cookie[] parse(String host, int port, String path, boolean secure, final String header) - throws MalformedCookieException - { - log.trace("enter CookieSpecBase.parse(String, port, path, boolean, Header)"); - - if(host == null) - { - throw new IllegalArgumentException("Host of origin may not be null"); - } - if(host.trim().equals("")) - { - throw new IllegalArgumentException("Host of origin may not be blank"); + public Cookie[] parse(String host, int port, String path, + boolean secure, final String header) + throws MalformedCookieException { + + LOG.trace("enter CookieSpecBase.parse(" + + "String, port, path, boolean, Header)"); + + if (host == null) { + throw new IllegalArgumentException( + "Host of origin may not be null"); + } + if (host.trim().equals("")) { + throw new IllegalArgumentException( + "Host of origin may not be blank"); } - if(port < 0) - { + if (port < 0) { throw new IllegalArgumentException("Invalid port: " + port); } - if(path == null) - { - throw new IllegalArgumentException("Path of origin may not be null."); + if (path == null) { + throw new IllegalArgumentException( + "Path of origin may not be null."); } - if(header == null) - { + if (header == null) { throw new IllegalArgumentException("Header may not be null."); } @@ -185,19 +184,15 @@ host = host.toLowerCase(); HeaderElement[] headerElements = null; - try - { + try { headerElements = HeaderElement.parse(header); - } - catch(HttpException e) - { + } catch (HttpException e) { throw new MalformedCookieException(e.getMessage()); } String defaultPath = path; int lastSlashIndex = defaultPath.lastIndexOf(PATH_DELIM); - if(lastSlashIndex > 0) - { + if (lastSlashIndex > 0) { defaultPath = defaultPath.substring(0, lastSlashIndex); } @@ -218,8 +213,7 @@ // could be null. In case only a header element and no parameters. if (parameters != null) { - for (int j = 0; j < parameters.length; j++) - { + for (int j = 0; j < parameters.length; j++) { parseAttribute(parameters[j], cookie); } } @@ -230,7 +224,8 @@ /** - * Parse the "Set-Cookie" {@link Header} into an array of {@link Cookie}s. + * Parse the "Set-Cookie" {@link Header} into an array of {@link + * Cookie}s. * *The syntax for the Set-Cookie response header is:
*
@@ -248,22 +243,26 @@
* | "Version" "=" 1*DIGIT
*
*
- * @param host the host from which the Set-Cookie header was received
- * @param port the port from which the Set-Cookie header was received
- * @param path the path from which the Set-Cookie header was received
- * @param secure true when the Set-Cookie header was received over secure conection
+ * @param host the host from which the Set-Cookie header was
+ * received
+ * @param port the port from which the Set-Cookie header was
+ * received
+ * @param path the path from which the Set-Cookie header was
+ * received
+ * @param secure true when the Set-Cookie header was
+ * received over secure conection
* @param header the Set-Cookie received from the server
- * @return an array of Cookies parsed from the "Set-Cookie" header
+ * @return an array of Cookies parsed from the "Set-Cookie"
+ * header
* @throws MalformedCookieException if an exception occurs during parsing
- * @throws java.lang.IllegalArgumentException if an input parameter is illegal
*/
-
- public Cookie[] parse(String host, int port, String path, boolean secure, final Header header)
- throws MalformedCookieException
- {
- log.trace("enter CookieSpecBase.parse(String, port, path, boolean, String)");
- if(header == null)
- {
+ public Cookie[] parse(
+ String host, int port, String path, boolean secure, final Header header)
+ throws MalformedCookieException {
+
+ LOG.trace("enter CookieSpecBase.parse("
+ + "String, port, path, boolean, String)");
+ if (header == null) {
throw new IllegalArgumentException("Header may not be null.");
}
return parse(host, port, path, secure, header.getValue());
@@ -271,95 +270,98 @@
/**
- * Parse the cookie attribute and update the corresponsing {@link Cookie} properties.
+ * Parse the cookie attribute and update the corresponsing {@link Cookie}
+ * properties.
*
- * @param attribute {@link HeaderElement} cookie attribute from the Set-Cookie
+ * @param attribute {@link HeaderElement} cookie attribute from the
+ * Set- Cookie
* @param cookie {@link Cookie} to be updated
* @throws MalformedCookieException if an exception occurs during parsing
- * @throws java.lang.IllegalArgumentException if an input parameter is illegal
*/
- public void parseAttribute(final NameValuePair attribute, final Cookie cookie)
- throws MalformedCookieException
- {
- if(attribute == null)
- {
+ public void parseAttribute(
+ final NameValuePair attribute, final Cookie cookie)
+ throws MalformedCookieException {
+
+ if (attribute == null) {
throw new IllegalArgumentException("Attribute may not be null.");
}
- if(cookie == null)
- {
+ if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null.");
}
- String param_name = attribute.getName().toLowerCase();
- String param_value = attribute.getValue();
+ final String paramName = attribute.getName().toLowerCase();
+ String paramValue = attribute.getValue();
- if (param_name.equals("path")) {
+ if (paramName.equals("path")) {
- if (param_value == null) {
- throw new MalformedCookieException("Missing value for path attribute");
+ if (paramValue == null) {
+ throw new MalformedCookieException(
+ "Missing value for path attribute");
}
- if (param_value.trim().equals("")) {
- throw new MalformedCookieException("Blank value for path attribute");
+ if (paramValue.trim().equals("")) {
+ throw new MalformedCookieException(
+ "Blank value for path attribute");
}
- cookie.setPath(param_value);
+ cookie.setPath(paramValue);
cookie.setPathAttributeSpecified(true);
- }
- else if (param_name.equals("domain")) {
+ } else if (paramName.equals("domain")) {
- if (param_value == null) {
- throw new MalformedCookieException("Missing value for domain attribute");
+ if (paramValue == null) {
+ throw new MalformedCookieException(
+ "Missing value for domain attribute");
}
- if (param_value.trim().equals("")) {
- throw new MalformedCookieException("Blank value for domain attribute");
+ if (paramValue.trim().equals("")) {
+ throw new MalformedCookieException(
+ "Blank value for domain attribute");
}
- cookie.setDomain(param_value);
+ cookie.setDomain(paramValue);
cookie.setDomainAttributeSpecified(true);
- }
- else if (param_name.equals("max-age")) {
+ } else if (paramName.equals("max-age")) {
- if (param_value == null) {
- throw new MalformedCookieException("Missing value for max-age attribute");
+ if (paramValue == null) {
+ throw new MalformedCookieException(
+ "Missing value for max-age attribute");
}
int age;
try {
- age = Integer.parseInt(param_value);
+ age = Integer.parseInt(paramValue);
} catch (NumberFormatException e) {
- throw new MalformedCookieException( "Invalid max-age attribute: " + e.getMessage());
+ throw new MalformedCookieException ("Invalid max-age "
+ + "attribute: " + e.getMessage());
}
- cookie.setExpiryDate(new Date(System.currentTimeMillis() +
- age * 1000L));
+ cookie.setExpiryDate(
+ new Date(System.currentTimeMillis() + age * 1000L));
- }
- else if (param_name.equals("secure")) {
+ } else if (paramName.equals("secure")) {
cookie.setSecure(true);
- }
- else if (param_name.equals("comment")) {
+ } else if (paramName.equals("comment")) {
- cookie.setComment(param_value);
+ cookie.setComment(paramValue);
- }
- else if (param_name.equals("expires")) {
+ } else if (paramName.equals("expires")) {
- if (param_value == null) {
- throw new MalformedCookieException("Missing value for expires attribute");
+ if (paramValue == null) {
+ throw new MalformedCookieException(
+ "Missing value for expires attribute");
}
boolean set = false;
// trim single quotes around expiry if present
// see http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5279
- if(param_value.length() > 1 &&
- param_value.startsWith("'") &&
- param_value.endsWith("'")) {
- param_value = param_value.substring(1,param_value.length()-1);
+ if (paramValue.length() > 1
+ && paramValue.startsWith("'")
+ && paramValue.endsWith("'")) {
+ paramValue
+ = paramValue.substring (1, paramValue.length() - 1);
}
- for(int k=0;k