lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r1527776 - /lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
Date Mon, 30 Sep 2013 20:53:24 GMT
Author: markrmiller
Date: Mon Sep 30 20:53:24 2013
New Revision: 1527776

URL: http://svn.apache.org/r1527776
Log:
SOLR-3530: Handle content type correctly when a response parser cannot be used.

Modified:
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java?rev=1527776&r1=1527775&r2=1527776&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
(original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
Mon Sep 30 20:53:24 2013
@@ -412,8 +412,19 @@ public class HttpSolrServer extends Solr
         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;
         }
       }



Mime
View raw message