mirror of https://github.com/apache/lucene.git
SOLR-2535: REGRESSION: in Solr 3.x and trunk the admin/file handler fails to show directory listings
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1146685 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
903d239fb7
commit
e2e7c26849
|
@ -209,6 +209,9 @@ Bug Fixes
|
||||||
* SOLR-2193, SOLR-2565: SolrCores now properly share IndexWriters across SolrCore reloads.
|
* SOLR-2193, SOLR-2565: SolrCores now properly share IndexWriters across SolrCore reloads.
|
||||||
(Mark Miller, Robert Muir)
|
(Mark Miller, Robert Muir)
|
||||||
|
|
||||||
|
* SOLR-2535: REGRESSION: in Solr 3.x and trunk the admin/file handler
|
||||||
|
fails to show directory listings (David Smiley, Peter Wolanin via Erick Erickson)
|
||||||
|
|
||||||
Other Changes
|
Other Changes
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
|
|
|
@ -17,15 +17,6 @@
|
||||||
|
|
||||||
package org.apache.solr.handler.admin;
|
package org.apache.solr.handler.admin;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
import org.apache.solr.common.SolrException.ErrorCode;
|
import org.apache.solr.common.SolrException.ErrorCode;
|
||||||
|
@ -41,6 +32,15 @@ import org.apache.solr.request.SolrQueryRequest;
|
||||||
import org.apache.solr.response.RawResponseWriter;
|
import org.apache.solr.response.RawResponseWriter;
|
||||||
import org.apache.solr.response.SolrQueryResponse;
|
import org.apache.solr.response.SolrQueryResponse;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This handler uses the RawResponseWriter to give client access to
|
* This handler uses the RawResponseWriter to give client access to
|
||||||
* files inside ${solr.home}/conf
|
* files inside ${solr.home}/conf
|
||||||
|
@ -92,14 +92,7 @@ public class ShowFileRequestHandler extends RequestHandlerBase
|
||||||
@Override
|
@Override
|
||||||
public void init(NamedList args) {
|
public void init(NamedList args) {
|
||||||
super.init( args );
|
super.init( args );
|
||||||
|
|
||||||
// by default, use wt=raw
|
|
||||||
ModifiableSolrParams params = new ModifiableSolrParams( invariants );
|
|
||||||
if( params.get( CommonParams.WT ) == null ) {
|
|
||||||
params.set( CommonParams.WT, "raw" );
|
|
||||||
}
|
|
||||||
this.invariants = params;
|
|
||||||
|
|
||||||
// Build a list of hidden files
|
// Build a list of hidden files
|
||||||
hiddenFiles = new HashSet<String>();
|
hiddenFiles = new HashSet<String>();
|
||||||
if( invariants != null ) {
|
if( invariants != null ) {
|
||||||
|
@ -187,10 +180,15 @@ public class ShowFileRequestHandler extends RequestHandlerBase
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Include the file contents
|
// Include the file contents
|
||||||
|
//The file logic depends on RawResponseWriter, so force its use.
|
||||||
|
ModifiableSolrParams params = new ModifiableSolrParams( req.getParams() );
|
||||||
|
params.set( CommonParams.WT, "raw" );
|
||||||
|
req.setParams(params);
|
||||||
|
|
||||||
ContentStreamBase content = new ContentStreamBase.FileStream( adminFile );
|
ContentStreamBase content = new ContentStreamBase.FileStream( adminFile );
|
||||||
content.setContentType( req.getParams().get( USE_CONTENT_TYPE ) );
|
content.setContentType( req.getParams().get( USE_CONTENT_TYPE ) );
|
||||||
|
|
||||||
rsp.add( RawResponseWriter.CONTENT, content );
|
rsp.add(RawResponseWriter.CONTENT, content);
|
||||||
}
|
}
|
||||||
rsp.setHttpCaching(false);
|
rsp.setHttpCaching(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
package org.apache.solr.handler.admin;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import org.apache.solr.client.solrj.ResponseParser;
|
||||||
|
import org.apache.solr.SolrJettyTestBase;
|
||||||
|
import org.apache.solr.client.solrj.SolrServer;
|
||||||
|
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.util.ExternalPaths;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extend SolrJettyTestBase because the SOLR-2535 bug only manifested itself when
|
||||||
|
* the {@link SolrDispatchFilter} is used, which isn't for embedded Solr use.
|
||||||
|
*/
|
||||||
|
public class ShowFileRequestHandlerTest extends SolrJettyTestBase {
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void beforeTest() throws Exception {
|
||||||
|
createJetty(ExternalPaths.EXAMPLE_HOME, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDirList() throws SolrServerException {
|
||||||
|
SolrServer server = getSolrServer();
|
||||||
|
//assertQ(req("qt", "/admin/file")); TODO file bug that SolrJettyTestBase extends SolrTestCaseJ4
|
||||||
|
QueryRequest request = new QueryRequest();
|
||||||
|
request.setPath("/admin/file");
|
||||||
|
QueryResponse resp = request.process(server);
|
||||||
|
assertEquals(0,resp.getStatus());
|
||||||
|
assertTrue(((NamedList) resp.getResponse().get("files")).size() > 0);//some files
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetRawFile() throws SolrServerException, IOException {
|
||||||
|
SolrServer server = getSolrServer();
|
||||||
|
//assertQ(req("qt", "/admin/file")); TODO file bug that SolrJettyTestBase extends SolrTestCaseJ4
|
||||||
|
QueryRequest request = new QueryRequest(params("file","schema.xml"));
|
||||||
|
request.setPath("/admin/file");
|
||||||
|
final AtomicBoolean readFile = new AtomicBoolean();
|
||||||
|
request.setResponseParser(new ResponseParser() {
|
||||||
|
@Override
|
||||||
|
public String getWriterType() {
|
||||||
|
return "mock";//unfortunately this gets put onto params wt=mock but it apparently has no effect
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NamedList<Object> processResponse(InputStream body, String encoding) {
|
||||||
|
try {
|
||||||
|
if (body.read() >= 0)
|
||||||
|
readFile.set(true);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NamedList<Object> processResponse(Reader reader) {
|
||||||
|
throw new UnsupportedOperationException("TODO unimplemented");//TODO
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
server.request( request );//runs request
|
||||||
|
//request.process(server); but we don't have a NamedList response
|
||||||
|
assertTrue(readFile.get());
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,16 +17,16 @@
|
||||||
|
|
||||||
package org.apache.solr.client.solrj.request;
|
package org.apache.solr.client.solrj.request;
|
||||||
|
|
||||||
import java.util.Collection;
|
import org.apache.solr.client.solrj.SolrRequest;
|
||||||
|
|
||||||
import org.apache.solr.client.solrj.SolrServer;
|
import org.apache.solr.client.solrj.SolrServer;
|
||||||
import org.apache.solr.client.solrj.SolrServerException;
|
import org.apache.solr.client.solrj.SolrServerException;
|
||||||
import org.apache.solr.client.solrj.SolrRequest;
|
|
||||||
import org.apache.solr.client.solrj.response.QueryResponse;
|
import org.apache.solr.client.solrj.response.QueryResponse;
|
||||||
import org.apache.solr.common.params.CommonParams;
|
import org.apache.solr.common.params.CommonParams;
|
||||||
import org.apache.solr.common.params.SolrParams;
|
import org.apache.solr.common.params.SolrParams;
|
||||||
import org.apache.solr.common.util.ContentStream;
|
import org.apache.solr.common.util.ContentStream;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
@ -58,7 +58,7 @@ public class QueryRequest extends SolrRequest
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
String qt = query.get( CommonParams.QT );
|
String qt = query == null ? null : query.get( CommonParams.QT );
|
||||||
if( qt == null ) {
|
if( qt == null ) {
|
||||||
qt = super.getPath();
|
qt = super.getPath();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue