Apache Lucene open-source search software
SOLR-9827: Make ConcurrentUpdateSolrClient create RemoteSolrExceptions in case of remote errors instead of SolrException
Tomas Fernandez Lobbec164f7e35e45
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex bac24e570d6..4f7377c5f94 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -259,6 +259,10 @@ Other Changes* SOLR-9819: Upgrade commons-fileupload to 1.3.2, fixing a potential vulnerability CVE-2016-3092 (Anshum Gupta)+* SOLR-9827: ConcurrentUpdateSolrClient creates a RemoteSolrException if the remote host responded with a non-ok+ response (instead of a SolrException) and includes the remote error message as part of the exception message+ (Tomás Fernández Löbbe)+================== 6.3.0 ==================Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.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 b96cc2365c2..5c3f289c4f5 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@@ -46,7 +46,6 @@ import org.apache.solr.client.solrj.request.RequestWriter;import org.apache.solr.client.solrj.request.UpdateRequest;import org.apache.solr.client.solrj.util.ClientUtils;import org.apache.solr.common.SolrException;-import org.apache.solr.common.SolrException.ErrorCode;import org.apache.solr.common.params.CommonParams;import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.common.params.SolrParams;@@ -330,7 +329,8 @@ public class ConcurrentUpdateSolrClient extends SolrClient {msg.append("\n\n\n\n");msg.append("request: ").append(method.getURI());- SolrException solrExc = new SolrException(ErrorCode.getErrorCode(statusCode), msg.toString());+ SolrException solrExc;+ NamedList<String> metadata = null;// parse out the metadata from the SolrExceptiontry {String encoding = "UTF-8"; // default@@ -343,11 +343,21 @@ public class ConcurrentUpdateSolrClient extends SolrClient {NamedList<Object> resp = client.parser.processResponse(rspBody, encoding);NamedList<Object> error = (NamedList<Object>) resp.get("error");if (error != null) {- solrExc.setMetadata((NamedList<String>) error.get("metadata"));+ metadata = (NamedList<String>) error.get("metadata");+ String remoteMsg = (String) error.get("msg");+ if (remoteMsg != null) {+ msg.append("\nRemote error message: ");+ msg.append(remoteMsg);+ }}} 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);+ } finally {+ solrExc = new HttpSolrClient.RemoteSolrException(client.getBaseURL(), statusCode, msg.toString(), null);+ if (metadata != null) {+ solrExc.setMetadata(metadata);+ }}handleError(solrExc);diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.javaindex f403f3f7b9e..d25280dfe26 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java@@ -36,6 +36,7 @@ import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;import org.apache.solr.client.solrj.embedded.SolrExampleStreamingTest.ErrorTrackingConcurrentUpdateSolrClient;import org.apache.solr.client.solrj.impl.BinaryResponseParser;import org.apache.solr.client.solrj.impl.HttpSolrClient;+import org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException;import org.apache.solr.client.solrj.impl.NoOpResponseParser;import org.apache.solr.client.solrj.impl.XMLResponseParser;import org.apache.solr.client.solrj.request.AbstractUpdateRequest;@@ -463,7 +464,11 @@ abstract public class SolrExampleTests extends SolrExampleTestsBaseconcurrentClient.lastError = null;concurrentClient.add(doc);concurrentClient.blockUntilFinished();- assertNotNull("Should throw exception!", concurrentClient.lastError);+ assertNotNull("Should throw exception!", concurrentClient.lastError);+ assertEquals("Unexpected exception type",+ RemoteSolrException.class, concurrentClient.lastError.getClass());+ assertTrue("Unexpected exception message: " + concurrentClient.lastError.getMessage(),+ concurrentClient.lastError.getMessage().contains("Remote error message: Document contains multiple values for uniqueKey"));} else {log.info("Ignoring update test for client:" + client.getClass().getName());}