mirror of https://github.com/apache/lucene.git
SOLR-3972: Fix ShowFileRequestHandler to not log a warning in the (expected) situation of a file not found.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1425207 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1088f1a4d4
commit
9fd744d160
|
@ -375,6 +375,9 @@ Bug Fixes
|
|||
* SOLR-4134: Standard (XML) request writer cannot "set" multiple values into
|
||||
multivalued 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
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -154,8 +154,9 @@ public class ShowFileRequestHandler extends RequestHandlerBase
|
|||
|
||||
// Make sure the file exists, is readable and is not a hidden file
|
||||
if (!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 RequestHandlerBase
|
|||
try {
|
||||
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 file
|
||||
if( !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 listing
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue