mirror of https://github.com/apache/lucene.git
SOLR-203 path normalization. If you register a path '/path' it shoudl work for '/path' and '/path/'
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@532987 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
302ac7b48b
commit
e4284d09bb
|
@ -49,11 +49,28 @@ final class RequestHandlers {
|
|||
private final Map<String, SolrRequestHandler> handlers = Collections.synchronizedMap(
|
||||
new HashMap<String,SolrRequestHandler>() );
|
||||
|
||||
/**
|
||||
* Trim the trailing '/' if its there.
|
||||
*
|
||||
* we want:
|
||||
* /update/csv
|
||||
* /update/csv/
|
||||
* to map to the same handler
|
||||
*
|
||||
*/
|
||||
private static String normalize( String p )
|
||||
{
|
||||
if( p != null && p.endsWith( "/" ) )
|
||||
return p.substring( 0, p.length()-1 );
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the RequestHandler registered at the given name
|
||||
*/
|
||||
public SolrRequestHandler get(String handlerName) {
|
||||
return handlers.get(handlerName);
|
||||
return handlers.get(normalize(handlerName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,10 +82,11 @@ final class RequestHandlers {
|
|||
* @return the previous handler at the given path or null
|
||||
*/
|
||||
public SolrRequestHandler register( String handlerName, SolrRequestHandler handler ) {
|
||||
String norm = normalize( handlerName );
|
||||
if( handler == null ) {
|
||||
return handlers.remove( handlerName );
|
||||
return handlers.remove( norm );
|
||||
}
|
||||
SolrRequestHandler old = handlers.put(handlerName, handler);
|
||||
SolrRequestHandler old = handlers.put(norm, handler);
|
||||
if (handlerName != null && handlerName != "") {
|
||||
if (handler instanceof SolrInfoMBean) {
|
||||
SolrInfoRegistry.getRegistry().put(handlerName, (SolrInfoMBean)handler);
|
||||
|
|
|
@ -62,4 +62,18 @@ public class RequestHandlersTest extends AbstractSolrTestCase {
|
|||
"//lst[@name='highlighting']"
|
||||
);
|
||||
}
|
||||
|
||||
public void testPathNormalization()
|
||||
{
|
||||
SolrCore core = SolrCore.getSolrCore();
|
||||
SolrRequestHandler h1 = core.getRequestHandler("/update/csv" );
|
||||
assertNotNull( h1 );
|
||||
|
||||
SolrRequestHandler h2 = core.getRequestHandler("/update/csv/" );
|
||||
assertNotNull( h2 );
|
||||
|
||||
assertEquals( h1, h2 ); // the same object
|
||||
|
||||
assertNull( core.getRequestHandler("/update/csv/asdgadsgas" ) ); // prefix
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue