diff -uNr .\java\org\apache\commons\httpclient\methods\multipart\ByteArrayPartSource.java ../../commons-httpclient-3.0-rc4.orig/src\java\org\apache\commons\httpclient\methods\multipart\ByteArrayPartSource.java
--- .\java\org\apache\commons\httpclient\methods\multipart\ByteArrayPartSource.java Thu Nov 10 12:45:50 2005
+++ ../../commons-httpclient-3.0-rc4.orig/src\java\org\apache\commons\httpclient\methods\multipart\ByteArrayPartSource.java Mon Oct 10 22:09:10 2005
@@ -83,11 +83,4 @@
return new ByteArrayInputStream(bytes);
}
- /**
- * @see PartSource#isRepeatable()
- */
- public boolean isRepeatable() {
- return true;
- }
-
}
diff -uNr .\java\org\apache\commons\httpclient\methods\multipart\FilePart.java ../../commons-httpclient-3.0-rc4.orig/src\java\org\apache\commons\httpclient\methods\multipart\FilePart.java
--- .\java\org\apache\commons\httpclient\methods\multipart\FilePart.java Thu Nov 10 12:46:33 2005
+++ ../../commons-httpclient-3.0-rc4.orig/src\java\org\apache\commons\httpclient\methods\multipart\FilePart.java Mon Oct 10 22:09:10 2005
@@ -99,6 +99,9 @@
if (partSource == null) {
throw new IllegalArgumentException("Source may not be null");
}
+ if (partSource.getLength() < 0) {
+ throw new IllegalArgumentException("Source length must be >= 0");
+ }
this.source = partSource;
}
@@ -248,15 +251,4 @@
return source.getLength();
}
- /**
- * Tests if this part can be sent more than once.
- * @return true if {@link #sendData(OutputStream)} can be successfully called
- * more than once.
- * @since 3.0
- */
- public boolean isRepeatable() {
- LOG.trace("enter isRepeatable()");
- return source.isRepeatable();
- }
-
}
diff -uNr .\java\org\apache\commons\httpclient\methods\multipart\FilePartSource.java ../../commons-httpclient-3.0-rc4.orig/src\java\org\apache\commons\httpclient\methods\multipart\FilePartSource.java
--- .\java\org\apache\commons\httpclient\methods\multipart\FilePartSource.java Thu Nov 10 12:47:00 2005
+++ ../../commons-httpclient-3.0-rc4.orig/src\java\org\apache\commons\httpclient\methods\multipart\FilePartSource.java Mon Oct 10 22:09:12 2005
@@ -126,12 +126,5 @@
return new ByteArrayInputStream(new byte[] {});
}
}
-
- /**
- * @see PartSource#isRepeatable()
- */
- public boolean isRepeatable() {
- return true;
- }
}
diff -uNr .\java\org\apache\commons\httpclient\methods\multipart\Part.java ../../commons-httpclient-3.0-rc4.orig/src\java\org\apache\commons\httpclient\methods\multipart\Part.java
--- .\java\org\apache\commons\httpclient\methods\multipart\Part.java Thu Nov 10 12:47:58 2005
+++ ../../commons-httpclient-3.0-rc4.orig/src\java\org\apache\commons\httpclient\methods\multipart\Part.java Mon Oct 10 22:09:12 2005
@@ -190,7 +190,9 @@
* more than once.
* @since 3.0
*/
- public abstract boolean isRepeatable();
+ public boolean isRepeatable() {
+ return true;
+ }
/**
* Write the start to the specified output stream
@@ -321,9 +323,6 @@
*/
public long length() throws IOException {
LOG.trace("enter length()");
- if (lengthOfData() < 0) {
- return -1;
- }
ByteArrayOutputStream overhead = new ByteArrayOutputStream();
sendStart(overhead);
sendDispositionHeader(overhead);
@@ -420,11 +419,7 @@
for (int i = 0; i < parts.length; i++) {
// set the part boundary before we calculate the part's length
parts[i].setPartBoundary(partBoundary);
- long l = parts[i].length();
- if (l < 0) {
- return -1;
- }
- total += l;
+ total += parts[i].length();
}
total += EXTRA_BYTES.length;
total += partBoundary.length;
diff -uNr .\java\org\apache\commons\httpclient\methods\multipart\PartSource.java ../../commons-httpclient-3.0-rc4.orig/src\java\org\apache\commons\httpclient\methods\multipart\PartSource.java
--- .\java\org\apache\commons\httpclient\methods\multipart\PartSource.java Thu Nov 10 12:48:49 2005
+++ ../../commons-httpclient-3.0-rc4.orig/src\java\org\apache\commons\httpclient\methods\multipart\PartSource.java Mon Oct 10 22:09:12 2005
@@ -58,16 +58,6 @@
String getFileName();
/**
- * Tests if this part can be sent more than once.
- *
- * @return true if {@link #createInputStream()} can be successfully called
- * more than once.
- *
- * @since 3.0
- */
- boolean isRepeatable();
-
- /**
* Gets a new InputStream for reading this source. This method can be
* called more than once and should therefore return a new stream every
* time.
diff -uNr .\java\org\apache\commons\httpclient\methods\multipart\StringPart.java ../../commons-httpclient-3.0-rc4.orig/src\java\org\apache\commons\httpclient\methods\multipart\StringPart.java
--- .\java\org\apache\commons\httpclient\methods\multipart\StringPart.java Thu Nov 10 12:50:02 2005
+++ ../../commons-httpclient-3.0-rc4.orig/src\java\org\apache\commons\httpclient\methods\multipart\StringPart.java Mon Oct 10 22:09:12 2005
@@ -144,14 +144,4 @@
this.content = null;
}
- /**
- * Return true as this part can be sent more than once.
- * @return true as {@link #sendData(OutputStream)} can be successfully called
- * more than once.
- * @since 3.0
- */
- public boolean isRepeatable() {
- return true;
- }
-
}
diff -uNr .\test\org\apache\commons\httpclient\TestMultipartPost.java ../../commons-httpclient-3.0-rc4.orig/src\test\org\apache\commons\httpclient\TestMultipartPost.java
--- .\test\org\apache\commons\httpclient\TestMultipartPost.java Thu Nov 10 12:50:55 2005
+++ ../../commons-httpclient-3.0-rc4.orig/src\test\org\apache\commons\httpclient\TestMultipartPost.java Mon Oct 10 22:09:12 2005
@@ -31,9 +31,7 @@
package org.apache.commons.httpclient;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
-import java.io.InputStream;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -43,7 +41,6 @@
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
-import org.apache.commons.httpclient.methods.multipart.PartSource;
import org.apache.commons.httpclient.methods.multipart.StringPart;
/**
@@ -121,63 +118,5 @@
assertTrue(body.indexOf("Content-Transfer-Encoding: binary") >= 0);
assertTrue(body.indexOf("Hello") >= 0);
}
-
- /**
- * Test that the body consisting of a file part of unknown length can be posted.
- */
-
- public class TestPartSource implements PartSource {
- private String fileName;
- private byte[] data;
-
- public TestPartSource(String fileName, byte[] data) {
- this.fileName = fileName;
- this.data = data;
- }
-
- public long getLength() {
- return -1;
- }
-
- public String getFileName() {
- return fileName;
- }
-
- public boolean isRepeatable() {
- return true;
- }
-
- public InputStream createInputStream() throws IOException {
- return new ByteArrayInputStream(data);
- }
-
- }
-
- public void testPostFilePartUnknownLength() throws Exception {
-
- this.server.setHttpService(new EchoService());
-
- String enc = "ISO-8859-1";
- PostMethod method = new PostMethod();
- byte[] content = "Hello".getBytes(enc);
- MultipartRequestEntity entity = new MultipartRequestEntity(
- new Part[] {
- new FilePart(
- "param1",
- new TestPartSource("filename.txt", content),
- "text/plain",
- enc) },
- method.getParams());
- method.setRequestEntity(entity);
-
- client.executeMethod(method);
-
- assertEquals(200,method.getStatusCode());
- String body = method.getResponseBodyAsString();
- assertTrue(body.indexOf("Content-Disposition: form-data; name=\"param1\"; filename=\"filename.txt\"") >= 0);
- assertTrue(body.indexOf("Content-Type: text/plain; charset="+enc) >= 0);
- assertTrue(body.indexOf("Content-Transfer-Encoding: binary") >= 0);
- assertTrue(body.indexOf("Hello") >= 0);
- }
-
}
+