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 ho...@apache.org on 2007/02/20 02:38:26 UTC
svn commit: r509406 - in /lucene/solr/trunk: CHANGES.txt
src/java/org/apache/solr/core/Config.java
src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java
Author: hossman
Date: Mon Feb 19 17:38:26 2007
New Revision: 509406
URL: http://svn.apache.org/viewvc?view=rev&rev=509406
Log:
SOLR-166 - JNDI solr.home code refactoring
Modified:
lucene/solr/trunk/CHANGES.txt
lucene/solr/trunk/src/java/org/apache/solr/core/Config.java
lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java
Modified: lucene/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?view=diff&rev=509406&r1=509405&r2=509406
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Mon Feb 19 17:38:26 2007
@@ -88,7 +88,7 @@
8. SOLR-104: Support for "Update Plugins" -- RequestHandlers that want
access to streams of data for doing updates. ContentStreams can come
from the raw POST body, multi-part form data, or remote URLs.
- Included in this change is a new SlrDispatchFilter that allows
+ Included in this change is a new SolrDispatchFilter that allows
RequestHandlers registered with names that begin with a "/" to be
accessed using a URL structure based on that name.
(Ryan McKinley via hossman)
@@ -140,6 +140,14 @@
4. SOLR-145: Fix for bug introduced in SOLR-104 where some Exceptions
were being ignored by all "out of the box" RequestHandlers. (hossman)
+ 5. SOLR-166: JNDI solr.home code refactoring. SOLR-104 moved
+ some JNDI related code to the init method of a Servlet Filter -
+ according to the Servlet Spec, all Filter's should be initialized
+ prior to initializing any Servlets, but this is not the case in at
+ least one Servlet Container (Resin). This "bug fix" refactors
+ this JNDI code so that it should be executed the first time any
+ attempt is made to use the solr.home dir.
+
Other Changes
1. Updated to Lucene 2.1
Modified: lucene/solr/trunk/src/java/org/apache/solr/core/Config.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/core/Config.java?view=diff&rev=509406&r1=509405&r2=509406
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/core/Config.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/core/Config.java Mon Feb 19 17:38:26 2007
@@ -24,6 +24,10 @@
import org.apache.solr.core.SolrException;
import org.apache.solr.util.DOMUtil;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.naming.NoInitialContextException;
import javax.xml.parsers.*;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
@@ -236,15 +240,38 @@
}
public static String getInstanceDir() {
- if (instanceDir==null) {
- String prop = project + ".solr.home";
- instanceDir = normalizeDir(System.getProperty(prop));
- if (instanceDir==null) {
- instanceDir=project + '/';
- log.info("Solr home defaulted to '" + instanceDir + "' (system property " + prop + " not set)");
- } else {
- log.info("Solr home set to '" + instanceDir + "' from system property " + prop);
+ if ( ! isInstanceDirInitalized() ) {
+ String home = null;
+ // Try JNDI
+ try {
+ Context c = new InitialContext();
+ home = (String)c.lookup("java:comp/env/solr/home");
+ log.info("Using JNDI solr.home: "+home );
+ } catch (NoInitialContextException e) {
+ log.info("JNDI not configured for Solr (NoInitialContextEx)");
+ } catch (NamingException e) {
+ log.info("No /solr/home in JNDI");
+ } catch( RuntimeException ex ) {
+ log.warning("Odd RuntimeException while testing for JNDI: "
+ + ex.getMessage());
+ }
+
+ // Now try system property
+ if( home == null ) {
+ String prop = project + ".solr.home";
+ home = normalizeDir(System.getProperty(prop));
+ if( home != null ) {
+ log.info("using system property solr.home: " + home );
+ }
+ }
+
+ // if all else fails, try
+ if( home == null ) {
+ home = project + '/';
+ log.info("Solr home defaulted to '" + instanceDir + "' (could not find system property or JNDI)");
}
+
+ setInstanceDir(home);
}
return instanceDir;
}
Modified: lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java?view=diff&rev=509406&r1=509405&r2=509406
==============================================================================
--- lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java (original)
+++ lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrDispatchFilter.java Mon Feb 19 17:38:26 2007
@@ -22,10 +22,6 @@
import java.io.StringWriter;
import java.util.logging.Logger;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.naming.NoInitialContextException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@@ -35,7 +31,6 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.apache.solr.core.Config;
import org.apache.solr.core.SolrConfig;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrException;
@@ -60,20 +55,7 @@
public void init(FilterConfig config) throws ServletException
{
log.info("SolrDispatchFilter.init()");
-
- // Only initalize the directory if it has not been done yet
- if( !Config.isInstanceDirInitalized() ) {
- try {
- Context c = new InitialContext();
- String home = (String)c.lookup("java:comp/env/solr/home");
- if (home!=null) Config.setInstanceDir(home);
- } catch (NoInitialContextException e) {
- log.info("JNDI not configured for Solr (NoInitialContextEx)");
- } catch (NamingException e) {
- log.info("No /solr/home in JNDI");
- }
- }
-
+
// web.xml configuration
this.pathPrefix = config.getInitParameter( "path-prefix" );
this.handleSelect = "true".equals( config.getInitParameter( "handle-select" ) );