Skip to content

Apache Lucene open-source search software

SOLR-3530: Handle content type correctly when a response parser cannot be used.

Mark Robert Millere02c6d0c14f6
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
index 6f2eb12b271..7d29fe73079 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
@@ -412,8 +412,19 @@ public class HttpSolrServer extends SolrServer {
if (!contentType.equals(procCt)) {
// unexpected content type
String msg = "Expected content type " + procCt + " but got " + contentType + ".";
- RemoteSolrException e = new RemoteSolrException(httpStatus, msg + " " +
- IOUtils.toString(respBody), null);
+ Header encodingHeader = response.getEntity().getContentEncoding();
+ String encoding;
+ if (encodingHeader != null) {
+ encoding = encodingHeader.getValue();
+ } else {
+ encoding = "UTF-8"; // try UTF-8
+ }
+ try {
+ msg = msg + " " + IOUtils.toString(respBody, encoding);
+ } catch (IOException e) {
+ new RemoteSolrException(httpStatus, "Could not parse response with encoding " + encoding, e);
+ }
+ RemoteSolrException e = new RemoteSolrException(httpStatus, msg, null);
throw e;
}
}