You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by ry...@apache.org on 2007/04/27 08:32:33 UTC

svn commit: r532987 - in /lucene/solr/trunk/src: java/org/apache/solr/core/RequestHandlers.java test/org/apache/solr/core/RequestHandlersTest.java

Author: ryan
Date: Thu Apr 26 23:32:33 2007
New Revision: 532987

URL: http://svn.apache.org/viewvc?view=rev&rev=532987
Log:
SOLR-203 path normalization.  If you register a path '/path' it shoudl work for '/path' and '/path/'

Modified:
    lucene/solr/trunk/src/java/org/apache/solr/core/RequestHandlers.java
    lucene/solr/trunk/src/test/org/apache/solr/core/RequestHandlersTest.java

Modified: lucene/solr/trunk/src/java/org/apache/solr/core/RequestHandlers.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/core/RequestHandlers.java?view=diff&rev=532987&r1=532986&r2=532987
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/core/RequestHandlers.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/core/RequestHandlers.java Thu Apr 26 23:32:33 2007
@@ -50,10 +50,27 @@
       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 @@
    * @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);

Modified: lucene/solr/trunk/src/test/org/apache/solr/core/RequestHandlersTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/core/RequestHandlersTest.java?view=diff&rev=532987&r1=532986&r2=532987
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/core/RequestHandlersTest.java (original)
+++ lucene/solr/trunk/src/test/org/apache/solr/core/RequestHandlersTest.java Thu Apr 26 23:32:33 2007
@@ -62,4 +62,18 @@
             "//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
+  }
 }