mirror of https://github.com/apache/lucene.git
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:
parent
4f8f10dcb0
commit
e02c6d0c14
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue