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.javaindex 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 typeString 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;}}