diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 8a5e369a32c..033e87963fa 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -203,6 +203,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.java index def65725628..677fe7eafdd 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; @@ -318,7 +317,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 metadata = null; // parse out the metadata from the SolrException try { String encoding = "UTF-8"; // default @@ -331,11 +331,21 @@ public class ConcurrentUpdateSolrClient extends SolrClient { NamedList resp = client.parser.processResponse(rspBody, encoding); NamedList error = (NamedList) resp.get("error"); if (error != null) { - solrExc.setMetadata((NamedList) error.get("metadata")); + metadata = (NamedList) 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 fails log.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.java index 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 SolrExampleTestsBase concurrentClient.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()); }