You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2013/04/17 04:16:16 UTC
svn commit: r1468718 - in /lucene/dev/branches/branch_4x: ./ dev-tools/
lucene/ lucene/analysis/
lucene/analysis/icu/src/java/org/apache/lucene/collation/ lucene/backwards/
lucene/benchmark/ lucene/classification/ lucene/classification/src/
lucene/code...
Author: hossman
Date: Wed Apr 17 02:16:14 2013
New Revision: 1468718
URL: http://svn.apache.org/r1468718
Log:
SOLR-4487: HttpSolrServer now includes the true http status code in SolrExceptions that it throws (merge r1468705)
Modified:
lucene/dev/branches/branch_4x/ (props changed)
lucene/dev/branches/branch_4x/dev-tools/ (props changed)
lucene/dev/branches/branch_4x/lucene/ (props changed)
lucene/dev/branches/branch_4x/lucene/BUILD.txt (props changed)
lucene/dev/branches/branch_4x/lucene/CHANGES.txt (props changed)
lucene/dev/branches/branch_4x/lucene/JRE_VERSION_MIGRATION.txt (props changed)
lucene/dev/branches/branch_4x/lucene/LICENSE.txt (props changed)
lucene/dev/branches/branch_4x/lucene/MIGRATE.txt (props changed)
lucene/dev/branches/branch_4x/lucene/NOTICE.txt (props changed)
lucene/dev/branches/branch_4x/lucene/README.txt (props changed)
lucene/dev/branches/branch_4x/lucene/SYSTEM_REQUIREMENTS.txt (props changed)
lucene/dev/branches/branch_4x/lucene/analysis/ (props changed)
lucene/dev/branches/branch_4x/lucene/analysis/icu/src/java/org/apache/lucene/collation/ICUCollationKeyFilterFactory.java (props changed)
lucene/dev/branches/branch_4x/lucene/backwards/ (props changed)
lucene/dev/branches/branch_4x/lucene/benchmark/ (props changed)
lucene/dev/branches/branch_4x/lucene/build.xml (props changed)
lucene/dev/branches/branch_4x/lucene/classification/ (props changed)
lucene/dev/branches/branch_4x/lucene/classification/build.xml (props changed)
lucene/dev/branches/branch_4x/lucene/classification/ivy.xml (props changed)
lucene/dev/branches/branch_4x/lucene/classification/src/ (props changed)
lucene/dev/branches/branch_4x/lucene/codecs/ (props changed)
lucene/dev/branches/branch_4x/lucene/common-build.xml (props changed)
lucene/dev/branches/branch_4x/lucene/core/ (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/index.40.cfs.zip (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/index.40.nocfs.zip (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/index.40.optimized.cfs.zip (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/index/index.40.optimized.nocfs.zip (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestSort.java (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestSortDocValues.java (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestSortRandom.java (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestTopFieldCollector.java (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestTotalHitCountCollector.java (props changed)
lucene/dev/branches/branch_4x/lucene/demo/ (props changed)
lucene/dev/branches/branch_4x/lucene/facet/ (props changed)
lucene/dev/branches/branch_4x/lucene/grouping/ (props changed)
lucene/dev/branches/branch_4x/lucene/highlighter/ (props changed)
lucene/dev/branches/branch_4x/lucene/ivy-settings.xml (props changed)
lucene/dev/branches/branch_4x/lucene/join/ (props changed)
lucene/dev/branches/branch_4x/lucene/licenses/ (props changed)
lucene/dev/branches/branch_4x/lucene/memory/ (props changed)
lucene/dev/branches/branch_4x/lucene/misc/ (props changed)
lucene/dev/branches/branch_4x/lucene/module-build.xml (props changed)
lucene/dev/branches/branch_4x/lucene/queries/ (props changed)
lucene/dev/branches/branch_4x/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionQuerySort.java (props changed)
lucene/dev/branches/branch_4x/lucene/queryparser/ (props changed)
lucene/dev/branches/branch_4x/lucene/sandbox/ (props changed)
lucene/dev/branches/branch_4x/lucene/site/ (props changed)
lucene/dev/branches/branch_4x/lucene/spatial/ (props changed)
lucene/dev/branches/branch_4x/lucene/suggest/ (props changed)
lucene/dev/branches/branch_4x/lucene/test-framework/ (props changed)
lucene/dev/branches/branch_4x/lucene/tools/ (props changed)
lucene/dev/branches/branch_4x/solr/ (props changed)
lucene/dev/branches/branch_4x/solr/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_4x/solr/LICENSE.txt (props changed)
lucene/dev/branches/branch_4x/solr/NOTICE.txt (props changed)
lucene/dev/branches/branch_4x/solr/README.txt (props changed)
lucene/dev/branches/branch_4x/solr/SYSTEM_REQUIREMENTS.txt (props changed)
lucene/dev/branches/branch_4x/solr/build.xml (props changed)
lucene/dev/branches/branch_4x/solr/cloud-dev/ (props changed)
lucene/dev/branches/branch_4x/solr/common-build.xml (props changed)
lucene/dev/branches/branch_4x/solr/contrib/ (props changed)
lucene/dev/branches/branch_4x/solr/core/ (props changed)
lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/core/TestConfig.java (props changed)
lucene/dev/branches/branch_4x/solr/example/ (props changed)
lucene/dev/branches/branch_4x/solr/licenses/ (props changed)
lucene/dev/branches/branch_4x/solr/licenses/httpclient-LICENSE-ASL.txt (props changed)
lucene/dev/branches/branch_4x/solr/licenses/httpclient-NOTICE.txt (props changed)
lucene/dev/branches/branch_4x/solr/licenses/httpcore-LICENSE-ASL.txt (props changed)
lucene/dev/branches/branch_4x/solr/licenses/httpcore-NOTICE.txt (props changed)
lucene/dev/branches/branch_4x/solr/licenses/httpmime-LICENSE-ASL.txt (props changed)
lucene/dev/branches/branch_4x/solr/licenses/httpmime-NOTICE.txt (props changed)
lucene/dev/branches/branch_4x/solr/scripts/ (props changed)
lucene/dev/branches/branch_4x/solr/site/ (props changed)
lucene/dev/branches/branch_4x/solr/solrj/ (props changed)
lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrException.java
lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java
lucene/dev/branches/branch_4x/solr/test-framework/ (props changed)
lucene/dev/branches/branch_4x/solr/webapp/ (props changed)
Modified: lucene/dev/branches/branch_4x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/CHANGES.txt?rev=1468718&r1=1468717&r2=1468718&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/solr/CHANGES.txt Wed Apr 17 02:16:14 2013
@@ -185,6 +185,11 @@ Bug Fixes
* SOLR-4710: You cannot delete a collection fully from ZooKeeper unless all nodes are up and
functioning correctly. (Mark Miller)
+* SOLR-4487: SolrExceptions thrown by HttpSolrServer will now contain the
+ proper HTTP status code returned by the remote server, even if that status
+ code is not something Solr itself returned -- eg: from the Servlet Container,
+ or an intermediate HTTP Proxy (hossman)
+
Optimizations
----------------------
Modified: lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java?rev=1468718&r1=1468717&r2=1468718&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java Wed Apr 17 02:16:14 2013
@@ -369,10 +369,9 @@ public class HttpSolrServer extends Solr
}
break;
default:
- throw new SolrException(SolrException.ErrorCode.getErrorCode(httpStatus), "Server at " + getBaseURL()
+ throw new RemoteSolrException(httpStatus, "Server at " + getBaseURL()
+ " returned non ok status:" + httpStatus + ", message:"
- + response.getStatusLine().getReasonPhrase());
-
+ + response.getStatusLine().getReasonPhrase(), null);
}
if (processor == null) {
// no processor specified, return raw stream
@@ -400,8 +399,7 @@ public class HttpSolrServer extends Solr
msg.append("request: " + method.getURI());
reason = java.net.URLDecoder.decode(msg.toString(), UTF_8);
}
- throw new SolrException(
- SolrException.ErrorCode.getErrorCode(httpStatus), reason);
+ throw new RemoteSolrException(httpStatus, reason, null);
}
return rsp;
} catch (ConnectException e) {
@@ -632,4 +630,20 @@ public class HttpSolrServer extends Solr
public void setUseMultiPartPost(boolean useMultiPartPost) {
this.useMultiPartPost = useMultiPartPost;
}
-}
\ No newline at end of file
+
+ /**
+ * Subclass of SolrException that allows us to capture an arbitrary HTTP
+ * status code that may have been returned by the remote server or a
+ * proxy along the way.
+ */
+ protected static class RemoteSolrException extends SolrException {
+ /**
+ * @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);
+ }
+ }
+}
Modified: lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrException.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrException.java?rev=1468718&r1=1468717&r2=1468718&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrException.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrException.java Wed Apr 17 02:16:14 2013
@@ -31,6 +31,9 @@ import org.slf4j.Logger;
public class SolrException extends RuntimeException {
/**
+ * This list of valid HTTP Status error codes that Solr may return in
+ * the case of a "Server Side" error.
+ *
* @since solr 1.2
*/
public enum ErrorCode {
@@ -69,8 +72,28 @@ public class SolrException extends Runti
super(th);
this.code = code.code;
}
+
+ /**
+ * Constructor that can set arbitrary http status code. Not for
+ * use in Solr, but may be used by clients in subclasses to capture
+ * errors returned by the servlet container or other HTTP proxies.
+ */
+ protected SolrException(int code, String msg, Throwable th) {
+ super(msg, th);
+ this.code = code;
+ }
int code=0;
+
+ /**
+ * The HTTP Status code associated with this Exception. For SolrExceptions
+ * thrown by Solr "Server Side", this should valid {@link ErrorCode},
+ * however client side exceptions may contain an arbitrary error code based
+ * on the behavior of the Servlet Container hosting Solr, or any HTTP
+ * Proxies that may exist between the client and the server.
+ *
+ * @return The HTTP Status code associated with this Exception
+ */
public int code() { return code; }
Modified: lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java?rev=1468718&r1=1468717&r2=1468718&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrServerTest.java Wed Apr 17 02:16:14 2013
@@ -43,6 +43,8 @@ import org.apache.solr.client.solrj.requ
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrInputDocument;
+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.util.NamedList;
import org.apache.solr.util.ExternalPaths;
@@ -74,12 +76,19 @@ public class BasicHttpSolrServerTest ext
lastMethod = null;
headers = null;
parameters = null;
+ errorCode = null;
}
+ public static Integer errorCode = null;
public static String lastMethod = null;
public static HashMap<String,String> headers = null;
public static Map<String,String[]> parameters = null;
+ public static void setErrorCode(Integer code) {
+ errorCode = code;
+ }
+
+
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
@@ -110,6 +119,13 @@ public class BasicHttpSolrServerTest ext
private void recordRequest(HttpServletRequest req, HttpServletResponse resp) {
setHeaders(req);
setParameters(req);
+ if (null != errorCode) {
+ try {
+ resp.sendError(errorCode);
+ } catch (IOException e) {
+ throw new RuntimeException("sendError IO fail in DebugServlet", e);
+ }
+ }
}
}
@@ -160,6 +176,34 @@ public class BasicHttpSolrServerTest ext
server.shutdown();
}
+ /**
+ * test that SolrExceptions thrown by HttpSolrServer can
+ * correctly encapsulate http status codes even when not on the list of
+ * ErrorCodes solr may return.
+ */
+ public void testSolrExceptionCodeNotFromSolr() throws IOException, SolrServerException {
+ final int status = 527;
+ assertEquals(status + " didn't generate an UNKNOWN error code, someone modified the list of valid ErrorCode's w/o changing this test to work a different way",
+ ErrorCode.UNKNOWN, ErrorCode.getErrorCode(status));
+
+ HttpSolrServer server = new HttpSolrServer(jetty.getBaseUrl().toString() +
+ "/debug/foo");
+ try {
+ DebugServlet.setErrorCode(status);
+ try {
+ SolrQuery q = new SolrQuery("foo");
+ server.query(q, METHOD.GET);
+ fail("Didn't get excepted exception from oversided request");
+ } catch (SolrException e) {
+ System.out.println(e);
+ assertEquals("Unexpected exception status code", status, e.code());
+ }
+ } finally {
+ server.shutdown();
+ DebugServlet.clear();
+ }
+ }
+
@Test
public void testQuery(){
DebugServlet.clear();