SOLR-8501: Specify the entity request size when known in HttpSolrClient.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1724612 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2016-01-14 14:00:02 +00:00
parent 6b850bca1d
commit 32fc5285f6
3 changed files with 16 additions and 3 deletions

View File

@ -393,6 +393,11 @@ Bug Fixes
* SOLR-8453: Solr should attempt to consume the request inputstream on errors as we cannot
count on the container to do it. (Mark Miller, Greg Wilkins, yonik, Joakim Erdfelt)
Optimizations
----------------------
* SOLR-8501: Specify the entity request size when known in HttpSolrClient. (Mark Miller)
Other Changes
----------------------

View File

@ -435,7 +435,8 @@ public class HttpSolrClient extends SolrClient {
break;
}
if (contentStream[0] instanceof RequestWriter.LazyContentStream) {
postOrPut.setEntity(new InputStreamEntity(contentStream[0].getStream(), -1) {
Long size = contentStream[0].getSize();
postOrPut.setEntity(new InputStreamEntity(contentStream[0].getStream(), size == null ? -1 : size) {
@Override
public Header getContentType() {
return new BasicHeader("Content-Type", contentStream[0].getContentType());
@ -448,7 +449,8 @@ public class HttpSolrClient extends SolrClient {
});
} else {
postOrPut.setEntity(new InputStreamEntity(contentStream[0].getStream(), -1) {
Long size = contentStream[0].getSize();
postOrPut.setEntity(new InputStreamEntity(contentStream[0].getStream(), size == null ? -1 : size) {
@Override
public Header getContentType() {
return new BasicHeader("Content-Type", contentStream[0].getContentType());

View File

@ -25,6 +25,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
@ -150,7 +151,12 @@ public abstract class ContentStreamBase implements ContentStream
this.str = str;
this.contentType = contentType;
name = null;
size = new Long( str.length() );
try {
size = new Long( str.getBytes(DEFAULT_CHARSET).length );
} catch (UnsupportedEncodingException e) {
// won't happen
throw new RuntimeException(e);
}
sourceInfo = "string";
}