Apache Solr open-source search software
SOLR-3972: Fix ShowFileRequestHandler to not log a warning in the (expected) situation of a file not found.
Chris M. Hostetter9fd744d160ea
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 5fba325b5ea..c9982b84828 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -375,6 +375,9 @@ Bug Fixes* SOLR-4134: Standard (XML) request writer cannot "set" multiple values intomultivalued field with partial updates. (Luis Cappa Banda, Will Butler, shalin)+* SOLR-3972: Fix ShowFileRequestHandler to not log a warning in the+ (expected) situation of a file not found. (hossman)+Other Changes----------------------diff --git a/solr/core/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.javaindex ba74e93a589..c40a8ca1ced 100644--- a/solr/core/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java@@ -154,8 +154,9 @@ public class ShowFileRequestHandler extends RequestHandlerBase// Make sure the file exists, is readable and is not a hidden fileif (!zkClient.exists(adminFile, true)) {- throw new SolrException(ErrorCode.BAD_REQUEST, "Can not find: "- + adminFile);+ rsp.setException(new SolrException(ErrorCode.NOT_FOUND, "Can not find: "+ + adminFile));+ return;}// Show a directory listing@@ -210,7 +211,8 @@ public class ShowFileRequestHandler extends RequestHandlerBasetry {configdir = new File( loader.getClassLoader().getResource(loader.getConfigDir()).toURI() );} catch (URISyntaxException e) {- throw new SolrException( ErrorCode.FORBIDDEN, "Can not access configuration directory!");+ rsp.setException(new SolrException( ErrorCode.FORBIDDEN, "Can not access configuration directory!", e));+ return;}}String fname = req.getParams().get("file", null);@@ -232,12 +234,16 @@ public class ShowFileRequestHandler extends RequestHandlerBase// Make sure the file exists, is readable and is not a hidden fileif( !adminFile.exists() ) {- throw new SolrException( ErrorCode.BAD_REQUEST, "Can not find: "+adminFile.getName()- + " ["+adminFile.getAbsolutePath()+"]" );+ rsp.setException(new SolrException+ ( ErrorCode.NOT_FOUND, "Can not find: "+adminFile.getName()+ + " ["+adminFile.getAbsolutePath()+"]" ));+ return;}if( !adminFile.canRead() || adminFile.isHidden() ) {- throw new SolrException( ErrorCode.BAD_REQUEST, "Can not show: "+adminFile.getName()- + " ["+adminFile.getAbsolutePath()+"]" );+ rsp.setException(new SolrException+ ( ErrorCode.NOT_FOUND, "Can not show: "+adminFile.getName()+ + " ["+adminFile.getAbsolutePath()+"]" ));+ return;}// Show a directory listingdiff --git a/solr/core/src/test/org/apache/solr/handler/admin/ShowFileRequestHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/ShowFileRequestHandlerTest.javaindex d47318692ee..bda44d3ae8b 100644--- a/solr/core/src/test/org/apache/solr/handler/admin/ShowFileRequestHandlerTest.java+++ b/solr/core/src/test/org/apache/solr/handler/admin/ShowFileRequestHandlerTest.java@@ -24,7 +24,10 @@ import org.apache.solr.client.solrj.SolrServerException;import org.apache.solr.client.solrj.request.QueryRequest;import org.apache.solr.client.solrj.response.QueryResponse;import org.apache.solr.common.util.NamedList;+import org.apache.solr.common.SolrException;import org.apache.solr.util.ExternalPaths;+import org.apache.solr.core.SolrCore;+import org.apache.solr.response.SolrQueryResponse;import org.junit.BeforeClass;import java.io.IOException;@@ -43,6 +46,41 @@ public class ShowFileRequestHandlerTest extends SolrJettyTestBase {createJetty(ExternalPaths.EXAMPLE_HOME, null, null);}+ public void test404ViaHttp() throws SolrServerException {+ SolrServer server = getSolrServer();+ QueryRequest request = new QueryRequest(params("file",+ "does-not-exist-404.txt"));+ request.setPath("/admin/file");+ try {+ QueryResponse resp = request.process(server);+ fail("didn't get 404 exception");+ } catch (SolrException e) {+ assertEquals(404, e.code());+ }+ }++ public void test404Locally() throws Exception {++ // we need to test that executing the handler directly does not+ // throw an exception, just sets the exception on the response.+ initCore("solrconfig.xml", "schema.xml");+ try {+ // bypass TestHarness since it will throw any exception found in the+ // response.+ SolrCore core = h.getCore();+ SolrQueryResponse rsp = new SolrQueryResponse();+ core.execute(core.getRequestHandler("/admin/file"),+ req("file", "does-not-exist-404.txt"), rsp);+ assertNotNull("no exception in response", rsp.getException());+ assertTrue("wrong type of exception: " + rsp.getException().getClass(),+ rsp.getException() instanceof SolrException);+ assertEquals(404, ((SolrException)rsp.getException()).code());++ } catch (Exception e) {+ assertNull("Should not have caught an exception", e);+ }+ }+public void testDirList() throws SolrServerException {SolrServer server = getSolrServer();//assertQ(req("qt", "/admin/file")); TODO file bug that SolrJettyTestBase extends SolrTestCaseJ4