Apache Solr open-source search software
SOLR-8366: ConcurrentUpdateSolrClient attempts to use response's content type as charset encoding for parsing exception
Shalin Shekhar Mangar30c0cfc26246
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 354004bb5ec..35b037c9da2 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -197,6 +197,9 @@ Bug Fixes* SOLR-2556: The default spellcheck query converter was ignoring terms consisting entirelyof digits. (James Dyer)+* SOLR-8366: ConcurrentUpdateSolrClient attempts to use response's content type as charset encoding+ for parsing exception. (shalin)+Other Changes----------------------diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.javaindex 52362a3715b..1aa5a706351 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java@@ -19,6 +19,7 @@ package org.apache.solr.client.solrj.impl;import org.apache.http.HttpResponse;import org.apache.http.HttpStatus;+import org.apache.http.NameValuePair;import org.apache.http.client.HttpClient;import org.apache.http.client.methods.HttpPost;import org.apache.http.entity.ContentProducer;@@ -287,12 +288,18 @@ public class ConcurrentUpdateSolrClient extends SolrClient {SolrException solrExc = new SolrException(ErrorCode.getErrorCode(statusCode), msg.toString());// parse out the metadata from the SolrExceptiontry {- NamedList<Object> resp =- client.parser.processResponse(response.getEntity().getContent(),- response.getEntity().getContentType().getValue());+ String encoding = "UTF-8"; // default+ if (response.getEntity().getContentType().getElements().length > 0) {+ NameValuePair param = response.getEntity().getContentType().getElements()[0].getParameterByName("charset");+ if (param != null) {+ encoding = param.getValue();+ }+ }+ NamedList<Object> resp = client.parser.processResponse(response.getEntity().getContent(), encoding);NamedList<Object> error = (NamedList<Object>) resp.get("error");- if (error != null)+ if (error != null) {solrExc.setMetadata((NamedList<String>) error.get("metadata"));+ }} catch (Exception exc) {// don't want to fail to report error if parsing the response failslog.warn("Failed to parse error response from " + client.getBaseURL() + " due to: " + exc);