mirror of https://github.com/apache/lucene.git
SOLR-2230: fix CommonsHttpSolrServer so that multiple addFile calls work
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1144038 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fd337c605c
commit
dd55ad4397
|
@ -306,6 +306,10 @@ Bug Fixes
|
||||||
bigger then the max int/float were used.
|
bigger then the max int/float were used.
|
||||||
(Erbi Hanka, hossman)
|
(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
|
Other Changes
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
|
|
|
@ -32,11 +32,11 @@ import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
|
||||||
import org.apache.commons.httpclient.methods.PostMethod;
|
import org.apache.commons.httpclient.methods.PostMethod;
|
||||||
import org.apache.commons.httpclient.methods.RequestEntity;
|
import org.apache.commons.httpclient.methods.RequestEntity;
|
||||||
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
|
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.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.methods.multipart.StringPart;
|
||||||
import org.apache.commons.httpclient.params.HttpMethodParams;
|
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.ResponseParser;
|
||||||
import org.apache.solr.client.solrj.SolrRequest;
|
import org.apache.solr.client.solrj.SolrRequest;
|
||||||
import org.apache.solr.client.solrj.SolrServer;
|
import org.apache.solr.client.solrj.SolrServer;
|
||||||
|
@ -324,25 +324,24 @@ public class CommonsHttpSolrServer extends SolrServer
|
||||||
final ContentStream c = content;
|
final ContentStream c = content;
|
||||||
|
|
||||||
String charSet = null;
|
String charSet = null;
|
||||||
String transferEncoding = null;
|
PartSource source = new PartSource() {
|
||||||
parts.add(new PartBase(c.getName(), c.getContentType(),
|
|
||||||
charSet, transferEncoding) {
|
|
||||||
@Override
|
@Override
|
||||||
protected long lengthOfData() throws IOException {
|
public long getLength() {
|
||||||
return c.getSize();
|
return c.getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFileName() {
|
||||||
|
return c.getName();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void sendData(OutputStream out)
|
public InputStream createInputStream() throws IOException {
|
||||||
throws IOException {
|
return c.getStream();
|
||||||
InputStream in = c.getStream();
|
|
||||||
try {
|
|
||||||
IOUtils.copy(in, out);
|
|
||||||
} finally {
|
|
||||||
in.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
parts.add(new FilePart(c.getName(), source,
|
||||||
|
c.getContentType(), charSet));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (parts.size() > 0) {
|
if (parts.size() > 0) {
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
<!--
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<add>
|
||||||
|
<doc>
|
||||||
|
<field name="id">SP2514N</field>
|
||||||
|
<field name="name">Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133</field>
|
||||||
|
<field name="manu">Samsung Electronics Co. Ltd.</field>
|
||||||
|
<!-- Join -->
|
||||||
|
<field name="manu_id_s">samsung</field>
|
||||||
|
<field name="cat">electronics</field>
|
||||||
|
<field name="cat">hard drive</field>
|
||||||
|
<field name="features">7200RPM, 8MB cache, IDE Ultra ATA-133</field>
|
||||||
|
<field name="features">NoiseGuard, SilentSeek technology, Fluid Dynamic Bearing (FDB) motor</field>
|
||||||
|
<field name="price">92</field>
|
||||||
|
<field name="popularity">6</field>
|
||||||
|
<field name="inStock">true</field>
|
||||||
|
<field name="manufacturedate_dt">2006-02-13T15:26:37Z</field>
|
||||||
|
<!-- Near Oklahoma city -->
|
||||||
|
<field name="store">35.0752,-97.032</field>
|
||||||
|
</doc>
|
||||||
|
|
||||||
|
<doc>
|
||||||
|
<field name="id">6H500F0</field>
|
||||||
|
<field name="name">Maxtor DiamondMax 11 - hard drive - 500 GB - SATA-300</field>
|
||||||
|
<field name="manu">Maxtor Corp.</field>
|
||||||
|
<!-- Join -->
|
||||||
|
<field name="manu_id_s">maxtor</field>
|
||||||
|
<field name="cat">electronics</field>
|
||||||
|
<field name="cat">hard drive</field>
|
||||||
|
<field name="features">SATA 3.0Gb/s, NCQ</field>
|
||||||
|
<field name="features">8.5ms seek</field>
|
||||||
|
<field name="features">16MB cache</field>
|
||||||
|
<field name="price">350</field>
|
||||||
|
<field name="popularity">6</field>
|
||||||
|
<field name="inStock">true</field>
|
||||||
|
<!-- Buffalo store -->
|
||||||
|
<field name="store">45.17614,-93.87341</field>
|
||||||
|
<field name="manufacturedate_dt">2006-02-13T15:26:37Z</field>
|
||||||
|
</doc>
|
||||||
|
</add>
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
<!--
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<add>
|
||||||
|
<doc>
|
||||||
|
<field name="id">TWINX2048-3200PRO</field>
|
||||||
|
<field name="name">CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory - Retail</field>
|
||||||
|
<field name="manu">Corsair Microsystems Inc.</field>
|
||||||
|
<!-- Join -->
|
||||||
|
<field name="manu_id_s">corsair</field>
|
||||||
|
<field name="cat">electronics</field>
|
||||||
|
<field name="cat">memory</field>
|
||||||
|
<field name="features">CAS latency 2, 2-3-3-6 timing, 2.75v, unbuffered, heat-spreader</field>
|
||||||
|
<field name="price">185</field>
|
||||||
|
<field name="popularity">5</field>
|
||||||
|
<field name="inStock">true</field>
|
||||||
|
<!-- San Francisco store -->
|
||||||
|
<field name="store">37.7752,-122.4232</field>
|
||||||
|
<field name="manufacturedate_dt">2006-02-13T15:26:37Z</field>
|
||||||
|
|
||||||
|
<!-- a field for testing payload tagged text via DelimitedPayloadTokenFilter -->
|
||||||
|
<field name="payloads">electronics|6.0 memory|3.0</field>
|
||||||
|
</doc>
|
||||||
|
|
||||||
|
<doc>
|
||||||
|
<field name="id">VS1GB400C3</field>
|
||||||
|
<field name="name">CORSAIR ValueSelect 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - Retail</field>
|
||||||
|
<field name="manu">Corsair Microsystems Inc.</field>
|
||||||
|
<!-- Join -->
|
||||||
|
<field name="manu_id_s">corsair</field>
|
||||||
|
<field name="cat">electronics</field>
|
||||||
|
<field name="cat">memory</field>
|
||||||
|
<field name="price">74.99</field>
|
||||||
|
<field name="popularity">7</field>
|
||||||
|
<field name="inStock">true</field>
|
||||||
|
<!-- Dodge City store -->
|
||||||
|
<field name="store">37.7752,-100.0232</field>
|
||||||
|
<field name="manufacturedate_dt">2006-02-13T15:26:37Z</field>
|
||||||
|
|
||||||
|
<field name="payloads">electronics|4.0 memory|2.0</field>
|
||||||
|
</doc>
|
||||||
|
|
||||||
|
<doc>
|
||||||
|
<field name="id">VDBDB1A16</field>
|
||||||
|
<field name="name">A-DATA V-Series 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - OEM</field>
|
||||||
|
<field name="manu">A-DATA Technology Inc.</field>
|
||||||
|
<!-- Join -->
|
||||||
|
<field name="manu_id_s">corsair</field>
|
||||||
|
<field name="cat">electronics</field>
|
||||||
|
<field name="cat">memory</field>
|
||||||
|
<field name="features">CAS latency 3, 2.7v</field>
|
||||||
|
<!-- note: price & popularity is missing on this one -->
|
||||||
|
<field name="popularity">0</field>
|
||||||
|
<field name="inStock">true</field>
|
||||||
|
<!-- Buffalo store -->
|
||||||
|
<field name="store">45.18414,-93.88141</field>
|
||||||
|
<field name="manufacturedate_dt">2006-02-13T15:26:37Z</field>
|
||||||
|
|
||||||
|
<field name="payloads">electronics|0.9 memory|0.1</field>
|
||||||
|
</doc>
|
||||||
|
|
||||||
|
</add>
|
||||||
|
|
|
@ -446,6 +446,24 @@ abstract public class SolrExampleTests extends SolrJettyTestBase
|
||||||
assertNotNull("Couldn't upload books.csv", result);
|
assertNotNull("Couldn't upload books.csv", result);
|
||||||
rsp = server.query( new SolrQuery( "*:*") );
|
rsp = server.query( new SolrQuery( "*:*") );
|
||||||
Assert.assertEquals( 10, rsp.getResults().getNumFound() );
|
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<Object> result = server.request(up);
|
||||||
|
assertNotNull("Couldn't upload xml files", result);
|
||||||
|
rsp = server.query( new SolrQuery( "*:*") );
|
||||||
|
Assert.assertEquals( 5 , rsp.getResults().getNumFound() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue