Index: 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.19 diff -u -r1.19 ChunkedInputStream.java --- java/org/apache/commons/httpclient/ChunkedInputStream.java 5 Aug 2003 19:29:30 -0000 1.19 +++ java/org/apache/commons/httpclient/ChunkedInputStream.java 13 Jan 2004 12:53:00 -0000 @@ -67,6 +67,7 @@ import java.io.IOException; import java.io.InputStream; +import org.apache.commons.httpclient.util.EncodingUtil; import org.apache.commons.httpclient.util.ExceptionUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -313,7 +314,7 @@ } //parse data - String dataString = HttpConstants.getString(baos.toByteArray()); + String dataString = EncodingUtil.getAsciiString(baos.toByteArray()); int separator = dataString.indexOf(';'); dataString = (separator > 0) ? dataString.substring(0, separator).trim() @@ -335,7 +336,8 @@ private void parseTrailerHeaders() throws IOException { Header[] footers = null; try { - footers = HttpParser.parseHeaders(in); + footers = HttpParser.parseHeaders(in, + method.getParams().getHttpElementCharset()); } catch(HttpException e) { LOG.error("Error parsing trailer headers", e); IOException ioe = new IOException(e.getMessage()); Index: 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.11 diff -u -r1.11 ChunkedOutputStream.java --- java/org/apache/commons/httpclient/ChunkedOutputStream.java 5 Aug 2003 19:29:30 -0000 1.11 +++ java/org/apache/commons/httpclient/ChunkedOutputStream.java 13 Jan 2004 12:53:01 -0000 @@ -65,6 +65,8 @@ import java.io.IOException; import java.io.OutputStream; + +import org.apache.commons.httpclient.util.EncodingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -142,7 +144,7 @@ if (s == null) { s = "null"; } - write(HttpConstants.getBytes(s)); + write(s.getBytes()); } /** @@ -201,7 +203,7 @@ if (closed) { throw new IllegalStateException("Output stream already closed"); } - byte chunkHeader[] = HttpConstants.getBytes ( + byte chunkHeader[] = EncodingUtil.getAsciiBytes ( Integer.toHexString(len) + "\r\n"); stream.write(chunkHeader, 0, chunkHeader.length); stream.write(b, off, len); Index: 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.82 diff -u -r1.82 HttpConnection.java --- java/org/apache/commons/httpclient/HttpConnection.java 11 Dec 2003 01:19:32 -0000 1.82 +++ java/org/apache/commons/httpclient/HttpConnection.java 13 Jan 2004 12:53:02 -0000 @@ -995,7 +995,7 @@ public void print(String data) throws IOException, IllegalStateException { LOG.trace("enter HttpConnection.print(String)"); - write(HttpConstants.getBytes(data)); + write(EncodingUtil.getBytes(data, "ISO-8859-1")); } /** @@ -1025,7 +1025,7 @@ public void printLine(String data) throws IOException, IllegalStateException { LOG.trace("enter HttpConnection.printLine(String)"); - writeLine(HttpConstants.getBytes(data)); + writeLine(EncodingUtil.getBytes(data, "ISO-8859-1")); } /** @@ -1063,12 +1063,32 @@ * @throws IllegalStateException if the connection is not open * @throws IOException if an I/O problem occurs * @return a line from the response + * + * @deprecated use #readLine(String) */ public String readLine() throws IOException, IllegalStateException { LOG.trace("enter HttpConnection.readLine()"); assertOpen(); return HttpParser.readLine(inputStream); + } + + /** + * Reads up to "\n" from the (unchunked) input stream. + * If the stream ends before the line terminator is found, + * the last part of the string will still be returned. + * + * @params charset the charset to use for reading the data + * + * @throws IllegalStateException if the connection is not open + * @throws IOException if an I/O problem occurs + * @return a line from the response + */ + public String readLine(final String charset) throws IOException, IllegalStateException { + LOG.trace("enter HttpConnection.readLine()"); + + assertOpen(); + return HttpParser.readLine(inputStream, charset); } /** Index: 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.10 diff -u -r1.10 HttpConstants.java --- java/org/apache/commons/httpclient/HttpConstants.java 17 Apr 2003 11:34:19 -0000 1.10 +++ java/org/apache/commons/httpclient/HttpConstants.java 13 Jan 2004 12:53:02 -0000 @@ -74,6 +74,8 @@ * * @author Oleg Kalnichevski * @author Mike Bowler + * + * @deprecated use {@link EncodingUtil} */ public class HttpConstants { Index: 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.195 diff -u -r1.195 HttpMethodBase.java --- java/org/apache/commons/httpclient/HttpMethodBase.java 14 Dec 2003 22:39:04 -0000 1.195 +++ java/org/apache/commons/httpclient/HttpMethodBase.java 13 Jan 2004 12:53:04 -0000 @@ -732,7 +732,7 @@ rawdata = getResponseBody(); } if (rawdata != null) { - return HttpConstants.getContentString(rawdata, getResponseCharSet()); + return EncodingUtil.getString(rawdata, getResponseCharSet()); } else { return null; } @@ -1716,7 +1716,9 @@ + "HttpConnection)"); getResponseHeaderGroup().clear(); - Header[] headers = HttpParser.parseHeaders(conn.getResponseInputStream()); + + Header[] headers = HttpParser.parseHeaders( + conn.getResponseInputStream(), getParams().getHttpElementCharset()); if (Wire.enabled()) { for (int i = 0; i < headers.length; i++) { Wire.input(headers[i].toExternalForm()); @@ -1757,7 +1759,7 @@ int count = 0; String s; do { - s = conn.readLine(); + s = conn.readLine(getParams().getHttpElementCharset()); if (Wire.enabled()) { Wire.input(s + "\r\n"); } @@ -2097,7 +2099,7 @@ * @param contentheader The content header. * @return String The character set. */ - protected static String getContentCharSet(Header contentheader) { + protected String getContentCharSet(Header contentheader) { LOG.trace("enter getContentCharSet( Header contentheader )"); String charset = null; if (contentheader != null) { @@ -2114,10 +2116,10 @@ } } if (charset == null) { + charset = getParams().getContentCharset(); if (LOG.isDebugEnabled()) { - LOG.debug("Default charset used: " + HttpConstants.DEFAULT_CONTENT_CHARSET); + LOG.debug("Default charset used: " + charset); } - charset = HttpConstants.DEFAULT_CONTENT_CHARSET; } return charset; } Index: java/org/apache/commons/httpclient/HttpParser.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpParser.java,v retrieving revision 1.8 diff -u -r1.8 HttpParser.java --- java/org/apache/commons/httpclient/HttpParser.java 15 Jul 2003 02:19:58 -0000 1.8 +++ java/org/apache/commons/httpclient/HttpParser.java 13 Jan 2004 12:53:04 -0000 @@ -68,6 +68,7 @@ import java.io.ByteArrayOutputStream; import java.util.ArrayList; +import org.apache.commons.httpclient.util.EncodingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -125,13 +126,14 @@ * If no input data available, null is returned * * @param inputStream the stream to read from + * @param charset charset of HTTP protocol elements * * @throws IOException if an I/O problem occurs * @return a line from the stream */ - public static String readLine(InputStream inputStream) throws IOException { - LOG.trace("enter HttpParser.readLine()"); + public static String readLine(InputStream inputStream, String charset) throws IOException { + LOG.trace("enter HttpParser.readLine(InputStream, String)"); byte[] rawdata = readRawLine(inputStream); if (rawdata == null) { return null; @@ -148,28 +150,48 @@ } } } - return HttpConstants.getString(rawdata, 0, len - offset); + return EncodingUtil.getString(rawdata, 0, len - offset, charset); } /** + * Read up to "\n" from an (unchunked) input stream. + * If the stream ends before the line terminator is found, + * the last part of the string will still be returned. + * If no input data available, null is returned + * + * @param inputStream the stream to read from + * + * @throws IOException if an I/O problem occurs + * @return a line from the stream + * + * @deprecated use #readLine(InputStream, String) + */ + + public static String readLine(InputStream inputStream) throws IOException { + LOG.trace("enter HttpParser.readLine(InputStream)"); + return readLine(inputStream, "US-ASCII"); + } + + /** * Parses headers from the given stream. Headers with the same name are not * combined. * * @param is the stream to read headers from + * @param charset the charset to use for reading the data * * @return an array of headers in the order in which they were parsed * * @throws IOException if an IO error occurs while reading from the stream * @throws HttpException if there is an error parsing a header value */ - public static Header[] parseHeaders(InputStream is) throws IOException, HttpException { - LOG.trace("enter HeaderParser.parseHeaders(HttpConnection, HeaderGroup)"); + public static Header[] parseHeaders(InputStream is, String charset) throws IOException, HttpException { + LOG.trace("enter HeaderParser.parseHeaders(InputStream, String)"); ArrayList headers = new ArrayList(); String name = null; StringBuffer value = null; for (; ;) { - String line = HttpParser.readLine(is); + String line = HttpParser.readLine(is, charset); if ((line == null) || (line.length() < 1)) { break; } @@ -210,5 +232,22 @@ return (Header[]) headers.toArray(new Header[headers.size()]); } - + + /** + * Parses headers from the given stream. Headers with the same name are not + * combined. + * + * @param is the stream to read headers from + * + * @return an array of headers in the order in which they were parsed + * + * @throws IOException if an IO error occurs while reading from the stream + * @throws HttpException if there is an error parsing a header value + * + * @deprecated use #parseHeaders(InputStream, String) + */ + public static Header[] parseHeaders(InputStream is) throws IOException, HttpException { + LOG.trace("enter HeaderParser.parseHeaders(InputStream, String)"); + return parseHeaders(is, "US-ASCII"); + } } Index: java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java,v retrieving revision 1.30 diff -u -r1.30 MultiThreadedHttpConnectionManager.java --- java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java 6 Jan 2004 20:08:56 -0000 1.30 +++ java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java 13 Jan 2004 12:53:06 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java,v 1.30 2004/01/06 20:08:56 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/MultiThreadedHttpConnectionManager.java,v 1.30 2004/01/06 20:08:56 olegk Exp $ * $Revision: 1.30 $ * $Date: 2004/01/06 20:08:56 $ * @@ -1147,9 +1147,20 @@ } } + /** + * @deprecated + */ public String readLine() throws IOException, IllegalStateException { if (hasConnection()) { return wrappedConnection.readLine(); + } else { + throw new IllegalStateException("Connection has been released"); + } + } + + public String readLine(String charset) throws IOException, IllegalStateException { + if (hasConnection()) { + return wrappedConnection.readLine(charset); } else { throw new IllegalStateException("Connection has been released"); } Index: java/org/apache/commons/httpclient/URI.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URI.java,v retrieving revision 1.43 diff -u -r1.43 URI.java --- java/org/apache/commons/httpclient/URI.java 6 Jan 2004 20:08:56 -0000 1.43 +++ java/org/apache/commons/httpclient/URI.java 13 Jan 2004 12:53:09 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URI.java,v 1.43 2004/01/06 20:08:56 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URI.java,v 1.43 2004/01/06 20:08:56 olegk Exp $ * $Revision: 1.43 $ * $Date: 2004/01/06 20:08:56 $ * @@ -1711,7 +1711,7 @@ throw new IllegalArgumentException("Allowed bitset may not be null"); } byte[] rawdata = URLCodec.encodeUrl(allowed, EncodingUtil.getBytes(original, charset)); - return HttpConstants.getAsciiString(rawdata).toCharArray(); + return EncodingUtil.getAsciiString(rawdata).toCharArray(); } /** @@ -1789,11 +1789,11 @@ } byte[] rawdata = null; try { - rawdata = URLCodec.decodeUrl(HttpConstants.getAsciiBytes(component)); + rawdata = URLCodec.decodeUrl(EncodingUtil.getAsciiBytes(component)); } catch (DecoderException e) { throw new URIException(e.getMessage()); } - return HttpConstants.getContentString(rawdata, charset); + return EncodingUtil.getString(rawdata, charset); } /** * Pre-validate the unescaped URI string within a specific component. Index: java/org/apache/commons/httpclient/auth/BasicScheme.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/BasicScheme.java,v retrieving revision 1.11 diff -u -r1.11 BasicScheme.java --- java/org/apache/commons/httpclient/auth/BasicScheme.java 12 Jan 2004 18:50:14 -0000 1.11 +++ java/org/apache/commons/httpclient/auth/BasicScheme.java 13 Jan 2004 12:53:09 -0000 @@ -65,7 +65,6 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.httpclient.Credentials; -import org.apache.commons.httpclient.HttpConstants; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.UsernamePasswordCredentials; import org.apache.commons.httpclient.util.EncodingUtil; @@ -236,7 +235,7 @@ * @return a basic authorization string */ public static String authenticate(UsernamePasswordCredentials credentials) { - return authenticate(credentials, HttpConstants.DEFAULT_CONTENT_CHARSET); + return authenticate(credentials, "ISO-8859-1"); } /** @@ -263,7 +262,7 @@ buffer.append(":"); buffer.append(credentials.getPassword()); - return "Basic " + HttpConstants.getAsciiString( + return "Basic " + EncodingUtil.getAsciiString( Base64.encodeBase64(EncodingUtil.getBytes(buffer.toString(), charset))); } Index: java/org/apache/commons/httpclient/auth/DigestScheme.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/DigestScheme.java,v retrieving revision 1.15 diff -u -r1.15 DigestScheme.java --- java/org/apache/commons/httpclient/auth/DigestScheme.java 12 Jan 2004 18:50:14 -0000 1.15 +++ java/org/apache/commons/httpclient/auth/DigestScheme.java 13 Jan 2004 12:53:10 -0000 @@ -69,7 +69,6 @@ import org.apache.commons.httpclient.Credentials; import org.apache.commons.httpclient.HttpClientError; -import org.apache.commons.httpclient.HttpConstants; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.UsernamePasswordCredentials; import org.apache.commons.httpclient.util.EncodingUtil; @@ -290,7 +289,7 @@ String digest = createDigest( usernamepassword.getUserName(), usernamepassword.getPassword(), - HttpConstants.DEFAULT_CONTENT_CHARSET); + "ISO-8859-1"); return "Digest " + createDigestHeader(usernamepassword.getUserName(), digest); } @@ -415,7 +414,7 @@ } else { a2 = method + ":" + uri; } - String md5a2 = encode(md5Helper.digest(HttpConstants.getBytes(a2))); + String md5a2 = encode(md5Helper.digest(EncodingUtil.getAsciiBytes(a2))); // 3.2.2.1 String serverDigestValue; @@ -448,7 +447,7 @@ } String serverDigest = - encode(md5Helper.digest(HttpConstants.getBytes(serverDigestValue))); + encode(md5Helper.digest(EncodingUtil.getAsciiBytes(serverDigestValue))); return serverDigest; } @@ -552,7 +551,7 @@ } cnonce = Long.toString(System.currentTimeMillis()); - cnonce = encode(md5Helper.digest(HttpConstants.getBytes(cnonce))); + cnonce = encode(md5Helper.digest(EncodingUtil.getAsciiBytes(cnonce))); return cnonce; } Index: java/org/apache/commons/httpclient/auth/NTLM.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/auth/NTLM.java,v retrieving revision 1.7 diff -u -r1.7 NTLM.java --- java/org/apache/commons/httpclient/auth/NTLM.java 12 Jan 2004 18:50:14 -0000 1.7 +++ java/org/apache/commons/httpclient/auth/NTLM.java 13 Jan 2004 12:53:10 -0000 @@ -73,7 +73,6 @@ import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; -import org.apache.commons.httpclient.HttpConstants; import org.apache.commons.httpclient.util.EncodingUtil; /** @@ -252,7 +251,7 @@ } else { resp = currentResponse; } - return HttpConstants.getString(Base64.encodeBase64(resp)); + return EncodingUtil.getAsciiString(Base64.encodeBase64(resp)); } /** Index: java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java,v retrieving revision 1.27 diff -u -r1.27 EntityEnclosingMethod.java --- java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java 14 Dec 2003 22:39:04 -0000 1.27 +++ java/org/apache/commons/httpclient/methods/EntityEnclosingMethod.java 13 Jan 2004 12:53:10 -0000 @@ -72,11 +72,11 @@ import org.apache.commons.httpclient.ChunkedOutputStream; import org.apache.commons.httpclient.ContentLengthInputStream; import org.apache.commons.httpclient.HttpConnection; -import org.apache.commons.httpclient.HttpConstants; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpVersion; import org.apache.commons.httpclient.ProtocolException; import org.apache.commons.httpclient.HttpState; +import org.apache.commons.httpclient.util.EncodingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -209,7 +209,7 @@ if (this.buffer != null) { return this.buffer; } else if (this.requestString != null) { - return HttpConstants.getContentBytes(this.requestString, getRequestCharSet()); + return EncodingUtil.getBytes(this.requestString, getRequestCharSet()); } else { return null; } @@ -435,7 +435,7 @@ LOG.trace("enter EntityEnclosingMethod.getRequestBodyAsString()"); byte [] content = generateRequestBody(); if (content != null) { - return HttpConstants.getContentString(content, getRequestCharSet()); + return EncodingUtil.getString(content, getRequestCharSet()); } else { return null; } Index: java/org/apache/commons/httpclient/methods/PostMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java,v retrieving revision 1.50 diff -u -r1.50 PostMethod.java --- java/org/apache/commons/httpclient/methods/PostMethod.java 14 Dec 2003 22:39:03 -0000 1.50 +++ java/org/apache/commons/httpclient/methods/PostMethod.java 13 Jan 2004 12:53:11 -0000 @@ -67,7 +67,6 @@ import java.util.Vector; import org.apache.commons.httpclient.HttpConnection; -import org.apache.commons.httpclient.HttpConstants; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpState; import org.apache.commons.httpclient.NameValuePair; @@ -207,7 +206,7 @@ LOG.trace("enter PostMethod.renerateRequestBody()"); if (!this.params.isEmpty()) { String content = EncodingUtil.formUrlEncode(getParameters(), getRequestCharSet()); - return HttpConstants.getContentBytes(content); + return EncodingUtil.getAsciiBytes(content); } else { return super.generateRequestBody(); } Index: java/org/apache/commons/httpclient/methods/multipart/FilePart.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/FilePart.java,v retrieving revision 1.15 diff -u -r1.15 FilePart.java --- java/org/apache/commons/httpclient/methods/multipart/FilePart.java 10 Oct 2003 04:18:35 -0000 1.15 +++ java/org/apache/commons/httpclient/methods/multipart/FilePart.java 13 Jan 2004 12:53:11 -0000 @@ -68,7 +68,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import org.apache.commons.httpclient.HttpConstants; +import org.apache.commons.httpclient.util.EncodingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -93,7 +93,7 @@ public static final String DEFAULT_CONTENT_TYPE = "application/octet-stream"; /** Default charset of file attachments. */ - public static final String DEFAULT_CHARSET = HttpConstants.DEFAULT_CONTENT_CHARSET; + public static final String DEFAULT_CHARSET = "ISO-8859-1"; /** Default transfer encoding of file attachments. */ public static final String DEFAULT_TRANSFER_ENCODING = "binary"; @@ -106,7 +106,7 @@ /** Attachment's file name as a byte array */ protected static final byte[] FILE_NAME_BYTES = - HttpConstants.getAsciiBytes(FILE_NAME); + EncodingUtil.getAsciiBytes(FILE_NAME); /** Source of the file part. */ private PartSource source; @@ -126,7 +126,7 @@ super( name, contentType == null ? DEFAULT_CONTENT_TYPE : contentType, - charset == null ? DEFAULT_CHARSET : charset, + charset == null ? "ISO-8859-1" : charset, DEFAULT_TRANSFER_ENCODING ); @@ -229,7 +229,7 @@ if (filename != null) { out.write(FILE_NAME_BYTES); out.write(QUOTE_BYTES); - out.write(HttpConstants.getAsciiBytes(filename)); + out.write(EncodingUtil.getAsciiBytes(filename)); out.write(QUOTE_BYTES); } } Index: java/org/apache/commons/httpclient/methods/multipart/Part.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/Part.java,v retrieving revision 1.11 diff -u -r1.11 Part.java --- java/org/apache/commons/httpclient/methods/multipart/Part.java 10 Oct 2003 04:18:35 -0000 1.11 +++ java/org/apache/commons/httpclient/methods/multipart/Part.java 13 Jan 2004 12:53:11 -0000 @@ -67,7 +67,7 @@ import java.io.IOException; import java.io.OutputStream; -import org.apache.commons.httpclient.HttpConstants; +import org.apache.commons.httpclient.util.EncodingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -93,55 +93,55 @@ protected static final String BOUNDARY = "----------------314159265358979323846"; /** The boundary as a byte array */ - protected static final byte[] BOUNDARY_BYTES = HttpConstants.getAsciiBytes(BOUNDARY); + protected static final byte[] BOUNDARY_BYTES = EncodingUtil.getAsciiBytes(BOUNDARY); /** Carriage return/linefeed */ protected static final String CRLF = "\r\n"; /** Carriage return/linefeed as a byte array */ - protected static final byte[] CRLF_BYTES = HttpConstants.getAsciiBytes(CRLF); + protected static final byte[] CRLF_BYTES = EncodingUtil.getAsciiBytes(CRLF); /** Content dispostion characters */ protected static final String QUOTE = "\""; /** Content dispostion as a byte array */ protected static final byte[] QUOTE_BYTES = - HttpConstants.getAsciiBytes(QUOTE); + EncodingUtil.getAsciiBytes(QUOTE); /** Extra characters */ protected static final String EXTRA = "--"; /** Extra characters as a byte array */ protected static final byte[] EXTRA_BYTES = - HttpConstants.getAsciiBytes(EXTRA); + EncodingUtil.getAsciiBytes(EXTRA); /** Content dispostion characters */ protected static final String CONTENT_DISPOSITION = "Content-Disposition: form-data; name="; /** Content dispostion as a byte array */ protected static final byte[] CONTENT_DISPOSITION_BYTES = - HttpConstants.getAsciiBytes(CONTENT_DISPOSITION); + EncodingUtil.getAsciiBytes(CONTENT_DISPOSITION); /** Content type header */ protected static final String CONTENT_TYPE = "Content-Type: "; /** Content type header as a byte array */ protected static final byte[] CONTENT_TYPE_BYTES = - HttpConstants.getAsciiBytes(CONTENT_TYPE); + EncodingUtil.getAsciiBytes(CONTENT_TYPE); /** Content charset */ protected static final String CHARSET = "; charset="; /** Content charset as a byte array */ protected static final byte[] CHARSET_BYTES = - HttpConstants.getAsciiBytes(CHARSET); + EncodingUtil.getAsciiBytes(CHARSET); /** Content type header */ protected static final String CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding: "; /** Content type header as a byte array */ protected static final byte[] CONTENT_TRANSFER_ENCODING_BYTES = - HttpConstants.getAsciiBytes(CONTENT_TRANSFER_ENCODING); + EncodingUtil.getAsciiBytes(CONTENT_TRANSFER_ENCODING); /** * Return the boundary string. @@ -198,7 +198,7 @@ LOG.trace("enter sendDispositionHeader(OutputStream out)"); out.write(CONTENT_DISPOSITION_BYTES); out.write(QUOTE_BYTES); - out.write(HttpConstants.getAsciiBytes(getName())); + out.write(EncodingUtil.getAsciiBytes(getName())); out.write(QUOTE_BYTES); } @@ -213,11 +213,11 @@ if (contentType != null) { out.write(CRLF_BYTES); out.write(CONTENT_TYPE_BYTES); - out.write(HttpConstants.getAsciiBytes(contentType)); + out.write(EncodingUtil.getAsciiBytes(contentType)); String charSet = getCharSet(); if (charSet != null) { out.write(CHARSET_BYTES); - out.write(HttpConstants.getAsciiBytes(charSet)); + out.write(EncodingUtil.getAsciiBytes(charSet)); } } } @@ -235,7 +235,7 @@ if (transferEncoding != null) { out.write(CRLF_BYTES); out.write(CONTENT_TRANSFER_ENCODING_BYTES); - out.write(HttpConstants.getAsciiBytes(transferEncoding)); + out.write(EncodingUtil.getAsciiBytes(transferEncoding)); } } Index: java/org/apache/commons/httpclient/methods/multipart/StringPart.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/StringPart.java,v retrieving revision 1.8 diff -u -r1.8 StringPart.java --- java/org/apache/commons/httpclient/methods/multipart/StringPart.java 10 Oct 2003 04:18:35 -0000 1.8 +++ java/org/apache/commons/httpclient/methods/multipart/StringPart.java 13 Jan 2004 12:53:12 -0000 @@ -65,7 +65,8 @@ import java.io.OutputStream; import java.io.IOException; -import org.apache.commons.httpclient.HttpConstants; + +import org.apache.commons.httpclient.util.EncodingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -143,7 +144,7 @@ */ private byte[] getContent() { if (content == null) { - content = HttpConstants.getContentBytes(value, getCharSet()); + content = EncodingUtil.getBytes(value, getCharSet()); } return content; } Index: java/org/apache/commons/httpclient/params/DefaultHttpParamsFactory.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/DefaultHttpParamsFactory.java,v retrieving revision 1.5 diff -u -r1.5 DefaultHttpParamsFactory.java --- java/org/apache/commons/httpclient/params/DefaultHttpParamsFactory.java 11 Dec 2003 01:19:32 -0000 1.5 +++ java/org/apache/commons/httpclient/params/DefaultHttpParamsFactory.java 13 Jan 2004 12:53:12 -0000 @@ -103,6 +103,7 @@ params.setConnectionManagerClass(SimpleHttpConnectionManager.class); params.setCookiePolicy(CookiePolicy.RFC_2109); params.setHttpElementCharset("US-ASCII"); + params.setContentCharset("ISO-8859-1"); ArrayList datePatterns = new ArrayList(); datePatterns.addAll( Index: java/org/apache/commons/httpclient/params/HttpMethodParams.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpMethodParams.java,v retrieving revision 1.7 diff -u -r1.7 HttpMethodParams.java --- java/org/apache/commons/httpclient/params/HttpMethodParams.java 11 Dec 2003 22:54:19 -0000 1.7 +++ java/org/apache/commons/httpclient/params/HttpMethodParams.java 13 Jan 2004 12:53:12 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpMethodParams.java,v 1.7 2003/12/11 22:54:19 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/params/HttpMethodParams.java,v 1.7 2003/12/11 22:54:19 olegk Exp $ * $Revision: 1.7 $ * $Date: 2003/12/11 22:54:19 $ * @@ -198,6 +198,14 @@ public static final String HTTP_ELEMENT_CHARSET = "http.protocol.element-charset"; /** + * Defines the charset to be used for encoding content body. + *

+ * This parameter expects a value of type {@link String}. + *

+ */ + public static final String HTTP_CONTENT_CHARSET = "http.protocol.content-charset"; + + /** * Defines {@link CookiePolicy cookie policy} to be used for cookie management. *

* This parameter expects a value of type {@link String}. @@ -289,6 +297,29 @@ */ public void setHttpElementCharset(String charset) { setParameter(HTTP_ELEMENT_CHARSET, charset); + } + + /** + * Returns the default charset to be used for writing content body, + * when no charset explicitly specified. + * @return The charset + */ + public String getContentCharset() { + String charset = (String) getParameter(HTTP_CONTENT_CHARSET); + if (charset == null) { + LOG.warn("Default content charset not configured, using ISO-8859-1"); + charset = "ISO-8859-1"; + } + return charset; + } + + /** + * Sets the default charset to be used for writing content body, + * when no charset explicitly specified. + * @param charset The charset + */ + public void setContentCharset(String charset) { + setParameter(HTTP_CONTENT_CHARSET, charset); } /** Index: java/org/apache/commons/httpclient/util/EncodingUtil.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/EncodingUtil.java,v retrieving revision 1.3 diff -u -r1.3 EncodingUtil.java --- java/org/apache/commons/httpclient/util/EncodingUtil.java 6 Jan 2004 20:08:56 -0000 1.3 +++ java/org/apache/commons/httpclient/util/EncodingUtil.java 13 Jan 2004 12:53:12 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/EncodingUtil.java,v 1.3 2004/01/06 20:08:56 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/EncodingUtil.java,v 1.3 2004/01/06 20:08:56 olegk Exp $ * $Revision: 1.3 $ * $Date: 2004/01/06 20:08:56 $ * @@ -66,7 +66,6 @@ import org.apache.commons.codec.net.URLCodec; import org.apache.commons.httpclient.HttpClientError; -import org.apache.commons.httpclient.HttpConstants; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -75,11 +74,15 @@ * The home for utility methods that handle various encoding tasks. * * @author Michael Becke + * @author Oleg Kalnichevski * * @since 2.0 final */ public class EncodingUtil { + /** Default content encoding chatset */ + private static final String DEFAULT_CHARSET = "ISO-8859-1"; + /** Log object for this class. */ private static final Log LOG = LogFactory.getLog(EncodingUtil.class); @@ -96,7 +99,7 @@ * as in multi-line text field values, are represented as CR LF pairs, i.e. `%0D%0A'. * *

- * if the given charset is not supported, {@link HttpConstants.DEFAULT_CONTENT_CHARSET default HTTP + * if the given charset is not supported, {@link DEFAULT_CONTENT_CHARSET default HTTP * content encoding} is used instead. *

* @@ -113,11 +116,11 @@ } catch (UnsupportedEncodingException e) { LOG.error("Encoding not supported: " + charset); try { - return doFormUrlEncode(pairs, HttpConstants.DEFAULT_CONTENT_CHARSET); + return doFormUrlEncode(pairs, DEFAULT_CHARSET); } catch (UnsupportedEncodingException fatal) { // Should never happen. ISO-8859-1 must be supported on all JVMs throw new HttpClientError("Encoding not supported: " + - HttpConstants.DEFAULT_CONTENT_CHARSET); + DEFAULT_CHARSET); } } } @@ -164,6 +167,57 @@ } /** + * Converts the byte array of HTTP content characters to a string. If + * the specified charset is not supported, default system encoding + * is used. + * + * @param data the byte array to be encoded + * @param offset the index of the first byte to encode + * @param length the number of bytes to encode + * @param charset the desired character encoding + * @return The result of the conversion. + */ + public static String getString( + final byte[] data, + int offset, + int length, + String charset + ) { + + if (data == null) { + throw new IllegalArgumentException("Parameter may not be null"); + } + + if (charset == null || charset.length() == 0) { + throw new IllegalArgumentException("charset may not be null or empty"); + } + + try { + return new String(data, offset, length, charset); + } catch (UnsupportedEncodingException e) { + + if (LOG.isWarnEnabled()) { + LOG.warn("Unsupported encoding: " + charset + ". System encoding used"); + } + return new String(data, offset, length); + } + } + + + /** + * Converts the byte array of HTTP content characters to a string. If + * the specified charset is not supported, default system encoding + * is used. + * + * @param data the byte array to be encoded + * @param charset the desired character encoding + * @return The result of the conversion. + */ + public static String getString(final byte[] data, String charset) { + return getString(data, 0, data.length, charset); + } + + /** * Converts the specified string to a byte array. If the charset is not supported the * default system charset is used. * @@ -193,6 +247,60 @@ } } + /** + * 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) { + + if (data == null) { + throw new IllegalArgumentException("Parameter may not be null"); + } + + try { + return data.getBytes("US-ASCII"); + } catch (UnsupportedEncodingException e) { + throw new HttpClientError("HttpClient requires ASCII support"); + } + } + + /** + * 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 + * @param offset the index of the first byte to encode + * @param length the number of bytes to encode + * @return The string representation of the byte array + */ + public static String getAsciiString(final byte[] data, int offset, int length) { + + if (data == null) { + throw new IllegalArgumentException("Parameter may not be null"); + } + + try { + return new String(data, offset, length, "US-ASCII"); + } catch (UnsupportedEncodingException e) { + throw new HttpClientError("HttpClient requires ASCII support"); + } + } + + /** + * 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) { + return getAsciiString(data, 0, data.length); + } + /** * This class should not be instantiated. */ Index: java/org/apache/commons/httpclient/util/URIUtil.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/URIUtil.java,v retrieving revision 1.23 diff -u -r1.23 URIUtil.java --- java/org/apache/commons/httpclient/util/URIUtil.java 6 Jan 2004 20:08:56 -0000 1.23 +++ java/org/apache/commons/httpclient/util/URIUtil.java 13 Jan 2004 12:53:13 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/URIUtil.java,v 1.23 2004/01/06 20:08:56 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/util/URIUtil.java,v 1.23 2004/01/06 20:08:56 olegk Exp $ * $Revision: 1.23 $ * $Date: 2004/01/06 20:08:56 $ * @@ -67,7 +67,6 @@ import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.net.URLCodec; -import org.apache.commons.httpclient.HttpConstants; import org.apache.commons.httpclient.URI; import org.apache.commons.httpclient.URIException; @@ -538,7 +537,7 @@ String charset) throws URIException { byte[] rawdata = URLCodec.encodeUrl(allowed, EncodingUtil.getBytes(unescaped, charset)); - return HttpConstants.getAsciiString(rawdata); + return EncodingUtil.getAsciiString(rawdata); } @@ -555,8 +554,8 @@ */ public static String decode(String escaped) throws URIException { try { - byte[] rawdata = URLCodec.decodeUrl(HttpConstants.getAsciiBytes(escaped)); - return HttpConstants.getContentString(rawdata, URI.getDefaultProtocolCharset()); + byte[] rawdata = URLCodec.decodeUrl(EncodingUtil.getAsciiBytes(escaped)); + return EncodingUtil.getString(rawdata, URI.getDefaultProtocolCharset()); } catch (DecoderException e) { throw new URIException(e.getMessage()); } Index: test/org/apache/commons/httpclient/SimpleHttpConnection.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/SimpleHttpConnection.java,v retrieving revision 1.16 diff -u -r1.16 SimpleHttpConnection.java --- test/org/apache/commons/httpclient/SimpleHttpConnection.java 11 Sep 2003 20:08:33 -0000 1.16 +++ test/org/apache/commons/httpclient/SimpleHttpConnection.java 13 Jan 2004 12:53:13 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/SimpleHttpConnection.java,v 1.16 2003/09/11 20:08:33 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/SimpleHttpConnection.java,v 1.16 2003/09/11 20:08:33 olegk Exp $ * $Revision: 1.16 $ * $Date: 2003/09/11 20:08:33 $ * ==================================================================== @@ -72,6 +72,7 @@ import java.util.Vector; import org.apache.commons.httpclient.protocol.Protocol; +import org.apache.commons.httpclient.util.EncodingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -163,7 +164,7 @@ writer.close(); byte[] headerContent = headerOutputStream.toByteArray(); - byte[] bodyContent = HttpConstants.getContentBytes((String)bodies.elementAt(hits)); + byte[] bodyContent = EncodingUtil.getBytes((String)bodies.elementAt(hits), "ISO-8859-1"); // combine the header and body content so they can be read from one steam byte[] content = new byte[headerContent.length + bodyContent.length]; @@ -207,6 +208,16 @@ throws IOException, IllegalStateException, HttpRecoverableException { } + public String readLine(String charset) + throws IOException, IllegalStateException { + String str = HttpParser.readLine(inputStream, charset); + log.debug("read: " + str); + return str; + } + + /** + * @deprecated + */ public String readLine() throws IOException, IllegalStateException { String str = HttpParser.readLine(inputStream); Index: test/org/apache/commons/httpclient/TestAuthenticator.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestAuthenticator.java,v retrieving revision 1.37 diff -u -r1.37 TestAuthenticator.java --- test/org/apache/commons/httpclient/TestAuthenticator.java 12 Jan 2004 18:50:15 -0000 1.37 +++ test/org/apache/commons/httpclient/TestAuthenticator.java 13 Jan 2004 12:53:14 -0000 @@ -76,6 +76,7 @@ import org.apache.commons.httpclient.auth.DigestScheme; import org.apache.commons.httpclient.auth.MalformedChallengeException; import org.apache.commons.httpclient.auth.NTLMScheme; +import org.apache.commons.httpclient.util.EncodingUtil; /** * Unit tests for {@link Authenticator}. @@ -262,8 +263,8 @@ authscheme.processChallenge(challenge); assertTrue(authenticate(authscheme, method, null, state)); assertTrue(null != method.getRequestHeader("Authorization")); - String expected = "Basic " + HttpConstants.getString( - Base64.encodeBase64(HttpConstants.getBytes("username:password"))); + String expected = "Basic " + EncodingUtil.getAsciiString( + Base64.encodeBase64(EncodingUtil.getAsciiBytes("username:password"))); assertEquals(expected,method.getRequestHeader("Authorization").getValue()); } @@ -274,8 +275,8 @@ HttpMethod method = new SimpleHttpMethod(new Header("WWW-Authenticate","Basic realm=\"realm1\"")); assertTrue(authenticate(new BasicScheme(), method, null, state)); assertTrue(null != method.getRequestHeader("Authorization")); - String expected = "Basic " + HttpConstants.getString( - Base64.encodeBase64(HttpConstants.getBytes("username:password"))); + String expected = "Basic " + EncodingUtil.getAsciiString( + Base64.encodeBase64(EncodingUtil.getAsciiBytes("username:password"))); assertEquals(expected,method.getRequestHeader("Authorization").getValue()); } @@ -288,8 +289,8 @@ authscheme.processChallenge(challenge); assertTrue(authenticate(authscheme, method, null, state)); assertTrue(null != method.getRequestHeader("Authorization")); - String expected = "Basic " + HttpConstants.getString( - Base64.encodeBase64(HttpConstants.getBytes("username:password"))); + String expected = "Basic " + EncodingUtil.getAsciiString( + Base64.encodeBase64(EncodingUtil.getAsciiBytes("username:password"))); assertEquals(expected,method.getRequestHeader("Authorization").getValue()); } @@ -302,7 +303,7 @@ UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("dh", buffer.toString()); assertEquals("Basic ZGg65C32Lfw=", - BasicScheme.authenticate(credentials, HttpConstants.DEFAULT_CONTENT_CHARSET)); + BasicScheme.authenticate(credentials, "ISO-8859-1")); } public void testBasicAuthenticationWithMutlipleRealms() throws Exception { @@ -319,16 +320,16 @@ HttpMethod method = new SimpleHttpMethod(new Header("WWW-Authenticate",challenge1)); assertTrue(authenticate(authscheme1, method, null, state)); assertTrue(null != method.getRequestHeader("Authorization")); - String expected = "Basic " + HttpConstants.getString( - Base64.encodeBase64(HttpConstants.getBytes("username:password"))); + String expected = "Basic " + EncodingUtil.getAsciiString( + Base64.encodeBase64(EncodingUtil.getAsciiBytes("username:password"))); assertEquals(expected,method.getRequestHeader("Authorization").getValue()); } { HttpMethod method = new SimpleHttpMethod(new Header("WWW-Authenticate", challenge2)); assertTrue(authenticate(authscheme2, method, null, state)); assertTrue(null != method.getRequestHeader("Authorization")); - String expected = "Basic " + HttpConstants.getString( - Base64.encodeBase64(HttpConstants.getBytes("uname2:password2"))); + String expected = "Basic " + EncodingUtil.getAsciiString( + Base64.encodeBase64(EncodingUtil.getAsciiBytes("uname2:password2"))); assertEquals(expected,method.getRequestHeader("Authorization").getValue()); } } @@ -340,8 +341,8 @@ assertTrue(authenticate(new BasicScheme(), method, null, state)); assertTrue(null != method.getRequestHeader("Authorization")); - String expected = "Basic " + HttpConstants.getString( - Base64.encodeBase64(HttpConstants.getBytes("username:password"))); + String expected = "Basic " + EncodingUtil.getAsciiString( + Base64.encodeBase64(EncodingUtil.getAsciiBytes("username:password"))); assertEquals(expected, method.getRequestHeader("Authorization").getValue()); } Index: test/org/apache/commons/httpclient/TestHttpParser.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpParser.java,v retrieving revision 1.1 diff -u -r1.1 TestHttpParser.java --- test/org/apache/commons/httpclient/TestHttpParser.java 19 Oct 2003 18:46:03 -0000 1.1 +++ test/org/apache/commons/httpclient/TestHttpParser.java 13 Jan 2004 12:53:14 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpParser.java,v 1.1 2003/10/19 18:46:03 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpParser.java,v 1.1 2003/10/19 18:46:03 olegk Exp $ * $Revision: 1.1 $ * $Date: 2003/10/19 18:46:03 $ * ==================================================================== @@ -75,6 +75,8 @@ */ public class TestHttpParser extends TestCase { + private static final String HTTP_ELEMENT_CHARSET = "US-ASCII"; + // ------------------------------------------------------------ Constructor public TestHttpParser(String testName) { super(testName); @@ -94,16 +96,16 @@ public void testReadHttpLine() throws Exception { InputStream instream = new ByteArrayInputStream( - "\r\r\nstuff\r\n".getBytes("US-ASCII")); - assertEquals("\r", HttpParser.readLine(instream)); - assertEquals("stuff", HttpParser.readLine(instream)); - assertEquals(null, HttpParser.readLine(instream)); + "\r\r\nstuff\r\n".getBytes(HTTP_ELEMENT_CHARSET)); + assertEquals("\r", HttpParser.readLine(instream, HTTP_ELEMENT_CHARSET)); + assertEquals("stuff", HttpParser.readLine(instream, HTTP_ELEMENT_CHARSET)); + assertEquals(null, HttpParser.readLine(instream, HTTP_ELEMENT_CHARSET)); instream = new ByteArrayInputStream( "\n\r\nstuff\r\n".getBytes("US-ASCII")); - assertEquals("", HttpParser.readLine(instream)); - assertEquals("", HttpParser.readLine(instream)); - assertEquals("stuff", HttpParser.readLine(instream)); - assertEquals(null, HttpParser.readLine(instream)); + assertEquals("", HttpParser.readLine(instream, HTTP_ELEMENT_CHARSET)); + assertEquals("", HttpParser.readLine(instream, HTTP_ELEMENT_CHARSET)); + assertEquals("stuff", HttpParser.readLine(instream, HTTP_ELEMENT_CHARSET)); + assertEquals(null, HttpParser.readLine(instream, HTTP_ELEMENT_CHARSET)); } } Index: test/org/apache/commons/httpclient/TestMethodCharEncoding.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodCharEncoding.java,v retrieving revision 1.5 diff -u -r1.5 TestMethodCharEncoding.java --- test/org/apache/commons/httpclient/TestMethodCharEncoding.java 11 Dec 2003 22:54:19 -0000 1.5 +++ test/org/apache/commons/httpclient/TestMethodCharEncoding.java 13 Jan 2004 12:53:15 -0000 @@ -80,7 +80,7 @@ public class TestMethodCharEncoding extends TestCase { - static final String CHARSET_DEFAULT = HttpConstants.DEFAULT_CONTENT_CHARSET; + static final String CHARSET_DEFAULT = "ISO-8859-1"; static final String CHARSET_ASCII = "US-ASCII"; static final String CHARSET_UTF8 = "UTF-8"; static final String CHARSET_KOI8_R = "KOI8_R"; Index: test/org/apache/commons/httpclient/TestStreams.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestStreams.java,v retrieving revision 1.12 diff -u -r1.12 TestStreams.java --- test/org/apache/commons/httpclient/TestStreams.java 17 Jul 2003 21:57:42 -0000 1.12 +++ test/org/apache/commons/httpclient/TestStreams.java 13 Jan 2004 12:53:15 -0000 @@ -73,10 +73,13 @@ import junit.framework.TestSuite; import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.util.EncodingUtil; public class TestStreams extends TestCase { + private static final String CONTENT_CHARSET = "ISO-8859-1"; + public TestStreams(String testName) { super(testName); } @@ -87,14 +90,15 @@ HttpMethod method = new SimpleHttpMethod(); //Test for when buffer is larger than chunk size - InputStream in = new ChunkedInputStream(new ByteArrayInputStream(HttpConstants.getBytes(correctInput)), method); + InputStream in = new ChunkedInputStream(new ByteArrayInputStream( + EncodingUtil.getBytes(correctInput, CONTENT_CHARSET)), method); byte[] buffer = new byte[300]; ByteArrayOutputStream out = new ByteArrayOutputStream(); int len; while ((len = in.read(buffer)) > 0) { out.write(buffer, 0, len); } - String result = HttpConstants.getContentString(out.toByteArray()); + String result = EncodingUtil.getString(out.toByteArray(), CONTENT_CHARSET); assertEquals(result, correctResult); Header footer = method.getResponseFooter("footer1"); assertEquals(footer.getValue(), "abcde"); @@ -105,13 +109,14 @@ method.recycle(); //Test for when buffer is smaller than chunk size. - in = new ChunkedInputStream(new ByteArrayInputStream(HttpConstants.getBytes(correctInput)), method); + in = new ChunkedInputStream(new ByteArrayInputStream( + EncodingUtil.getBytes(correctInput, CONTENT_CHARSET)), method); buffer = new byte[7]; out = new ByteArrayOutputStream(); while ((len = in.read(buffer)) > 0) { out.write(buffer, 0, len); } - result = HttpConstants.getContentString(out.toByteArray()); + result = EncodingUtil.getString(out.toByteArray(), CONTENT_CHARSET); assertEquals(result, correctResult); footer = method.getResponseFooter("footer1"); assertEquals(footer.getValue(), "abcde"); @@ -124,7 +129,8 @@ String corrupInput = "10;key=\"value\"\r\n123456789012345\r\n5\r\n12345\r\n0\r\nFooter1: abcde\r\nFooter2: fghij\r\n"; HttpMethod method = new SimpleHttpMethod(); - InputStream in = new ChunkedInputStream(new ByteArrayInputStream(HttpConstants.getBytes(corrupInput)), method); + InputStream in = new ChunkedInputStream(new ByteArrayInputStream( + EncodingUtil.getBytes(corrupInput, CONTENT_CHARSET)), method); byte[] buffer = new byte[300]; ByteArrayOutputStream out = new ByteArrayOutputStream(); int len; @@ -142,7 +148,8 @@ String input = "0\r\n"; HttpMethod method = new SimpleHttpMethod(); - InputStream in = new ChunkedInputStream(new ByteArrayInputStream(HttpConstants.getBytes(input)), method); + InputStream in = new ChunkedInputStream(new ByteArrayInputStream( + EncodingUtil.getBytes(input, CONTENT_CHARSET)), method); byte[] buffer = new byte[300]; ByteArrayOutputStream out = new ByteArrayOutputStream(); int len; @@ -154,12 +161,13 @@ public void testContentLengthInputStream() throws IOException { String correct = "1234567890123456"; - InputStream in = new ContentLengthInputStream(new ByteArrayInputStream(HttpConstants.getBytes(correct)), 10L); + InputStream in = new ContentLengthInputStream(new ByteArrayInputStream( + EncodingUtil.getBytes(correct, CONTENT_CHARSET)), 10L); byte[] buffer = new byte[50]; int len = in.read(buffer); ByteArrayOutputStream out = new ByteArrayOutputStream(); out.write(buffer, 0, len); - String result = HttpConstants.getContentString(out.toByteArray()); + String result = EncodingUtil.getString(out.toByteArray(), CONTENT_CHARSET); assertEquals(result, "1234567890"); } @@ -167,7 +175,7 @@ String input = "76126;27823abcd;:q38a-\nkjc\rk%1ad\tkh/asdui\r\njkh+?\\suweb"; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); OutputStream out = new ChunkedOutputStream(buffer); - out.write(HttpConstants.getBytes(input)); + out.write(EncodingUtil.getBytes(input, CONTENT_CHARSET)); out.close(); buffer.close(); InputStream in = new ChunkedInputStream(new ByteArrayInputStream(buffer.toByteArray()), new GetMethod()); @@ -179,7 +187,7 @@ result.write(d, 0, len); } - String output = HttpConstants.getContentString(result.toByteArray()); + String output = EncodingUtil.getString(result.toByteArray(), CONTENT_CHARSET); assertEquals(input, output); } Index: test/org/apache/commons/httpclient/TestWebappMethods.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappMethods.java,v retrieving revision 1.18 diff -u -r1.18 TestWebappMethods.java --- test/org/apache/commons/httpclient/TestWebappMethods.java 17 Jul 2003 21:57:42 -0000 1.18 +++ test/org/apache/commons/httpclient/TestWebappMethods.java 13 Jan 2004 12:53:16 -0000 @@ -67,6 +67,7 @@ import junit.framework.*; import org.apache.commons.httpclient.methods.*; +import org.apache.commons.httpclient.util.EncodingUtil; /** * This suite of tests depends upon the httpclienttest webapp, @@ -325,7 +326,7 @@ PostMethod method = new PostMethod("/" + getWebappContext() + "/body"); String bodyStr = "quote=It+was+the+best+of+times%2C+it+was+the+worst+of+times."; - byte[] body = HttpConstants.getContentBytes(bodyStr); + byte[] body = EncodingUtil.getBytes(bodyStr, "ISO-8859-1"); method.setRequestBody(new ByteArrayInputStream(body)); method.setRequestContentLength((long)body.length); @@ -396,7 +397,7 @@ PostMethod method = new PostMethod("/" + getWebappContext() + "/body"); String bodyStr = "Like, hello, and stuff"; - byte [] body = HttpConstants.getContentBytes(bodyStr); + byte [] body = EncodingUtil.getBytes(bodyStr, "ISO-8859-1"); method.setRequestHeader("Content-Type", "text/plain"); method.setRequestBody(new ByteArrayInputStream(body)); method.setRequestContentLength((long)body.length); Index: test/org/apache/commons/httpclient/TestWebappRedirect.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappRedirect.java,v retrieving revision 1.19 diff -u -r1.19 TestWebappRedirect.java --- test/org/apache/commons/httpclient/TestWebappRedirect.java 17 Jul 2003 21:57:42 -0000 1.19 +++ test/org/apache/commons/httpclient/TestWebappRedirect.java 13 Jan 2004 12:53:16 -0000 @@ -70,6 +70,7 @@ import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.PutMethod; +import org.apache.commons.httpclient.util.EncodingUtil; import org.apache.commons.httpclient.util.URIUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -227,7 +228,7 @@ method.setQueryString("to=" + URIUtil.encodeWithinQuery( client.getHostConfiguration().getHostURL() + "/" + getWebappContext() + "/params?foo=bar&bar=foo")); - byte[] body = HttpConstants.getContentBytes(bodyStr); + byte[] body = EncodingUtil.getBytes(bodyStr, "ISO-8859-1"); method.setRequestBody(new ByteArrayInputStream(body)); method.setRequestContentLength((long)body.length); //unbuffered request Index: test/org/apache/commons/httpclient/server/SimpleHttpServerConnection.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/server/SimpleHttpServerConnection.java,v retrieving revision 1.3 diff -u -r1.3 SimpleHttpServerConnection.java --- test/org/apache/commons/httpclient/server/SimpleHttpServerConnection.java 11 Dec 2003 09:19:18 -0000 1.3 +++ test/org/apache/commons/httpclient/server/SimpleHttpServerConnection.java 13 Jan 2004 12:53:16 -0000 @@ -84,6 +84,7 @@ public class SimpleHttpServerConnection implements Runnable { private static final Log LOG = LogFactory.getLog(SimpleHttpServerConnection.class); + private static final String HTTP_ELEMENT_CHARSET = "US-ASCII"; private SimpleHttpServer server; private Socket socket; @@ -180,7 +181,7 @@ private void readRequest() throws IOException { String line; do { - line = HttpParser.readLine(in); + line = HttpParser.readLine(in, HTTP_ELEMENT_CHARSET); } while (line != null && line.length() == 0); if (line == null) { @@ -190,7 +191,7 @@ try { requestLine = RequestLine.parseLine(line); - headers = HttpParser.parseHeaders(in); + headers = HttpParser.parseHeaders(in, HTTP_ELEMENT_CHARSET); } catch (IOException e) { connectionClose(); ErrorResponse.getInstance().getResponse(HttpStatus.SC_BAD_REQUEST).processRequest(this); Index: test/org/apache/commons/httpclient/server/TransparentProxyRequestHandler.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/server/TransparentProxyRequestHandler.java,v retrieving revision 1.3 diff -u -r1.3 TransparentProxyRequestHandler.java --- test/org/apache/commons/httpclient/server/TransparentProxyRequestHandler.java 11 Dec 2003 09:19:18 -0000 1.3 +++ test/org/apache/commons/httpclient/server/TransparentProxyRequestHandler.java 13 Jan 2004 12:53:16 -0000 @@ -72,7 +72,6 @@ import java.net.Socket; import org.apache.commons.httpclient.Header; -import org.apache.commons.httpclient.HttpConstants; import org.apache.commons.httpclient.HttpURL; import org.apache.commons.httpclient.URI; @@ -122,7 +121,7 @@ private void sendHeaders(Header[] headers, OutputStream os) throws IOException { Writer out; try { - out = new OutputStreamWriter(os, HttpConstants.HTTP_ELEMENT_CHARSET); + out = new OutputStreamWriter(os, "US-ASCII"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.toString()); }