mirror of https://github.com/apache/lucene.git
SOLR-166 - JNDI solr.home code refactoring
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@509406 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5ddfe531ed
commit
cacf143d65
10
CHANGES.txt
10
CHANGES.txt
|
@ -88,7 +88,7 @@ New Features
|
||||||
8. SOLR-104: Support for "Update Plugins" -- RequestHandlers that want
|
8. SOLR-104: Support for "Update Plugins" -- RequestHandlers that want
|
||||||
access to streams of data for doing updates. ContentStreams can come
|
access to streams of data for doing updates. ContentStreams can come
|
||||||
from the raw POST body, multi-part form data, or remote URLs.
|
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
|
RequestHandlers registered with names that begin with a "/" to be
|
||||||
accessed using a URL structure based on that name.
|
accessed using a URL structure based on that name.
|
||||||
(Ryan McKinley via hossman)
|
(Ryan McKinley via hossman)
|
||||||
|
@ -140,6 +140,14 @@ Bug Fixes
|
||||||
4. SOLR-145: Fix for bug introduced in SOLR-104 where some Exceptions
|
4. SOLR-145: Fix for bug introduced in SOLR-104 where some Exceptions
|
||||||
were being ignored by all "out of the box" RequestHandlers. (hossman)
|
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
|
Other Changes
|
||||||
1. Updated to Lucene 2.1
|
1. Updated to Lucene 2.1
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,10 @@ import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.core.SolrException;
|
import org.apache.solr.core.SolrException;
|
||||||
import org.apache.solr.util.DOMUtil;
|
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.parsers.*;
|
||||||
import javax.xml.xpath.XPath;
|
import javax.xml.xpath.XPath;
|
||||||
import javax.xml.xpath.XPathFactory;
|
import javax.xml.xpath.XPathFactory;
|
||||||
|
@ -236,15 +240,38 @@ public class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getInstanceDir() {
|
public static String getInstanceDir() {
|
||||||
if (instanceDir==null) {
|
if ( ! isInstanceDirInitalized() ) {
|
||||||
String prop = project + ".solr.home";
|
String home = null;
|
||||||
instanceDir = normalizeDir(System.getProperty(prop));
|
// Try JNDI
|
||||||
if (instanceDir==null) {
|
try {
|
||||||
instanceDir=project + '/';
|
Context c = new InitialContext();
|
||||||
log.info("Solr home defaulted to '" + instanceDir + "' (system property " + prop + " not set)");
|
home = (String)c.lookup("java:comp/env/solr/home");
|
||||||
} else {
|
log.info("Using JNDI solr.home: "+home );
|
||||||
log.info("Solr home set to '" + instanceDir + "' from system property " + prop);
|
} 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;
|
return instanceDir;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,10 +22,6 @@ import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.logging.Logger;
|
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.Filter;
|
||||||
import javax.servlet.FilterChain;
|
import javax.servlet.FilterChain;
|
||||||
import javax.servlet.FilterConfig;
|
import javax.servlet.FilterConfig;
|
||||||
|
@ -35,7 +31,6 @@ import javax.servlet.ServletResponse;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.solr.core.Config;
|
|
||||||
import org.apache.solr.core.SolrConfig;
|
import org.apache.solr.core.SolrConfig;
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.core.SolrException;
|
import org.apache.solr.core.SolrException;
|
||||||
|
@ -60,20 +55,7 @@ public class SolrDispatchFilter implements Filter
|
||||||
public void init(FilterConfig config) throws ServletException
|
public void init(FilterConfig config) throws ServletException
|
||||||
{
|
{
|
||||||
log.info("SolrDispatchFilter.init()");
|
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
|
// web.xml configuration
|
||||||
this.pathPrefix = config.getInitParameter( "path-prefix" );
|
this.pathPrefix = config.getInitParameter( "path-prefix" );
|
||||||
this.handleSelect = "true".equals( config.getInitParameter( "handle-select" ) );
|
this.handleSelect = "true".equals( config.getInitParameter( "handle-select" ) );
|
||||||
|
|
Loading…
Reference in New Issue