You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by tf...@apache.org on 2016/12/06 18:35:07 UTC
lucene-solr:master: SOLR-9827: Make ConcurrentUpdateSolrClient create
RemoteSolrExceptions in case of remote errors instead of SolrException
Repository: lucene-solr
Updated Branches:
refs/heads/master bf3a3137b -> c164f7e35
SOLR-9827: Make ConcurrentUpdateSolrClient create RemoteSolrExceptions in case of remote errors instead of SolrException
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/c164f7e3
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/c164f7e3
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/c164f7e3
Branch: refs/heads/master
Commit: c164f7e35e45d0bfa844cd450ffb4865c27fc4d5
Parents: bf3a313
Author: Tomas Fernandez Lobbe <tf...@apache.org>
Authored: Tue Dec 6 10:34:22 2016 -0800
Committer: Tomas Fernandez Lobbe <tf...@apache.org>
Committed: Tue Dec 6 10:34:22 2016 -0800
----------------------------------------------------------------------
solr/CHANGES.txt | 4 ++++
.../solrj/impl/ConcurrentUpdateSolrClient.java | 16 +++++++++++++---
.../apache/solr/client/solrj/SolrExampleTests.java | 7 ++++++-
3 files changed, 23 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c164f7e3/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index bac24e5..4f7377c 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.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c164f7e3/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClient.java
----------------------------------------------------------------------
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 b96cc23..5c3f289 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 SolrException
try {
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 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);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c164f7e3/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
----------------------------------------------------------------------
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 f403f3f..d25280d 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());
}