From 0841e7ea3343dafb1f562abd1fc15c5771ef796f Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Fri, 21 Dec 2007 22:23:39 +0000 Subject: [PATCH] SOLR-350 -- dropping 'default' core usage and requiring the core name in the URL. Also fixes broken admin links (SOLR-441) git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@606335 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/solr/client/solrj/SolrServer.java | 3 + .../solrj/embedded/EmbeddedSolrServer.java | 16 +- .../client/solrj/impl/BaseSolrServer.java | 12 +- .../solrj/impl/CommonsHttpSolrServer.java | 6 +- .../solrj/request/MultiCoreRequest.java | 26 ++- .../solrj/MultiCoreExampleTestBase.java | 11 +- example/multicore/multicore.xml | 4 +- .../solr/common/params/MultiCoreParams.java | 5 +- src/java/org/apache/solr/core/MultiCore.java | 50 +++-- src/java/org/apache/solr/core/SolrCore.java | 6 +- .../solr/handler/admin/MultiCoreHandler.java | 18 +- src/webapp/resources/admin/_info.jsp | 4 - src/webapp/resources/admin/action.jsp | 2 +- src/webapp/resources/admin/analysis.jsp | 1 - .../resources/admin/distributiondump.jsp | 2 +- src/webapp/resources/admin/form.jsp | 1 - src/webapp/resources/admin/header.jsp | 2 +- src/webapp/resources/admin/index.jsp | 31 ++- src/webapp/resources/admin/logging.xsl | 208 ++++++++---------- src/webapp/resources/admin/ping.xsl | 141 ++++++------ src/webapp/resources/admin/registry.xsl | 5 +- src/webapp/resources/admin/stats.xsl | 5 +- src/webapp/resources/admin/threaddump.xsl | 205 +++++++++-------- .../resources/{index.html => index.jsp} | 14 +- .../solr/servlet/SolrDispatchFilter.java | 114 +++++----- 25 files changed, 444 insertions(+), 448 deletions(-) rename src/webapp/resources/{index.html => index.jsp} (79%) diff --git a/client/java/solrj/src/org/apache/solr/client/solrj/SolrServer.java b/client/java/solrj/src/org/apache/solr/client/solrj/SolrServer.java index b3fe11e9525..3e7ca01ac4a 100644 --- a/client/java/solrj/src/org/apache/solr/client/solrj/SolrServer.java +++ b/client/java/solrj/src/org/apache/solr/client/solrj/SolrServer.java @@ -37,6 +37,9 @@ public interface SolrServer // A general method to allow various methods NamedList request( final SolrRequest request ) throws SolrServerException, IOException; + void setDefaultCore( String core ); + String getDefaultCore(); + // Standard methods UpdateResponse add( SolrInputDocument doc ) throws SolrServerException, IOException; UpdateResponse add( Collection docs ) throws SolrServerException, IOException; diff --git a/client/java/solrj/src/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java b/client/java/solrj/src/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java index 3dcf5117cd7..4ad3ee9de04 100644 --- a/client/java/solrj/src/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java +++ b/client/java/solrj/src/org/apache/solr/client/solrj/embedded/EmbeddedSolrServer.java @@ -96,19 +96,29 @@ public class EmbeddedSolrServer extends BaseSolrServer SolrCore core = this.core; MultiCore multicore = MultiCore.getRegistry(); if( useMultiCore ) { + String c = getDefaultCore(); if( request.getCore() != null ) { + c = request.getCore(); + } + if( c != null ) { if( !multicore.isEnabled() ) { throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "multicore access is not enabled" ); } - core = multicore.getCore( request.getCore() ); + if( c.length() > 0 ) { + core = multicore.getCore( c ); + } + else { + core = multicore.getDefaultCore(); + } if( core == null ) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, - "Unknown core: "+request.getCore() ); + "Unknown core: "+c ); } } else { - core = multicore.getDefaultCore(); + throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, + "missing core" ); } } diff --git a/client/java/solrj/src/org/apache/solr/client/solrj/impl/BaseSolrServer.java b/client/java/solrj/src/org/apache/solr/client/solrj/impl/BaseSolrServer.java index f65162a32dc..79edfe59371 100644 --- a/client/java/solrj/src/org/apache/solr/client/solrj/impl/BaseSolrServer.java +++ b/client/java/solrj/src/org/apache/solr/client/solrj/impl/BaseSolrServer.java @@ -37,7 +37,9 @@ import org.apache.solr.common.params.SolrParams; * @version $Id$ * @since solr 1.3 */ -public abstract class BaseSolrServer implements SolrServer { +public abstract class BaseSolrServer implements SolrServer +{ + protected String defaultCore = null; public UpdateResponse add(Collection docs, boolean overwrite ) throws SolrServerException, IOException { UpdateRequest req = new UpdateRequest(); @@ -98,4 +100,12 @@ public abstract class BaseSolrServer implements SolrServer { public QueryResponse query(SolrParams params) throws SolrServerException { return new QueryRequest( params ).process( this ); } + + public String getDefaultCore() { + return defaultCore; + } + + public void setDefaultCore(String defaultCore) { + this.defaultCore = defaultCore; + } } diff --git a/client/java/solrj/src/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.java b/client/java/solrj/src/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.java index 82f632c3641..3712c2e4f47 100644 --- a/client/java/solrj/src/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.java +++ b/client/java/solrj/src/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.java @@ -121,8 +121,12 @@ public class CommonsHttpSolrServer extends BaseSolrServer } // modify the path for multicore access + String core = getDefaultCore(); if( request.getCore() != null ) { - path = "/@"+request.getCore()+path; + core= request.getCore(); + } + if( core != null && core.length() > 0 ) { + path = "/"+core+path; } if( params == null ) { diff --git a/client/java/solrj/src/org/apache/solr/client/solrj/request/MultiCoreRequest.java b/client/java/solrj/src/org/apache/solr/client/solrj/request/MultiCoreRequest.java index f265b388b41..411a2daabaf 100644 --- a/client/java/solrj/src/org/apache/solr/client/solrj/request/MultiCoreRequest.java +++ b/client/java/solrj/src/org/apache/solr/client/solrj/request/MultiCoreRequest.java @@ -49,11 +49,21 @@ public class MultiCoreRequest extends RequestBase super( METHOD.GET, path ); } + public final void setCoreParam( String v ) + { + this.core = v; + } + @Override public final void setCore( String v ) { - this.core = v; - // this does not change the path! + throw new UnsupportedOperationException( "MultiCoreRequest does not use a core."); + } + + @Override + public final String getCore() + { + return ""; // force it to invalid core } //--------------------------------------------------------------------------------------- @@ -100,18 +110,10 @@ public class MultiCoreRequest extends RequestBase // //--------------------------------------------------------------------------------------- - public static MultiCoreResponse setDefault( String name, SolrServer server ) throws SolrServerException, IOException - { - MultiCoreRequest req = new MultiCoreRequest(); - req.setCore( name ); - req.setAction( MultiCoreAction.SETASDEFAULT ); - return req.process( server ); - } - public static MultiCoreResponse reloadCore( String name, SolrServer server ) throws SolrServerException, IOException { MultiCoreRequest req = new MultiCoreRequest(); - req.setCore( name ); + req.setCoreParam( name ); req.setAction( MultiCoreAction.RELOAD ); return req.process( server ); } @@ -119,8 +121,8 @@ public class MultiCoreRequest extends RequestBase public static MultiCoreResponse getStatus( String name, SolrServer server ) throws SolrServerException, IOException { MultiCoreRequest req = new MultiCoreRequest(); + req.setCoreParam( name ); req.setAction( MultiCoreAction.STATUS ); - req.setCore( name ); return req.process( server ); } } diff --git a/client/java/solrj/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java b/client/java/solrj/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java index 489aadd3819..1807a4bc719 100644 --- a/client/java/solrj/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java +++ b/client/java/solrj/test/org/apache/solr/client/solrj/MultiCoreExampleTestBase.java @@ -17,16 +17,12 @@ package org.apache.solr.client.solrj; -import org.apache.solr.client.solrj.request.LukeRequest; import org.apache.solr.client.solrj.request.MultiCoreRequest; import org.apache.solr.client.solrj.request.QueryRequest; import org.apache.solr.client.solrj.request.UpdateRequest; import org.apache.solr.client.solrj.request.UpdateRequest.ACTION; -import org.apache.solr.client.solrj.response.LukeResponse; import org.apache.solr.client.solrj.response.MultiCoreResponse; import org.apache.solr.common.SolrInputDocument; -import org.apache.solr.common.params.SolrParams; -import org.apache.solr.common.util.NamedList; /** @@ -44,9 +40,6 @@ public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase public void testMultiCore() throws Exception { SolrServer solr = getSolrServer(); - - MultiCoreRequest.setDefault( "core1", solr ); - MultiCoreRequest.setDefault( "core0", solr ); UpdateRequest up = new UpdateRequest(); up.setAction( ACTION.COMMIT, true, true ); @@ -101,9 +94,11 @@ public abstract class MultiCoreExampleTestBase extends SolrExampleTestBase assertEquals( 0, r.process( solr ).getResults().size() ); // Now test Changing the default core + solr.setDefaultCore( "core0" ); assertEquals( 1, solr.query( new SolrQuery( "id:AAA" ) ).getResults().size() ); assertEquals( 0, solr.query( new SolrQuery( "id:BBB" ) ).getResults().size() ); - MultiCoreRequest.setDefault( "core1", solr ); + + solr.setDefaultCore( "core1" ); assertEquals( 0, solr.query( new SolrQuery( "id:AAA" ) ).getResults().size() ); assertEquals( 1, solr.query( new SolrQuery( "id:BBB" ) ).getResults().size() ); diff --git a/example/multicore/multicore.xml b/example/multicore/multicore.xml index 362ab042e6c..0a516e782a7 100644 --- a/example/multicore/multicore.xml +++ b/example/multicore/multicore.xml @@ -27,6 +27,6 @@ sharedLib: path to a lib files that will be shared across all cores --> - - + + diff --git a/src/java/org/apache/solr/common/params/MultiCoreParams.java b/src/java/org/apache/solr/common/params/MultiCoreParams.java index c6c96cafc8b..a6f91da1348 100644 --- a/src/java/org/apache/solr/common/params/MultiCoreParams.java +++ b/src/java/org/apache/solr/common/params/MultiCoreParams.java @@ -28,6 +28,9 @@ public interface MultiCoreParams /** Persistent -- should it save the multicore state? **/ public final static String PERSISTENT = "persistent"; + + /** The name of the the core to swap names with **/ + public final static String WITH = "with"; /** What action **/ public final static String ACTION = "action"; @@ -37,7 +40,7 @@ public interface MultiCoreParams LOAD, UNLOAD, RELOAD, - SETASDEFAULT; + SWAP; public static MultiCoreAction get( String p ) { diff --git a/src/java/org/apache/solr/core/MultiCore.java b/src/java/org/apache/solr/core/MultiCore.java index d60e46d3e46..b5226c862ce 100644 --- a/src/java/org/apache/solr/core/MultiCore.java +++ b/src/java/org/apache/solr/core/MultiCore.java @@ -20,7 +20,6 @@ package org.apache.solr.core; import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -125,7 +124,7 @@ public class MultiCore "multicore.xml defines multiple default cores. "+ getDefaultCore().getName() + " and " + core.getName() ); } - this.setDefaultCore( core ); + defaultCore = core; hasDefault = true; } } @@ -171,9 +170,13 @@ public class MultiCore throw new RuntimeException( "Can not register a null core." ); } String name = core.getName(); - if( name == null || name.length() == 0 ) { - throw new RuntimeException( "Invalid core name." ); + if( name == null || + name.length() < 1 || + name.indexOf( '/' ) >= 0 || + name.indexOf( '\\' ) >= 0 ){ + throw new RuntimeException( "Invalid core name: "+name ); } + SolrCore old = cores.put(name, core); if( old == null ) { log.info( "registering core: "+name ); @@ -183,6 +186,21 @@ public class MultiCore return old; } + public void swap(SolrCore c0, SolrCore c1) { + if( c0 == null || c1 == null ) { + throw new RuntimeException( "Can not swap a null core." ); + } + synchronized( cores ) { + String n0 = c0.getName(); + String n1 = c1.getName(); + cores.put(n0, c1); + cores.put(n1, c0); + c0.setName( n1 ); + c1.setName( n0 ); + } + log.info( "swaped: "+c0.getName() + " with " + c1.getName() ); + } + /** * While the new core is loading, requests will continue to be dispatched to * and processed by the old core @@ -194,28 +212,21 @@ public class MultiCore */ public void reload(SolrCore core) throws ParserConfigurationException, IOException, SAXException { - boolean wasDefault = (core==defaultCore); - SolrResourceLoader loader = new SolrResourceLoader( core.getResourceLoader().getInstanceDir() ); SolrConfig config = new SolrConfig( loader, core.getConfigFile(), null ); IndexSchema schema = new IndexSchema( config, core.getSchemaFile() ); SolrCore loaded = new SolrCore( core.getName(), core.getDataDir(), config, schema ); this.register( loaded ); - if( wasDefault ) { - this.setDefaultCore( loaded ); - } // TODO? -- add some kind of hook to close the core after all references are // gone... is finalize() enough? } - - public void setDefaultCore( SolrCore core ) + + public void remove( String name ) { - defaultCore = core; - cores.put( null, core ); - cores.put( "", core ); + cores.remove( name ); } - + public SolrCore getDefaultCore() { return defaultCore; } @@ -224,13 +235,7 @@ public class MultiCore * @return a Collection of registered SolrCores */ public Collection getCores() { - ArrayList c = new ArrayList(cores.size()); - for( Map.Entry entry : cores.entrySet() ) { - if( entry.getKey() != null && entry.getKey().length() > 0 ) { - c.add( entry.getValue() ); - } - } - return c; + return cores.values(); } public SolrCore getCore(String name) { @@ -268,5 +273,4 @@ public class MultiCore public File getConfigFile() { return configFile; } - } diff --git a/src/java/org/apache/solr/core/SolrCore.java b/src/java/org/apache/solr/core/SolrCore.java index 73323a377f6..0dbfaf3f952 100644 --- a/src/java/org/apache/solr/core/SolrCore.java +++ b/src/java/org/apache/solr/core/SolrCore.java @@ -83,7 +83,7 @@ public final class SolrCore { public static Logger log = Logger.getLogger(SolrCore.class.getName()); - private final String name; + private String name; private final SolrConfig solrConfig; private final IndexSchema schema; private final String dataDir; @@ -136,6 +136,10 @@ public final class SolrCore { public String getName() { return name; } + + public void setName(String v) { + this.name = v; + } /** * @since solr 1.3 diff --git a/src/java/org/apache/solr/handler/admin/MultiCoreHandler.java b/src/java/org/apache/solr/handler/admin/MultiCoreHandler.java index e1a92b2e018..75189fdaf63 100644 --- a/src/java/org/apache/solr/handler/admin/MultiCoreHandler.java +++ b/src/java/org/apache/solr/handler/admin/MultiCoreHandler.java @@ -67,6 +67,7 @@ public class MultiCoreHandler extends RequestHandlerBase // Pick the action SolrParams params = req.getParams(); + SolrParams required = params.required(); MultiCoreAction action = MultiCoreAction.STATUS; String a = params.get( MultiCoreParams.ACTION ); if( a != null ) { @@ -109,15 +110,22 @@ public class MultiCoreHandler extends RequestHandlerBase } else { switch( action ) { - case SETASDEFAULT: - manager.setDefaultCore( core ); - rsp.add( "default", core.getName() ); - break; - + case RELOAD: { manager.reload( core ); break; } + + case SWAP: { + String name = required.get( MultiCoreParams.WITH ); + SolrCore swap = manager.getCore( name ); + if( swap == null ) { + throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, + "Unknown core: "+name ); + } + manager.swap( core, swap ); + break; + } default: throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, diff --git a/src/webapp/resources/admin/_info.jsp b/src/webapp/resources/admin/_info.jsp index 3b60f8eccbe..58362e2a3c0 100644 --- a/src/webapp/resources/admin/_info.jsp +++ b/src/webapp/resources/admin/_info.jsp @@ -28,10 +28,6 @@ <% // SolrCore core = (SolrCore) request.getAttribute("org.apache.solr.SolrCore"); - if (core == null) { - String coreParam = request.getParameter("core"); - core = coreParam != null? org.apache.solr.core.MultiCore.getRegistry().getCore(coreParam) : null; - } if (core == null) core = SolrCore.getSolrCore(); diff --git a/src/webapp/resources/admin/action.jsp b/src/webapp/resources/admin/action.jsp index 056e26b5f3f..978c5303a2e 100644 --- a/src/webapp/resources/admin/action.jsp +++ b/src/webapp/resources/admin/action.jsp @@ -111,6 +111,6 @@

- Return to Admin Page + Return to Admin Page diff --git a/src/webapp/resources/admin/analysis.jsp b/src/webapp/resources/admin/analysis.jsp index 77d2208febf..a1536efbb70 100644 --- a/src/webapp/resources/admin/analysis.jsp +++ b/src/webapp/resources/admin/analysis.jsp @@ -60,7 +60,6 @@

Field Analysis

-
diff --git a/src/webapp/resources/admin/distributiondump.jsp b/src/webapp/resources/admin/distributiondump.jsp index 4d205a323f8..71cb41680e0 100644 --- a/src/webapp/resources/admin/distributiondump.jsp +++ b/src/webapp/resources/admin/distributiondump.jsp @@ -153,6 +153,6 @@ <%= buffer %>


- Return to Admin Page + Return to Admin Page diff --git a/src/webapp/resources/admin/form.jsp b/src/webapp/resources/admin/form.jsp index e34e1c7d655..88877f7c9e0 100644 --- a/src/webapp/resources/admin/form.jsp +++ b/src/webapp/resources/admin/form.jsp @@ -19,7 +19,6 @@
- - - - - - - - - - - - - - - Solr Admin: Logging - - - - SOLR - - -

Solr Admin ()

-
- -
-
- - .?core= - Return to Admin Page - -
- - -
- - - - - -
-

Solr Logging

- - - - - - - - - -
-

Log Level:

-
- -
- Set Level - - [ - action.jsp?log=ALL&core= - ALL - ] - [ - action.jsp?log=CONFIG&core= - CONFIG - ] - [ - action.jsp?log=FINE&core= - FINE - ] - [ - action.jsp?log=FINER&core= - FINER - ] - [ - action.jsp?log=FINEST&core= - FINEST - ] - [ - action.jsp?log=INFO&core= - INFO - ] - [ - action.jsp?log=OFF&core= - OFF - ] - [ - action.jsp?log=SEVERE&core= - SEVERE - ] - [ - action.jsp?log=WARNING&core= - WARNING - ] -
- -
-
+ + + + + + + + + + + + + + + + Solr Admin: Logging + + + + SOLR + + +

Solr Admin ()

+ + + +
+ + + + + +
+

Solr Logging

+ + + + + + + + + +
+

Log Level:

+
+ +
+ Set Level + + [ALL] + [CONFIG] + [FINE] + [FINER] + [FINEST] + [INFO] + [OFF] + [SEVERE] + [WARNING] +
+ +
+
diff --git a/src/webapp/resources/admin/ping.xsl b/src/webapp/resources/admin/ping.xsl index ec5672acf5e..364577bc69c 100644 --- a/src/webapp/resources/admin/ping.xsl +++ b/src/webapp/resources/admin/ping.xsl @@ -1,72 +1,69 @@ - - - - - - - - - - - - - - - - Solr Admin: Ping - - - - SOLR - - -

Solr Admin ()

-
- -
-
- - .?core= - Return to Admin Page (ping) - -
- - -
- - - - - - - - - -
-

Ping

-
- -
-
-
+ + + + + + + + + + + + + + + + Solr Admin: Ping + + + + SOLR + + +

Solr Admin ()

+ + + +
+ + + + + + + + + +
+

Ping

+
+ +
+
+
diff --git a/src/webapp/resources/admin/registry.xsl b/src/webapp/resources/admin/registry.xsl index f375e2568a4..53ff775cc3b 100644 --- a/src/webapp/resources/admin/registry.xsl +++ b/src/webapp/resources/admin/registry.xsl @@ -48,10 +48,7 @@


- - .?core= - Return to Admin Page - + Return to Admin Page diff --git a/src/webapp/resources/admin/stats.xsl b/src/webapp/resources/admin/stats.xsl index 40bbdc99d78..80ccc913e41 100644 --- a/src/webapp/resources/admin/stats.xsl +++ b/src/webapp/resources/admin/stats.xsl @@ -48,10 +48,7 @@


- - .?core= - Return to Admin Page - + Return to Admin Page diff --git a/src/webapp/resources/admin/threaddump.xsl b/src/webapp/resources/admin/threaddump.xsl index a51787acc67..999b05d009b 100644 --- a/src/webapp/resources/admin/threaddump.xsl +++ b/src/webapp/resources/admin/threaddump.xsl @@ -1,104 +1,101 @@ - - - - - - - - - - - - - - - - SOLR Info - - - - SOLR - -

Solr Admin ()

-

Thread Dump

-
- - -
- - .?core= - Return to Admin Page - -
- - -
- - - - - - - - - - - - - Thread Count: - current=, - peak=, - daemon= - - - - -
Full Thread Dump:
- - - - - '' - Id=, - - on lock=, - total cpu time= - user time= - - - - -
- - - - - -
-
- - -
- -
+ + + + + + + + + + + + + + + + SOLR Info + + + + SOLR + +

Solr Admin ()

+

Thread Dump

+ + + +
+ + + + + + + + + + + + + Thread Count: + current=, + peak=, + daemon= + + + + +
Full Thread Dump:
+ + + + + '' + Id=, + + on lock=, + total cpu time= + user time= + + + + +
+ + + + + +
+
+ + +
+ +
diff --git a/src/webapp/resources/index.html b/src/webapp/resources/index.jsp similarity index 79% rename from src/webapp/resources/index.html rename to src/webapp/resources/index.jsp index f4a11e7fa97..f4b125ae6ab 100644 --- a/src/webapp/resources/index.html +++ b/src/webapp/resources/index.jsp @@ -1,4 +1,4 @@ - +--%> + @@ -25,6 +26,15 @@

Welcome to Solr!

Solr + +<% + org.apache.solr.core.MultiCore multicore = org.apache.solr.core.MultiCore.getRegistry(); + if( multicore.isEnabled() ) { + for( org.apache.solr.core.SolrCore core : multicore.getCores() ) {%> +Admin <%= core.getName() %>
+<% }} else { %> Solr Admin +<% } %> + diff --git a/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java b/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java index 668ee32c202..b977da1b001 100644 --- a/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java +++ b/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java @@ -76,13 +76,9 @@ public class SolrDispatchFilter implements Filter log.info( "looking for multicore.xml: "+multiconfig.getAbsolutePath() ); if( multiconfig.exists() ) { multicore.load( instanceDir, multiconfig ); + core = multicore.getDefaultCore(); } if( multicore.isEnabled() ) { - core = multicore.getDefaultCore(); - if( core == null ) { - throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, - "Multicore configuration does not include a default" ); - } singlecore = null; } else { @@ -93,22 +89,22 @@ public class SolrDispatchFilter implements Filter log.info("user.dir=" + System.getProperty("user.dir")); // Read global configuration - // Only the first registerd core configures the following attributes - Config solrConfig = core.getSolrConfig(); + // Only the first registered core configures the following attributes + Config globalConfig = core.getSolrConfig(); - long uploadLimitKB = solrConfig.getInt( + long uploadLimitKB = globalConfig.getInt( "requestDispatcher/requestParsers/@multipartUploadLimitInKB", 2000 ); // 2MB default - boolean enableRemoteStreams = solrConfig.getBool( + boolean enableRemoteStreams = globalConfig.getBool( "requestDispatcher/requestParsers/@enableRemoteStreaming", false ); parsers = new SolrRequestParsers( enableRemoteStreams, uploadLimitKB ); // Let this filter take care of /select?xxx format - this.handleSelect = solrConfig.getBool( "requestDispatcher/@handleSelect", false ); + this.handleSelect = globalConfig.getBool( "requestDispatcher/@handleSelect", false ); // should it keep going if we hit an error? - abortOnConfigurationError = solrConfig.getBool("abortOnConfigurationError",true); + abortOnConfigurationError = globalConfig.getBool("abortOnConfigurationError",true); } catch( Throwable t ) { // catch this so our filter still works @@ -125,7 +121,12 @@ public class SolrDispatchFilter implements Filter out.println( "Check your log files for more detailed information on what may be wrong.\n" ); out.println( "If you want solr to continue after configuration errors, change: \n"); out.println( " false\n" ); - out.println( "in solrconfig.xml\n" ); + if( multicore.isEnabled() ) { + out.println( "in multicore.xml\n" ); + } + else { + out.println( "in solrconfig.xml\n" ); + } for( Throwable t : SolrConfig.severeErrors ) { out.println( "-------------------------------------------------------------" ); @@ -179,54 +180,51 @@ public class SolrDispatchFilter implements Filter } // By default use the single core. If multicore is enabled, look for one. + SolrRequestHandler handler = null; SolrCore core = singlecore; if( core == null ) { - // try to get the corename as a request parameter first - String corename = null; - if( path.startsWith( "/@" ) ) { // multicore - idx = path.indexOf( '/', 2 ); - if( idx < 1 ) { - throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, - "MultiCore path must contain a '/'. For example: /@corename/handlerpath" ); - } - corename = path.substring( 2, idx ); - path = path.substring( idx ); - - core = multicore.getCore( corename ); - if( core == null ) { - throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, - "Can not find core: '"+corename+"'" ); - } + // Perhaps this is a muli-core admin page? + if( path.equals( multicore.getAdminPath() ) ) { + handler = multicore.getMultiCoreHandler(); } else { - core = multicore.getDefaultCore(); + idx = path.indexOf( "/", 1 ); + if( idx > 1 ) { + // try to get the corename as a request parameter first + String corename = path.substring( 1, idx ); + path = path.substring( idx ); + core = multicore.getCore( corename ); + // invalid core name is ok. It could fall through to some other request + } } } - SolrRequestHandler handler = null; - if( path.length() > 1 ) { // don't match "" or "/" as valid path - handler = core.getRequestHandler( path ); - } - if( handler == null && handleSelect ) { - if( "/select".equals( path ) || "/select/".equals( path ) ) { - solrReq = parsers.parse( core, path, req ); - String qt = solrReq.getParams().get( CommonParams.QT ); - if( qt != null && qt.startsWith( "/" ) ) { - throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Invalid query type. Do not use /select to access: "+qt); - } - handler = core.getRequestHandler( qt ); - if( handler == null ) { - throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "unknown handler: "+qt); + if( core != null ) { + // Only try to parse the handler *if* a valid core exists + // when multi-core is enabled, the path can lead to a null core. + if( handler == null && path.length() > 1 ) { // don't match "" or "/" as valid path + handler = core.getRequestHandler( path ); + } + if( handler == null && handleSelect ) { + if( "/select".equals( path ) || "/select/".equals( path ) ) { + solrReq = parsers.parse( core, path, req ); + String qt = solrReq.getParams().get( CommonParams.QT ); + if( qt != null && qt.startsWith( "/" ) ) { + throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Invalid query type. Do not use /select to access: "+qt); + } + handler = core.getRequestHandler( qt ); + if( handler == null ) { + throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "unknown handler: "+qt); + } } } } - - // Perhaps this is a muli-core admin page? - if( handler == null && path.equals( multicore.getAdminPath() ) ) { - handler = multicore.getMultiCoreHandler(); - } if( handler != null ) { + if( core == null ) { + core = multicore.getDefaultCore(); + } + if( solrReq == null ) { solrReq = parsers.parse( core, path, req ); } @@ -245,21 +243,15 @@ public class SolrDispatchFilter implements Filter return; } // otherwise, let's ensure the core is in the SolrCore request attribute so - // the servlet can retrieve it + // the servlet/jsp can retrieve it else { - // TEMP -- to support /admin multicore grab the core from the request - // TODO -- for muticore /admin support, strip the corename from the path - // and forward to the /admin jsp file - // req.getRequestDispatcher( path ).forward( request, response ); - String corename = request.getParameter("core"); - if( corename != null ) { - core = multicore.getCore( corename ); - if( core == null ) { - throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, - "Can not find core: '"+corename+"'" ); - } - } req.setAttribute("org.apache.solr.SolrCore", core); + + // Modify the request so each core gets its own /admin + if( singlecore == null && path.startsWith( "/admin" ) ) { + req.getRequestDispatcher( path ).forward( request, response ); + return; + } } } catch( Throwable ex ) {