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

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1527776 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2013-09-30 20:53:24 +00:00
parent 4f8f10dcb0
commit e02c6d0c14
1 changed files with 13 additions and 2 deletions

View File

@ -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;
}
}