You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ro...@apache.org on 2014/12/15 12:06:09 UTC
svn commit: r1645622 - in /lucene/dev/trunk/solr: CHANGES.txt
solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
Author: romseygeek
Date: Mon Dec 15 11:06:09 2014
New Revision: 1645622
URL: http://svn.apache.org/r1645622
Log:
SOLR-6849: RemoteSolrException should report its source host
Modified:
lucene/dev/trunk/solr/CHANGES.txt
lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1645622&r1=1645621&r2=1645622&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Mon Dec 15 11:06:09 2014
@@ -492,6 +492,9 @@ Other Changes
* SOLR-6826: fieldType capitalization is not consistent with the rest of case-sensitive field names.
(Alexandre Rafalovitch via Erick Erickson)
+* SOLR-6849: HttpSolrServer.RemoteSolrException reports the URL of the remote
+ host where the exception occurred. (Alan Woodward)
+
================== 4.10.3 ==================
Bug Fixes
Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java?rev=1645622&r1=1645621&r2=1645622&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java (original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java Mon Dec 15 11:06:09 2014
@@ -16,24 +16,6 @@
*/
package org.apache.solr.client.solrj.impl;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.ConnectException;
-import java.net.SocketTimeoutException;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-
import org.apache.commons.io.IOUtils;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
@@ -48,7 +30,6 @@ import org.apache.http.client.methods.Ht
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.client.params.ClientPNames;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.InputStreamEntity;
@@ -80,6 +61,23 @@ import org.apache.solr.common.util.Solrj
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.ConnectException;
+import java.net.SocketTimeoutException;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
public class HttpSolrServer extends SolrServer {
private static final String UTF_8 = StandardCharsets.UTF_8.name();
private static final String DEFAULT_PATH = "/select";
@@ -490,8 +488,7 @@ public class HttpSolrServer extends Solr
break;
default:
if (processor == null) {
- throw new RemoteSolrException(httpStatus, "Server at "
- + getBaseURL() + " returned non ok status:" + httpStatus
+ throw new RemoteSolrException(baseUrl, httpStatus, "non ok status: " + httpStatus
+ ", message:" + response.getStatusLine().getReasonPhrase(),
null);
}
@@ -524,9 +521,9 @@ public class HttpSolrServer extends Solr
try {
msg = msg + " " + IOUtils.toString(respBody, encoding);
} catch (IOException e) {
- throw new RemoteSolrException(httpStatus, "Could not parse response with encoding " + encoding, e);
+ throw new RemoteSolrException(baseUrl, httpStatus, "Could not parse response with encoding " + encoding, e);
}
- RemoteSolrException e = new RemoteSolrException(httpStatus, msg, null);
+ RemoteSolrException e = new RemoteSolrException(baseUrl, httpStatus, msg, null);
throw e;
}
}
@@ -544,7 +541,7 @@ public class HttpSolrServer extends Solr
try {
rsp = processor.processResponse(respBody, charset);
} catch (Exception e) {
- throw new RemoteSolrException(httpStatus, e.getMessage(), e);
+ throw new RemoteSolrException(baseUrl, httpStatus, e.getMessage(), e);
}
if (httpStatus != HttpStatus.SC_OK) {
NamedList<String> metadata = null;
@@ -566,7 +563,7 @@ public class HttpSolrServer extends Solr
msg.append("request: " + method.getURI());
reason = java.net.URLDecoder.decode(msg.toString(), UTF_8);
}
- RemoteSolrException rss = new RemoteSolrException(httpStatus, reason, null);
+ RemoteSolrException rss = new RemoteSolrException(baseUrl, httpStatus, reason, null);
if (metadata != null) rss.setMetadata(metadata);
throw rss;
}
@@ -814,12 +811,13 @@ public class HttpSolrServer extends Solr
*/
public static class RemoteSolrException extends SolrException {
/**
+ * @param remoteHost the host the error was received from
* @param code Arbitrary HTTP status code
* @param msg Exception Message
* @param th Throwable to wrap with this Exception
*/
- public RemoteSolrException(int code, String msg, Throwable th) {
- super(code, msg, th);
+ public RemoteSolrException(String remoteHost, int code, String msg, Throwable th) {
+ super(code, "Error from server at " + remoteHost + ": " + msg, th);
}
}
}
Modified: lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java?rev=1645622&r1=1645621&r2=1645622&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java (original)
+++ lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java Mon Dec 15 11:06:09 2014
@@ -61,6 +61,8 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
+import static org.junit.internal.matchers.StringContains.containsString;
+
/**
* This should include tests against the example solr config
*
@@ -408,7 +410,7 @@ abstract public class SolrExampleTests e
}
catch(SolrException ex) {
assertEquals(400, ex.code());
- assertEquals("Invalid Number: ignore_exception", ex.getMessage()); // The reason should get passed through
+ assertThat(ex.getMessage(), containsString("Invalid Number: ignore_exception"));
}
catch(Throwable t) {
t.printStackTrace();