mirror of https://github.com/apache/lucene.git
SOLR-9827: Make ConcurrentUpdateSolrClient create RemoteSolrExceptions in case of remote errors instead of SolrException
This commit is contained in:
parent
4e7a7dbf9a
commit
fdec7871a1
|
@ -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.
|
||||
|
|
|
@ -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<String> 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<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);
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue