diff --ignore-space -uNr src.org/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java src/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java --- src.org/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java 2004-07-28 16:42:50.000000000 +0900 +++ src/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java 2004-07-30 22:52:34.000000000 +0900 @@ -86,6 +86,9 @@ /** The parameters for this method */ private final List parameters = new ArrayList(); + /** character encoding for header */ + private String headerEncoding = null; + /** * No-arg constructor. */ @@ -151,6 +154,8 @@ public void addParameter(String parameterName, String parameterValue) { LOG.trace("enter addParameter(String parameterName, String parameterValue)"); Part param = new StringPart(parameterName, parameterValue); + param.setHeaderEncoding(headerEncoding); + param.setBodyEncoding(headerEncoding); parameters.add(param); } @@ -165,7 +170,7 @@ throws FileNotFoundException { LOG.trace("enter MultipartPostMethod.addParameter(String parameterName, " + "File parameterFile)"); - Part param = new FilePart(parameterName, parameterFile); + Part param = new FilePart(parameterName, parameterFile, headerEncoding); parameters.add(param); } @@ -181,7 +186,7 @@ throws FileNotFoundException { LOG.trace("enter MultipartPostMethod.addParameter(String parameterName, " + "String fileName, File parameterFile)"); - Part param = new FilePart(parameterName, fileName, parameterFile); + Part param = new FilePart(parameterName, fileName, parameterFile ,headerEncoding); parameters.add(param); } @@ -192,6 +197,7 @@ */ public void addPart (final Part part) { LOG.trace("enter addPart(Part part)"); + part.setHeaderEncoding(headerEncoding); parameters.add(part); } @@ -298,4 +304,21 @@ super.recycle(); parameters.clear(); } + + /** + * get header character encoding. + * @return charset charset for Header. + */ + public String getHeaderEncoding(){ + return headerEncoding; + } + + /** + * get header character encoding. + * @charset header character encoding. + */ + public void setHeaderEncoding(String charset){ + this.headerEncoding = charset; + } + } diff --ignore-space -uNr src.org/java/org/apache/commons/httpclient/methods/multipart/FilePart.java src/java/org/apache/commons/httpclient/methods/multipart/FilePart.java --- src.org/java/org/apache/commons/httpclient/methods/multipart/FilePart.java 2004-07-28 16:42:50.000000000 +0900 +++ src/java/org/apache/commons/httpclient/methods/multipart/FilePart.java 2004-07-30 22:19:46.000000000 +0900 @@ -73,8 +73,7 @@ protected static final String FILE_NAME = "; filename="; /** Attachment's file name as a byte array */ - protected static final byte[] FILE_NAME_BYTES = - HttpConstants.getAsciiBytes(FILE_NAME); + protected static final byte[] FILE_NAME_BYTES = HttpConstants.getAsciiBytes(FILE_NAME); /** Source of the file part. */ private PartSource source; @@ -85,18 +84,17 @@ * @param name the name for this part * @param partSource the source for this part * @param contentType the content type for this part, if null the - * {@link #DEFAULT_CONTENT_TYPE default} is used - * @param charset the charset encoding for this part, if null the - * {@link #DEFAULT_CHARSET default} is used - */ - public FilePart(String name, PartSource partSource, String contentType, String charset) { - - super( - name, - contentType == null ? DEFAULT_CONTENT_TYPE : contentType, - charset == null ? DEFAULT_CHARSET : charset, - DEFAULT_TRANSFER_ENCODING - ); + * {@link #DEFAULT_CONTENT_TYPE default}is used + * @param charset + * the charset encoding for this part, if null the + * {@link #DEFAULT_CHARSET default}is used + */ + public FilePart(String name, PartSource partSource, String contentType, + String bodyEncoding) { + + super(name, contentType == null ? DEFAULT_CONTENT_TYPE : contentType, + bodyEncoding == null ? DEFAULT_CHARSET : bodyEncoding, + DEFAULT_TRANSFER_ENCODING); if (partSource == null) { throw new IllegalArgumentException("Source may not be null"); @@ -123,11 +121,11 @@ * @param name the name of the file part * @param file the file to post * - * @throws FileNotFoundException if the file is not a normal - * file or if it is not readable. + * @throws FileNotFoundException + * if the file is not a normal file or if it is not + * readable. */ - public FilePart(String name, File file) - throws FileNotFoundException { + public FilePart(String name, File file) throws FileNotFoundException { this(name, new FilePartSource(file), null, null); } @@ -137,27 +135,33 @@ * @param name the name of the file part * @param file the file to post * @param contentType the content type for this part, if null the - * {@link #DEFAULT_CONTENT_TYPE default} is used - * @param charset the charset encoding for this part, if null the - * {@link #DEFAULT_CHARSET default} is used - * - * @throws FileNotFoundException if the file is not a normal - * file or if it is not readable. - */ - public FilePart(String name, File file, String contentType, String charset) - throws FileNotFoundException { - this(name, new FilePartSource(file), contentType, charset); + * {@link #DEFAULT_CONTENT_TYPE default}is used + * @param the + * charset encoding for this part, if null the + * {@link #DEFAULT_CHARSET default}is used + * + * @throws FileNotFoundException + * if the file is not a normal file or if it is not + * readable. + */ + public FilePart(String name, File file, String contentType, + String bodyEncoding) throws FileNotFoundException { + this(name, new FilePartSource(file), contentType, bodyEncoding); } /** * FilePart Constructor. * - * @param name the name of the file part - * @param fileName the file name - * @param file the file to post - * - * @throws FileNotFoundException if the file is not a normal - * file or if it is not readable. + * @param name + * the name of the file part + * @param fileName + * the file name + * @param file + * the file to post + * + * @throws FileNotFoundException + * if the file is not a normal file or if it is not + * readable. */ public FilePart(String name, String fileName, File file) throws FileNotFoundException { @@ -167,45 +171,89 @@ /** * FilePart Constructor. * - * @param name the name of the file part - * @param fileName the file name - * @param file the file to post - * @param contentType the content type for this part, if null the - * {@link #DEFAULT_CONTENT_TYPE default} is used - * @param charset the charset encoding for this part, if null the - * {@link #DEFAULT_CHARSET default} is used + * @param name + * the name of the file part + * @param fileName + * the file name + * @param file + * the file to post + * @param charset + * the charset + * + * @throws FileNotFoundException + * if the file is not a normal file or if it is not + * readable. + */ + public FilePart(String name, String fileName, File file, String bodyEncoding) + throws FileNotFoundException { + this(name, new FilePartSource(fileName, file), null, bodyEncoding); + } + + /** + * FilePart Constructor. * - * @throws FileNotFoundException if the file is not a normal - * file or if it is not readable. + * @param name + * the name of the file part + * @param fileName + * the file name + * @param file + * the file to post + * @param contentType + * the content type for this part, if null the + * {@link #DEFAULT_CONTENT_TYPE default}is used + * @param charset + * the charset encoding for this part, if null the + * {@link #DEFAULT_CHARSET default}is used + * + * @throws FileNotFoundException + * if the file is not a normal file or if it is not + * readable. */ - public FilePart(String name, String fileName, File file, String contentType, String charset) + public FilePart(String name, String fileName, File file, + String contentType, String bodyEncoding) throws FileNotFoundException { - this(name, new FilePartSource(fileName, file), contentType, charset); + this(name, new FilePartSource(fileName, file), contentType, + bodyEncoding); + } + + public FilePart(String name, File fileName, String bodyEncoding) + throws FileNotFoundException { + this(name, fileName, null, bodyEncoding); } /** * Write the disposition header to the output stream - * @param out The output stream - * @throws IOException If an IO problem occurs + * + * @param out + * The output stream + * @throws IOException + * If an IO problem occurs * @see Part#sendDispositionHeader(OutputStream) */ - protected void sendDispositionHeader(OutputStream out) - throws IOException { + protected void sendDispositionHeader(OutputStream out) throws IOException { LOG.trace("enter sendDispositionHeader(OutputStream out)"); super.sendDispositionHeader(out); String filename = this.source.getFileName(); if (filename != null) { out.write(FILE_NAME_BYTES); out.write(QUOTE_BYTES); + String charset = getHeaderEncoding(); + if (charset != null && charset.length() > 0) { + out.write(filename.getBytes(charset)); + } else { out.write(HttpConstants.getAsciiBytes(filename)); + } out.write(QUOTE_BYTES); } } /** * Write the data in "source" to the specified stream. - * @param out The output stream. - * @throws IOException if an IO problem occurs. + * + * @param out + * The output stream. + * @throws IOException + * if an IO problem occurs. * @see org.apache.commons.httpclient.methods.multipart.Part#sendData(OutputStream) */ protected void sendData(OutputStream out) throws IOException { @@ -244,8 +292,10 @@ /** * Return the length of the data. + * * @return The length. - * @throws IOException if an IO problem occurs + * @throws IOException + * if an IO problem occurs * @see org.apache.commons.httpclient.methods.multipart.Part#lengthOfData() */ protected long lengthOfData() throws IOException { diff --ignore-space -uNr src.org/java/org/apache/commons/httpclient/methods/multipart/Part.java src/java/org/apache/commons/httpclient/methods/multipart/Part.java --- src.org/java/org/apache/commons/httpclient/methods/multipart/Part.java 2004-07-28 16:42:50.000000000 +0900 +++ src/java/org/apache/commons/httpclient/methods/multipart/Part.java 2004-07-30 17:09:52.000000000 +0900 @@ -34,7 +34,9 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.util.logging.ConsoleHandler; +import org.apache.axis.message.BodyBuilder; import org.apache.commons.httpclient.HttpConstants; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -136,7 +138,24 @@ * @return the character encoding, or null to exclude the character * encoding header */ - public abstract String getCharSet(); + public abstract String getHeaderEncoding(); + + /** + * Set the character encoding for header of this part. + */ + public abstract void setHeaderEncoding(String charset); + + /** + * Return the body character encoding of this part . + * @return the character encoding, or null to exclude the character + * encoding header + */ + public abstract String getBodyEncoding(); + + /** + * Set the body character encoding of this part. + */ + public abstract void setBodyEncoding(String charset); /** * Return the transfer encoding of this part. @@ -166,7 +185,13 @@ LOG.trace("enter sendDispositionHeader(OutputStream out)"); out.write(CONTENT_DISPOSITION_BYTES); out.write(QUOTE_BYTES); + String charset = getHeaderEncoding(); + if ( charset!= null && charset.length()>0) { + out.write(getName().getBytes(charset)); + } else { out.write(HttpConstants.getAsciiBytes(getName())); + } + out.write(QUOTE_BYTES); } @@ -182,7 +207,7 @@ out.write(CRLF_BYTES); out.write(CONTENT_TYPE_BYTES); out.write(HttpConstants.getAsciiBytes(contentType)); - String charSet = getCharSet(); + String charSet = getBodyEncoding(); if (charSet != null) { out.write(CHARSET_BYTES); out.write(HttpConstants.getAsciiBytes(charSet)); diff --ignore-space -uNr src.org/java/org/apache/commons/httpclient/methods/multipart/PartBase.java src/java/org/apache/commons/httpclient/methods/multipart/PartBase.java --- src.org/java/org/apache/commons/httpclient/methods/multipart/PartBase.java 2004-07-28 16:42:50.000000000 +0900 +++ src/java/org/apache/commons/httpclient/methods/multipart/PartBase.java 2004-07-30 12:19:26.000000000 +0900 @@ -46,7 +46,10 @@ private String contentType; /** Content encoding of the file part. */ - private String charSet; + private String headerEncoding; + + /** Content encoding of the file part. */ + private String bodyEncoding; /** The transfer encoding. */ private String transferEncoding; @@ -59,14 +62,14 @@ * @param charSet The character encoding, or null * @param transferEncoding The transfer encoding, or null */ - public PartBase(String name, String contentType, String charSet, String transferEncoding) { + public PartBase(String name, String contentType, String bodyEncoding, String transferEncoding) { if (name == null) { throw new IllegalArgumentException("Name must not be null"); } this.name = name; this.contentType = contentType; - this.charSet = charSet; + this.bodyEncoding = bodyEncoding; this.transferEncoding = transferEncoding; } @@ -88,11 +91,19 @@ } /** - * Return the character encoding of this part. + * Return the header character encoding of this part. + * @return String The name. + */ + public String getHeaderEncoding() { + return this.headerEncoding; + } + + /** + * Return the body character encoding of this part. * @return String The name. */ - public String getCharSet() { - return this.charSet; + public String getBodyEncoding() { + return this.bodyEncoding; } /** @@ -109,8 +120,18 @@ * @param charSet the character encoding, or null to exclude the character * encoding header */ - public void setCharSet(String charSet) { - this.charSet = charSet; + public void setHeaderEncoding(String charSet) { + this.headerEncoding = charSet; + } + + /** + * Sets the character encoding. + * + * @param charSet the character encoding, or null to exclude the character + * encoding header + */ + public void setBodyEncoding(String charset) { + bodyEncoding = charset; } /** diff --ignore-space -uNr src.org/java/org/apache/commons/httpclient/methods/multipart/StringPart.java src/java/org/apache/commons/httpclient/methods/multipart/StringPart.java --- src.org/java/org/apache/commons/httpclient/methods/multipart/StringPart.java 2004-07-28 16:42:50.000000000 +0900 +++ src/java/org/apache/commons/httpclient/methods/multipart/StringPart.java 2004-07-30 22:27:18.000000000 +0900 @@ -83,6 +83,7 @@ charset == null ? DEFAULT_CHARSET : charset, DEFAULT_TRANSFER_ENCODING ); + if (value == null) { throw new IllegalArgumentException("Value may not be null"); } @@ -111,7 +112,7 @@ */ private byte[] getContent() { if (content == null) { - content = HttpConstants.getContentBytes(value, getCharSet()); + content = HttpConstants.getContentBytes(value, getHeaderEncoding()); } return content; } @@ -137,12 +138,4 @@ return getContent().length; } - /* (non-Javadoc) - * @see org.apache.commons.httpclient.methods.multipart.BasePart#setCharSet(java.lang.String) - */ - public void setCharSet(String charSet) { - super.setCharSet(charSet); - this.content = null; - } - }