diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index dfb81fa8a5f..e0da92c0478 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -306,6 +306,10 @@ Bug Fixes
bigger then the max int/float were used.
(Erbi Hanka, hossman)
+* SOLR-2230: CommonsHttpSolrServer.addFile could not be used to send
+ multiple files in a single request.
+ (Stephan Günther, hossman)
+
Other Changes
----------------------
diff --git a/solr/src/solrj/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.java b/solr/src/solrj/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.java
index 2f1c19a6c5b..5a928857f5f 100644
--- a/solr/src/solrj/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.java
+++ b/solr/src/solrj/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.java
@@ -32,11 +32,11 @@ import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
+import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.Part;
-import org.apache.commons.httpclient.methods.multipart.PartBase;
+import org.apache.commons.httpclient.methods.multipart.PartSource;
import org.apache.commons.httpclient.methods.multipart.StringPart;
import org.apache.commons.httpclient.params.HttpMethodParams;
-import org.apache.commons.io.IOUtils;
import org.apache.solr.client.solrj.ResponseParser;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServer;
@@ -324,25 +324,24 @@ public class CommonsHttpSolrServer extends SolrServer
final ContentStream c = content;
String charSet = null;
- String transferEncoding = null;
- parts.add(new PartBase(c.getName(), c.getContentType(),
- charSet, transferEncoding) {
+ PartSource source = new PartSource() {
@Override
- protected long lengthOfData() throws IOException {
+ public long getLength() {
return c.getSize();
}
+
+ public String getFileName() {
+ return c.getName();
+ }
@Override
- protected void sendData(OutputStream out)
- throws IOException {
- InputStream in = c.getStream();
- try {
- IOUtils.copy(in, out);
- } finally {
- in.close();
- }
+ public InputStream createInputStream() throws IOException {
+ return c.getStream();
}
- });
+ };
+
+ parts.add(new FilePart(c.getName(), source,
+ c.getContentType(), charSet));
}
}
if (parts.size() > 0) {
diff --git a/solr/src/test-files/docs1.xml b/solr/src/test-files/docs1.xml
new file mode 100644
index 00000000000..3c5448d9dcf
--- /dev/null
+++ b/solr/src/test-files/docs1.xml
@@ -0,0 +1,56 @@
+
+
+
+
+ SP2514N
+ Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133
+ Samsung Electronics Co. Ltd.
+
+ samsung
+ electronics
+ hard drive
+ 7200RPM, 8MB cache, IDE Ultra ATA-133
+ NoiseGuard, SilentSeek technology, Fluid Dynamic Bearing (FDB) motor
+ 92
+ 6
+ true
+ 2006-02-13T15:26:37Z
+
+ 35.0752,-97.032
+
+
+
+ 6H500F0
+ Maxtor DiamondMax 11 - hard drive - 500 GB - SATA-300
+ Maxtor Corp.
+
+ maxtor
+ electronics
+ hard drive
+ SATA 3.0Gb/s, NCQ
+ 8.5ms seek
+ 16MB cache
+ 350
+ 6
+ true
+
+ 45.17614,-93.87341
+ 2006-02-13T15:26:37Z
+
+
+
diff --git a/solr/src/test-files/docs2.xml b/solr/src/test-files/docs2.xml
new file mode 100644
index 00000000000..0b89d6785c2
--- /dev/null
+++ b/solr/src/test-files/docs2.xml
@@ -0,0 +1,77 @@
+
+
+
+
+ TWINX2048-3200PRO
+ CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory - Retail
+ Corsair Microsystems Inc.
+
+ corsair
+ electronics
+ memory
+ CAS latency 2, 2-3-3-6 timing, 2.75v, unbuffered, heat-spreader
+ 185
+ 5
+ true
+
+ 37.7752,-122.4232
+ 2006-02-13T15:26:37Z
+
+
+ electronics|6.0 memory|3.0
+
+
+
+ VS1GB400C3
+ CORSAIR ValueSelect 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - Retail
+ Corsair Microsystems Inc.
+
+ corsair
+ electronics
+ memory
+ 74.99
+ 7
+ true
+
+ 37.7752,-100.0232
+ 2006-02-13T15:26:37Z
+
+ electronics|4.0 memory|2.0
+
+
+
+ VDBDB1A16
+ A-DATA V-Series 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - OEM
+ A-DATA Technology Inc.
+
+ corsair
+ electronics
+ memory
+ CAS latency 3, 2.7v
+
+ 0
+ true
+
+ 45.18414,-93.88141
+ 2006-02-13T15:26:37Z
+
+ electronics|0.9 memory|0.1
+
+
+
+
diff --git a/solr/src/test/org/apache/solr/client/solrj/SolrExampleTests.java b/solr/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
index e19992a4a21..1f28fa120d5 100644
--- a/solr/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
+++ b/solr/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
@@ -446,6 +446,24 @@ abstract public class SolrExampleTests extends SolrJettyTestBase
assertNotNull("Couldn't upload books.csv", result);
rsp = server.query( new SolrQuery( "*:*") );
Assert.assertEquals( 10, rsp.getResults().getNumFound() );
+ }
+
+ @Test
+ public void testMultiContentStreamRequest() throws Exception {
+ SolrServer server = getSolrServer();
+ server.deleteByQuery( "*:*" );// delete everything!
+ server.commit();
+ QueryResponse rsp = server.query( new SolrQuery( "*:*") );
+ Assert.assertEquals( 0, rsp.getResults().getNumFound() );
+
+ ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update");
+ up.addFile(getFile("docs1.xml")); // 2
+ up.addFile(getFile("docs2.xml")); // 3
+ up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
+ NamedList