reindex from remote to read content-type header rather than guessing content type based on content

This commit is contained in:
javanna 2016-07-12 21:35:45 +02:00 committed by Luca Cavanna
parent 54fa997545
commit bce54cf38d
2 changed files with 6 additions and 5 deletions

View File

@ -34,9 +34,8 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.reindex.ScrollableHitSource;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.threadpool.ThreadPool;
@ -141,8 +140,9 @@ public class RemoteScrollableHitSource extends ScrollableHitSource {
T parsedResponse;
try {
InputStream content = response.getEntity().getContent();
XContent xContent = XContentFactory.xContentType(content).xContent();
try(XContentParser xContentParser = xContent.createParser(content)) {
XContentType xContentType = XContentType.fromMediaTypeOrFormat(
response.getEntity().getContentType().getValue());
try(XContentParser xContentParser = xContentType.xContent().createParser(content)) {
parsedResponse = parser.apply(xContentParser, () -> ParseFieldMatcher.STRICT);
}
} catch (IOException e) {

View File

@ -25,6 +25,7 @@ import org.apache.http.HttpResponse;
import org.apache.http.ProtocolVersion;
import org.apache.http.StatusLine;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
@ -360,7 +361,7 @@ public class RemoteScrollableHitSourceTests extends ESTestCase {
} else {
StatusLine statusLine = new BasicStatusLine(protocolVersion, 200, "");
HttpResponse httpResponse = new BasicHttpResponse(statusLine);
httpResponse.setEntity(new InputStreamEntity(resource.openStream()));
httpResponse.setEntity(new InputStreamEntity(resource.openStream(), ContentType.APPLICATION_JSON));
futureCallback.completed(httpResponse);
}
return null;