mirror of https://github.com/apache/lucene.git
SOLR-215 -- extracting multicore config stuff from SOLR-350. This does three key things (that will make SOLR-350 easier to maintain)
1. extract SolrCore from SolrRequestParser -- this lets it be shared across cores 2. go back to the 1.2 interface for XmlUpdateRequestHandler public void doLegacyUpdate(Reader input, Writer output) 3. add a constructor to Config that lets you set the instanceDir explicitly (otherwise it forced static and needs to be specified as a property) git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@578507 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d78f61db76
commit
6d8ae540e2
|
@ -59,7 +59,7 @@ public class EmbeddedSolrServer extends BaseSolrServer
|
||||||
public EmbeddedSolrServer( SolrCore core )
|
public EmbeddedSolrServer( SolrCore core )
|
||||||
{
|
{
|
||||||
this.core = core;
|
this.core = core;
|
||||||
this.parser = new SolrRequestParsers( core );
|
this.parser = new SolrRequestParsers( true, Long.MAX_VALUE );
|
||||||
|
|
||||||
// by default use the XML one
|
// by default use the XML one
|
||||||
_processor = new XMLResponseParser();
|
_processor = new XMLResponseParser();
|
||||||
|
@ -100,7 +100,7 @@ public class EmbeddedSolrServer extends BaseSolrServer
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SolrQueryRequest req = parser.buildRequestFrom( params, request.getContentStreams() );
|
SolrQueryRequest req = parser.buildRequestFrom( core, params, request.getContentStreams() );
|
||||||
req.getContext().put( "path", path );
|
req.getContext().put( "path", path );
|
||||||
SolrQueryResponse rsp = new SolrQueryResponse();
|
SolrQueryResponse rsp = new SolrQueryResponse();
|
||||||
core.execute( handler, req, rsp );
|
core.execute( handler, req, rsp );
|
||||||
|
|
|
@ -50,16 +50,37 @@ public class Config {
|
||||||
|
|
||||||
static final XPathFactory xpathFactory = XPathFactory.newInstance();
|
static final XPathFactory xpathFactory = XPathFactory.newInstance();
|
||||||
|
|
||||||
private Document doc;
|
private final String instanceDir; // solr home directory
|
||||||
private String prefix;
|
private final Document doc;
|
||||||
private String name;
|
private final String prefix;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
public Config(String name, InputStream is, String prefix) throws ParserConfigurationException, IOException, SAXException {
|
@Deprecated
|
||||||
|
public Config(String name, InputStream is, String prefix) throws ParserConfigurationException, IOException, SAXException
|
||||||
|
{
|
||||||
|
this( Config.locateInstanceDir(), name, is, prefix );
|
||||||
|
}
|
||||||
|
|
||||||
|
public Config(String instanceDir, String name) throws ParserConfigurationException, IOException, SAXException
|
||||||
|
{
|
||||||
|
this( instanceDir, name, null, null );
|
||||||
|
}
|
||||||
|
|
||||||
|
public Config(String instanceDir, String name, InputStream is, String prefix) throws ParserConfigurationException, IOException, SAXException
|
||||||
|
{
|
||||||
|
if( instanceDir == null ) {
|
||||||
|
instanceDir = Config.locateInstanceDir();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.instanceDir = normalizeDir(instanceDir);
|
||||||
|
log.info("Solr home set to '" + instanceDir + "'");
|
||||||
|
classLoader = null;
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
if (prefix!=null && !prefix.endsWith("/")) prefix += '/';
|
if (prefix!=null && !prefix.endsWith("/")) prefix += '/';
|
||||||
InputStream lis = is;
|
InputStream lis = is;
|
||||||
try{
|
try {
|
||||||
if (lis == null)
|
if (lis == null)
|
||||||
lis = openResource(name);
|
lis = openResource(name);
|
||||||
|
|
||||||
|
@ -194,7 +215,7 @@ public class Config {
|
||||||
// The directory where solr will look for config files by default.
|
// The directory where solr will look for config files by default.
|
||||||
// defaults to "./solr/conf/"
|
// defaults to "./solr/conf/"
|
||||||
public String getConfigDir() {
|
public String getConfigDir() {
|
||||||
return getInstanceDir() + "conf/";
|
return instanceDir + "conf/";
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream openResource(String resource) {
|
public InputStream openResource(String resource) {
|
||||||
|
@ -311,7 +332,6 @@ public class Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String instanceDir; // solr home directory
|
|
||||||
private static String normalizeDir(String path) {
|
private static String normalizeDir(String path) {
|
||||||
if (path==null) return null;
|
if (path==null) return null;
|
||||||
if ( !(path.endsWith("/") || path.endsWith("\\")) ) {
|
if ( !(path.endsWith("/") || path.endsWith("\\")) ) {
|
||||||
|
@ -320,55 +340,44 @@ public class Config {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInstanceDir(String dir) {
|
|
||||||
instanceDir = normalizeDir(dir);
|
|
||||||
classLoader = null;
|
|
||||||
log.info("Solr home set to '" + instanceDir + "'");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getInstanceDir() {
|
public String getInstanceDir() {
|
||||||
if ( !isInstanceDirInitialized() ) {
|
|
||||||
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;
|
return instanceDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInstanceDirInitialized() {
|
public static String locateInstanceDir() {
|
||||||
return instanceDir != null;
|
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 '" + home + "' (could not find system property or JNDI)");
|
||||||
|
}
|
||||||
|
return normalizeDir( home );
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Singleton classloader loading resources specified in any configs */
|
/** Singleton classloader loading resources specified in any configs */
|
||||||
private static ClassLoader classLoader = null;
|
private ClassLoader classLoader = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the singleton classloader to be use when loading resources
|
* Returns the singleton classloader to be use when loading resources
|
||||||
|
@ -380,12 +389,12 @@ public class Config {
|
||||||
* found in the "lib/" directory in the "Solr Home" directory.
|
* found in the "lib/" directory in the "Solr Home" directory.
|
||||||
* <p>
|
* <p>
|
||||||
*/
|
*/
|
||||||
ClassLoader getClassLoader() {
|
private ClassLoader getClassLoader() {
|
||||||
if (null == classLoader) {
|
if (null == classLoader) {
|
||||||
// NB5.5/win32/1.5_10: need to go thru local var or classLoader is not set!
|
// NB5.5/win32/1.5_10: need to go thru local var or classLoader is not set!
|
||||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||||
|
|
||||||
File f = new File(getInstanceDir() + "lib/");
|
File f = new File(instanceDir + "lib/");
|
||||||
if (f.canRead() && f.isDirectory()) {
|
if (f.canRead() && f.isDirectory()) {
|
||||||
File[] jarFiles = f.listFiles();
|
File[] jarFiles = f.listFiles();
|
||||||
URL[] jars = new URL[jarFiles.length];
|
URL[] jars = new URL[jarFiles.length];
|
||||||
|
@ -404,4 +413,10 @@ public class Config {
|
||||||
return classLoader;
|
return classLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the XML filename
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,35 +74,30 @@ public class SolrConfig extends Config {
|
||||||
* Singleton keeping track of configuration errors
|
* Singleton keeping track of configuration errors
|
||||||
*/
|
*/
|
||||||
public static final Collection<Throwable> severeErrors = new HashSet<Throwable>();
|
public static final Collection<Throwable> severeErrors = new HashSet<Throwable>();
|
||||||
/**
|
|
||||||
* Creates a configation information from the specified file.
|
|
||||||
* Add any exception that might occur to the severeErrors singleton.
|
|
||||||
* @param file file name to load
|
|
||||||
* @see Config#openResource
|
|
||||||
*/
|
|
||||||
public static SolrConfig createInstance(String file) {
|
|
||||||
try {
|
|
||||||
return new SolrConfig(file);
|
|
||||||
} catch (Exception ee) {
|
|
||||||
severeErrors.add( ee );
|
|
||||||
throw new RuntimeException("Error in " + file, ee);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates a default instance from the solrconfig.xml. */
|
/** Creates a default instance from the solrconfig.xml. */
|
||||||
public SolrConfig()
|
public SolrConfig()
|
||||||
throws ParserConfigurationException, IOException, SAXException {
|
throws ParserConfigurationException, IOException, SAXException {
|
||||||
this(DEFAULT_CONF_FILE);
|
this( null, DEFAULT_CONF_FILE, null );
|
||||||
}
|
}
|
||||||
/** Creates a configuration instance from a file. */
|
/** Creates a configuration instance from a file. */
|
||||||
public SolrConfig(String file)
|
public SolrConfig(String file)
|
||||||
throws ParserConfigurationException, IOException, SAXException {
|
throws ParserConfigurationException, IOException, SAXException {
|
||||||
this(file, null);
|
this( null, file, null);
|
||||||
}
|
}
|
||||||
/** Creates a configuration instance from an input stream. */
|
|
||||||
|
@Deprecated
|
||||||
public SolrConfig(String file, InputStream is)
|
public SolrConfig(String file, InputStream is)
|
||||||
throws ParserConfigurationException, IOException, SAXException {
|
throws ParserConfigurationException, IOException, SAXException
|
||||||
super(file, is, "/config/");
|
{
|
||||||
|
this( null, file, is );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Creates a configuration instance from an input stream. */
|
||||||
|
public SolrConfig(String instanceDir, String file, InputStream is)
|
||||||
|
throws ParserConfigurationException, IOException, SAXException
|
||||||
|
{
|
||||||
|
super(instanceDir, file, is, "/config/");
|
||||||
this.configFile = file;
|
this.configFile = file;
|
||||||
defaultIndexConfig = new SolrIndexConfig(this, null, null);
|
defaultIndexConfig = new SolrIndexConfig(this, null, null);
|
||||||
mainIndexConfig = new SolrIndexConfig(this, "mainIndex", defaultIndexConfig);
|
mainIndexConfig = new SolrIndexConfig(this, "mainIndex", defaultIndexConfig);
|
||||||
|
|
|
@ -72,7 +72,8 @@ public final class SolrCore {
|
||||||
public static final String version="1.0";
|
public static final String version="1.0";
|
||||||
|
|
||||||
public static Logger log = Logger.getLogger(SolrCore.class.getName());
|
public static Logger log = Logger.getLogger(SolrCore.class.getName());
|
||||||
|
|
||||||
|
private final SolrConfig solrConfig;
|
||||||
private final IndexSchema schema;
|
private final IndexSchema schema;
|
||||||
private final String dataDir;
|
private final String dataDir;
|
||||||
private final String index_path;
|
private final String index_path;
|
||||||
|
@ -81,6 +82,7 @@ public final class SolrCore {
|
||||||
private final RequestHandlers reqHandlers;
|
private final RequestHandlers reqHandlers;
|
||||||
private final SolrHighlighter highlighter;
|
private final SolrHighlighter highlighter;
|
||||||
private final Map<String,UpdateRequestProcessorFactory> updateProcessors;
|
private final Map<String,UpdateRequestProcessorFactory> updateProcessors;
|
||||||
|
private final Map<String,SolrInfoMBean> infoRegistry = new java.util.HashMap<String,SolrInfoMBean>();
|
||||||
|
|
||||||
public long getStartTime() { return startTime; }
|
public long getStartTime() { return startTime; }
|
||||||
|
|
||||||
|
@ -94,8 +96,9 @@ public final class SolrCore {
|
||||||
if (boolean_query_max_clause_count == Integer.MIN_VALUE) {
|
if (boolean_query_max_clause_count == Integer.MIN_VALUE) {
|
||||||
boolean_query_max_clause_count = solrConfig.booleanQueryMaxClauseCount;
|
boolean_query_max_clause_count = solrConfig.booleanQueryMaxClauseCount;
|
||||||
BooleanQuery.setMaxClauseCount(boolean_query_max_clause_count);
|
BooleanQuery.setMaxClauseCount(boolean_query_max_clause_count);
|
||||||
} else if (boolean_query_max_clause_count != solrConfig.booleanQueryMaxClauseCount )
|
} else if (boolean_query_max_clause_count != solrConfig.booleanQueryMaxClauseCount ) {
|
||||||
log.fine("BooleanQuery.maxClauseCount= " +boolean_query_max_clause_count+ ", ignoring " +solrConfig.booleanQueryMaxClauseCount);
|
log.fine("BooleanQuery.maxClauseCount= " +boolean_query_max_clause_count+ ", ignoring " +solrConfig.booleanQueryMaxClauseCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,9 +114,6 @@ public final class SolrCore {
|
||||||
return schema.getSchemaFile();
|
return schema.getSchemaFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The configuration used by this core (to load resources, find classes, etc). */
|
|
||||||
private final SolrConfig solrConfig;
|
|
||||||
private Map<String,SolrInfoMBean> infoRegistry = new java.util.HashMap<String,SolrInfoMBean>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since solr 1.3
|
* @since solr 1.3
|
||||||
|
|
|
@ -371,9 +371,9 @@ public class XmlUpdateRequestHandler extends RequestHandlerBase
|
||||||
* @since solr 1.2
|
* @since solr 1.2
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void doLegacyUpdate(SolrCore core, Reader input, Writer output) {
|
public void doLegacyUpdate(Reader input, Writer output) {
|
||||||
try {
|
try {
|
||||||
//SolrCore core = SolrCore.getSolrCore();
|
SolrCore core = SolrCore.getSolrCore();
|
||||||
|
|
||||||
// Old style requests do not choose a custom handler
|
// Old style requests do not choose a custom handler
|
||||||
UpdateRequestProcessorFactory processorFactory = core.getUpdateProcessorFactory( null );
|
UpdateRequestProcessorFactory processorFactory = core.getUpdateProcessorFactory( null );
|
||||||
|
|
|
@ -156,7 +156,9 @@ public class TestHarness {
|
||||||
StringReader req = new StringReader(xml);
|
StringReader req = new StringReader(xml);
|
||||||
StringWriter writer = new StringWriter(32000);
|
StringWriter writer = new StringWriter(32000);
|
||||||
|
|
||||||
updater.doLegacyUpdate(core, req, writer);
|
// This relies on the fact that SolrCore.getSolrCore() uses the
|
||||||
|
// last instantiated SolrCore.
|
||||||
|
updater.doLegacyUpdate(req, writer);
|
||||||
return writer.toString();
|
return writer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class SolrRequestParserTest extends AbstractSolrTestCase {
|
||||||
|
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
parser = new SolrRequestParsers(h.getCore() );
|
parser = new SolrRequestParsers( true, Long.MAX_VALUE );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStreamBody() throws Exception
|
public void testStreamBody() throws Exception
|
||||||
|
@ -57,19 +57,21 @@ public class SolrRequestParserTest extends AbstractSolrTestCase {
|
||||||
String body2 = "qwertasdfgzxcvb";
|
String body2 = "qwertasdfgzxcvb";
|
||||||
String body3 = "1234567890";
|
String body3 = "1234567890";
|
||||||
|
|
||||||
|
SolrCore core = SolrCore.getSolrCore();
|
||||||
|
|
||||||
Map<String,String[]> args = new HashMap<String, String[]>();
|
Map<String,String[]> args = new HashMap<String, String[]>();
|
||||||
args.put( CommonParams.STREAM_BODY, new String[] {body1} );
|
args.put( CommonParams.STREAM_BODY, new String[] {body1} );
|
||||||
|
|
||||||
// Make sure it got a single stream in and out ok
|
// Make sure it got a single stream in and out ok
|
||||||
List<ContentStream> streams = new ArrayList<ContentStream>();
|
List<ContentStream> streams = new ArrayList<ContentStream>();
|
||||||
parser.buildRequestFrom( new MultiMapSolrParams( args ), streams );
|
parser.buildRequestFrom( core, new MultiMapSolrParams( args ), streams );
|
||||||
assertEquals( 1, streams.size() );
|
assertEquals( 1, streams.size() );
|
||||||
assertEquals( body1, IOUtils.toString( streams.get(0).getStream() ) );
|
assertEquals( body1, IOUtils.toString( streams.get(0).getStream() ) );
|
||||||
|
|
||||||
// Now add three and make sure they come out ok
|
// Now add three and make sure they come out ok
|
||||||
streams = new ArrayList<ContentStream>();
|
streams = new ArrayList<ContentStream>();
|
||||||
args.put( CommonParams.STREAM_BODY, new String[] {body1,body2,body3} );
|
args.put( CommonParams.STREAM_BODY, new String[] {body1,body2,body3} );
|
||||||
parser.buildRequestFrom( new MultiMapSolrParams( args ), streams );
|
parser.buildRequestFrom( core, new MultiMapSolrParams( args ), streams );
|
||||||
assertEquals( 3, streams.size() );
|
assertEquals( 3, streams.size() );
|
||||||
ArrayList<String> input = new ArrayList<String>();
|
ArrayList<String> input = new ArrayList<String>();
|
||||||
ArrayList<String> output = new ArrayList<String>();
|
ArrayList<String> output = new ArrayList<String>();
|
||||||
|
@ -88,7 +90,7 @@ public class SolrRequestParserTest extends AbstractSolrTestCase {
|
||||||
String ctype = "text/xxx";
|
String ctype = "text/xxx";
|
||||||
streams = new ArrayList<ContentStream>();
|
streams = new ArrayList<ContentStream>();
|
||||||
args.put( CommonParams.STREAM_CONTENTTYPE, new String[] {ctype} );
|
args.put( CommonParams.STREAM_CONTENTTYPE, new String[] {ctype} );
|
||||||
parser.buildRequestFrom( new MultiMapSolrParams( args ), streams );
|
parser.buildRequestFrom( core, new MultiMapSolrParams( args ), streams );
|
||||||
for( ContentStream s : streams ) {
|
for( ContentStream s : streams ) {
|
||||||
assertEquals( ctype, s.getContentType() );
|
assertEquals( ctype, s.getContentType() );
|
||||||
}
|
}
|
||||||
|
@ -108,13 +110,15 @@ public class SolrRequestParserTest extends AbstractSolrTestCase {
|
||||||
fail( "this test only works if you have a network connection." );
|
fail( "this test only works if you have a network connection." );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SolrCore core = SolrCore.getSolrCore();
|
||||||
|
|
||||||
Map<String,String[]> args = new HashMap<String, String[]>();
|
Map<String,String[]> args = new HashMap<String, String[]>();
|
||||||
args.put( CommonParams.STREAM_URL, new String[] {url} );
|
args.put( CommonParams.STREAM_URL, new String[] {url} );
|
||||||
|
|
||||||
// Make sure it got a single stream in and out ok
|
// Make sure it got a single stream in and out ok
|
||||||
List<ContentStream> streams = new ArrayList<ContentStream>();
|
List<ContentStream> streams = new ArrayList<ContentStream>();
|
||||||
parser.buildRequestFrom( new MultiMapSolrParams( args ), streams );
|
parser.buildRequestFrom( core, new MultiMapSolrParams( args ), streams );
|
||||||
assertEquals( 1, streams.size() );
|
assertEquals( 1, streams.size() );
|
||||||
assertEquals( txt, IOUtils.toString( streams.get(0).getStream() ) );
|
assertEquals( txt, IOUtils.toString( streams.get(0).getStream() ) );
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@ import org.apache.solr.common.params.MapSolrParams;
|
||||||
import org.apache.solr.common.params.SolrParams;
|
import org.apache.solr.common.params.SolrParams;
|
||||||
import org.apache.solr.common.util.ContentStream;
|
import org.apache.solr.common.util.ContentStream;
|
||||||
import org.apache.solr.common.util.ContentStreamBase;
|
import org.apache.solr.common.util.ContentStreamBase;
|
||||||
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.request.QueryResponseWriter;
|
import org.apache.solr.request.QueryResponseWriter;
|
||||||
|
@ -59,7 +58,7 @@ public class DirectSolrConnection
|
||||||
public DirectSolrConnection()
|
public DirectSolrConnection()
|
||||||
{
|
{
|
||||||
core = SolrCore.getSolrCore();
|
core = SolrCore.getSolrCore();
|
||||||
parser = new SolrRequestParsers( core );
|
parser = new SolrRequestParsers( true, Long.MAX_VALUE );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,7 +67,7 @@ public class DirectSolrConnection
|
||||||
public DirectSolrConnection( SolrCore c )
|
public DirectSolrConnection( SolrCore c )
|
||||||
{
|
{
|
||||||
core = c;
|
core = c;
|
||||||
parser = new SolrRequestParsers( core );
|
parser = new SolrRequestParsers( true, Long.MAX_VALUE );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,27 +99,20 @@ public class DirectSolrConnection
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO! Set the instance directory
|
// Initalize SolrConfig
|
||||||
// if( instanceDir != null ) {
|
SolrConfig config = null;
|
||||||
// if( Config.isInstanceDirInitialized() ) {
|
try {
|
||||||
// String dir = Config.getInstanceDir();
|
config = new SolrConfig(instanceDir, SolrConfig.DEFAULT_CONF_FILE, null);
|
||||||
// if( !dir.equals( instanceDir ) ) {
|
instanceDir = config.getInstanceDir();
|
||||||
// throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "already initalized: "+dir );
|
|
||||||
// }
|
// If the Data directory is specified, initialize SolrCore directly
|
||||||
// }
|
|
||||||
// Config.setInstanceDir( instanceDir );
|
|
||||||
// }
|
|
||||||
SolrConfig config = SolrConfig.createInstance("solrconfig.xml");
|
|
||||||
|
|
||||||
// If the Data directory is specified, initialize SolrCore directly
|
|
||||||
if( dataDir != null ) {
|
|
||||||
IndexSchema schema = new IndexSchema(config, instanceDir+"/conf/schema.xml");
|
IndexSchema schema = new IndexSchema(config, instanceDir+"/conf/schema.xml");
|
||||||
core = new SolrCore( dataDir, config, schema );
|
core = new SolrCore( dataDir, config, schema );
|
||||||
|
parser = new SolrRequestParsers( true, Long.MAX_VALUE );
|
||||||
|
}
|
||||||
|
catch (Exception ee) {
|
||||||
|
throw new RuntimeException(ee);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
core = SolrCore.getSolrCore();
|
|
||||||
}
|
|
||||||
parser = new SolrRequestParsers( core );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -165,7 +157,7 @@ public class DirectSolrConnection
|
||||||
streams.add( new ContentStreamBase.StringStream( body ) );
|
streams.add( new ContentStreamBase.StringStream( body ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
SolrQueryRequest req = parser.buildRequestFrom( params, streams );
|
SolrQueryRequest req = parser.buildRequestFrom( core, params, streams );
|
||||||
SolrQueryResponse rsp = new SolrQueryResponse();
|
SolrQueryResponse rsp = new SolrQueryResponse();
|
||||||
core.execute( handler, req, rsp );
|
core.execute( handler, req, rsp );
|
||||||
if( rsp.getException() != null ) {
|
if( rsp.getException() != null ) {
|
||||||
|
|
|
@ -34,6 +34,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.apache.solr.common.SolrException;
|
import org.apache.solr.common.SolrException;
|
||||||
import org.apache.solr.common.params.CommonParams;
|
import org.apache.solr.common.params.CommonParams;
|
||||||
|
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.request.QueryResponseWriter;
|
import org.apache.solr.request.QueryResponseWriter;
|
||||||
|
@ -57,18 +58,31 @@ 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()");
|
||||||
|
|
||||||
|
boolean abortOnConfigurationError = true;
|
||||||
try {
|
try {
|
||||||
// web.xml configuration
|
// web.xml configuration
|
||||||
this.pathPrefix = config.getInitParameter( "path-prefix" );
|
this.pathPrefix = config.getInitParameter( "path-prefix" );
|
||||||
|
|
||||||
log.info("user.dir=" + System.getProperty("user.dir"));
|
log.info("user.dir=" + System.getProperty("user.dir"));
|
||||||
core = SolrCore.getSolrCore();
|
core = SolrCore.getSolrCore();
|
||||||
parsers = new SolrRequestParsers( core );
|
|
||||||
|
// Read the configuration
|
||||||
|
Config solrConfig = core.getSolrConfig();
|
||||||
|
|
||||||
|
long uploadLimitKB = solrConfig.getInt(
|
||||||
|
"requestDispatcher/requestParsers/@multipartUploadLimitInKB", 2000 ); // 2MB default
|
||||||
|
|
||||||
|
boolean enableRemoteStreams = solrConfig.getBool(
|
||||||
|
"requestDispatcher/requestParsers/@enableRemoteStreaming", false );
|
||||||
|
|
||||||
|
parsers = new SolrRequestParsers( enableRemoteStreams, uploadLimitKB );
|
||||||
|
|
||||||
// Let this filter take care of /select?xxx format
|
// Let this filter take care of /select?xxx format
|
||||||
this.handleSelect =
|
this.handleSelect = solrConfig.getBool( "requestDispatcher/@handleSelect", false );
|
||||||
core.getSolrConfig().getBool( "requestDispatcher/@handleSelect", false );
|
|
||||||
|
// should it keep going if we hit an error?
|
||||||
|
abortOnConfigurationError = solrConfig.getBool("abortOnConfigurationError",true);
|
||||||
}
|
}
|
||||||
catch( Throwable t ) {
|
catch( Throwable t ) {
|
||||||
// catch this so our filter still works
|
// catch this so our filter still works
|
||||||
|
@ -78,7 +92,6 @@ public class SolrDispatchFilter implements Filter
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optionally abort if we found a sever error
|
// Optionally abort if we found a sever error
|
||||||
boolean abortOnConfigurationError = core.getSolrConfig().getBool("abortOnConfigurationError",true);
|
|
||||||
if( abortOnConfigurationError && SolrConfig.severeErrors.size() > 0 ) {
|
if( abortOnConfigurationError && SolrConfig.severeErrors.size() > 0 ) {
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
PrintWriter out = new PrintWriter( sw );
|
PrintWriter out = new PrintWriter( sw );
|
||||||
|
@ -142,7 +155,7 @@ public class SolrDispatchFilter implements Filter
|
||||||
}
|
}
|
||||||
if( handler == null && handleSelect ) {
|
if( handler == null && handleSelect ) {
|
||||||
if( "/select".equals( path ) || "/select/".equals( path ) ) {
|
if( "/select".equals( path ) || "/select/".equals( path ) ) {
|
||||||
solrReq = parsers.parse( path, req );
|
solrReq = parsers.parse( core, path, req );
|
||||||
String qt = solrReq.getParams().get( CommonParams.QT );
|
String qt = solrReq.getParams().get( CommonParams.QT );
|
||||||
if( qt != null && qt.startsWith( "/" ) ) {
|
if( qt != null && qt.startsWith( "/" ) ) {
|
||||||
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Invalid query type. Do not use /select to access: "+qt);
|
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Invalid query type. Do not use /select to access: "+qt);
|
||||||
|
@ -155,7 +168,7 @@ public class SolrDispatchFilter implements Filter
|
||||||
}
|
}
|
||||||
if( handler != null ) {
|
if( handler != null ) {
|
||||||
if( solrReq == null ) {
|
if( solrReq == null ) {
|
||||||
solrReq = parsers.parse( path, req );
|
solrReq = parsers.parse( core, path, req );
|
||||||
}
|
}
|
||||||
SolrQueryResponse solrRsp = new SolrQueryResponse();
|
SolrQueryResponse solrRsp = new SolrQueryResponse();
|
||||||
this.execute( req, handler, solrReq, solrRsp );
|
this.execute( req, handler, solrReq, solrRsp );
|
||||||
|
|
|
@ -42,8 +42,6 @@ import org.apache.solr.common.params.MultiMapSolrParams;
|
||||||
import org.apache.solr.common.params.SolrParams;
|
import org.apache.solr.common.params.SolrParams;
|
||||||
import org.apache.solr.common.util.ContentStream;
|
import org.apache.solr.common.util.ContentStream;
|
||||||
import org.apache.solr.common.util.ContentStreamBase;
|
import org.apache.solr.common.util.ContentStreamBase;
|
||||||
import org.apache.solr.core.Config;
|
|
||||||
import org.apache.solr.core.SolrConfig;
|
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.request.ServletSolrParams;
|
import org.apache.solr.request.ServletSolrParams;
|
||||||
import org.apache.solr.request.SolrQueryRequest;
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
|
@ -61,22 +59,13 @@ public class SolrRequestParsers
|
||||||
public static final String STANDARD = "standard";
|
public static final String STANDARD = "standard";
|
||||||
|
|
||||||
private HashMap<String, SolrRequestParser> parsers;
|
private HashMap<String, SolrRequestParser> parsers;
|
||||||
private SolrCore core;
|
|
||||||
private boolean enableRemoteStreams = false;
|
private boolean enableRemoteStreams = false;
|
||||||
private StandardRequestParser standard;
|
private StandardRequestParser standard;
|
||||||
|
|
||||||
public SolrRequestParsers( SolrCore core )
|
public SolrRequestParsers( boolean enableRemoteStreams, long uploadLimitKB )
|
||||||
{
|
{
|
||||||
this.core = core;
|
this.enableRemoteStreams = enableRemoteStreams;
|
||||||
Config config = core.getSolrConfig();
|
|
||||||
|
|
||||||
// Read the configuration
|
|
||||||
long uploadLimitKB = config.getInt(
|
|
||||||
"requestDispatcher/requestParsers/@multipartUploadLimitInKB", 2000 ); // 2MB default
|
|
||||||
|
|
||||||
this.enableRemoteStreams = config.getBool(
|
|
||||||
"requestDispatcher/requestParsers/@enableRemoteStreaming", false );
|
|
||||||
|
|
||||||
MultipartRequestParser multi = new MultipartRequestParser( uploadLimitKB );
|
MultipartRequestParser multi = new MultipartRequestParser( uploadLimitKB );
|
||||||
RawRequestParser raw = new RawRequestParser();
|
RawRequestParser raw = new RawRequestParser();
|
||||||
standard = new StandardRequestParser( multi, raw );
|
standard = new StandardRequestParser( multi, raw );
|
||||||
|
@ -91,7 +80,7 @@ public class SolrRequestParsers
|
||||||
parsers.put( "", standard );
|
parsers.put( "", standard );
|
||||||
}
|
}
|
||||||
|
|
||||||
public SolrQueryRequest parse( String path, HttpServletRequest req ) throws Exception
|
public SolrQueryRequest parse( SolrCore core, String path, HttpServletRequest req ) throws Exception
|
||||||
{
|
{
|
||||||
SolrRequestParser parser = standard;
|
SolrRequestParser parser = standard;
|
||||||
|
|
||||||
|
@ -100,7 +89,7 @@ public class SolrRequestParsers
|
||||||
// Pick the parser from the request...
|
// Pick the parser from the request...
|
||||||
ArrayList<ContentStream> streams = new ArrayList<ContentStream>(1);
|
ArrayList<ContentStream> streams = new ArrayList<ContentStream>(1);
|
||||||
SolrParams params = parser.parseParamsAndFillStreams( req, streams );
|
SolrParams params = parser.parseParamsAndFillStreams( req, streams );
|
||||||
SolrQueryRequest sreq = buildRequestFrom( params, streams );
|
SolrQueryRequest sreq = buildRequestFrom( core, params, streams );
|
||||||
|
|
||||||
// Handlers and loggin will want to know the path. If it contains a ':'
|
// Handlers and loggin will want to know the path. If it contains a ':'
|
||||||
// the handler could use it for RESTfull URLs
|
// the handler could use it for RESTfull URLs
|
||||||
|
@ -108,7 +97,7 @@ public class SolrRequestParsers
|
||||||
return sreq;
|
return sreq;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SolrQueryRequest buildRequestFrom( SolrParams params, Collection<ContentStream> streams ) throws Exception
|
public SolrQueryRequest buildRequestFrom( SolrCore core, SolrParams params, Collection<ContentStream> streams ) throws Exception
|
||||||
{
|
{
|
||||||
// The content type will be applied to all streaming content
|
// The content type will be applied to all streaming content
|
||||||
String contentType = params.get( CommonParams.STREAM_CONTENTTYPE );
|
String contentType = params.get( CommonParams.STREAM_CONTENTTYPE );
|
||||||
|
|
|
@ -25,7 +25,6 @@ import javax.servlet.http.HttpServlet;
|
||||||
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.SolrCore;
|
|
||||||
import org.apache.solr.handler.XmlUpdateRequestHandler;
|
import org.apache.solr.handler.XmlUpdateRequestHandler;
|
||||||
import org.apache.solr.request.QueryResponseWriter;
|
import org.apache.solr.request.QueryResponseWriter;
|
||||||
import org.apache.solr.request.XMLResponseWriter;
|
import org.apache.solr.request.XMLResponseWriter;
|
||||||
|
@ -40,6 +39,7 @@ public class SolrUpdateServlet extends HttpServlet {
|
||||||
XmlUpdateRequestHandler legacyUpdateHandler;
|
XmlUpdateRequestHandler legacyUpdateHandler;
|
||||||
XMLResponseWriter xmlResponseWriter;
|
XMLResponseWriter xmlResponseWriter;
|
||||||
|
|
||||||
|
@Override
|
||||||
public void init() throws ServletException
|
public void init() throws ServletException
|
||||||
{
|
{
|
||||||
legacyUpdateHandler = new XmlUpdateRequestHandler();
|
legacyUpdateHandler = new XmlUpdateRequestHandler();
|
||||||
|
@ -48,12 +48,12 @@ public class SolrUpdateServlet extends HttpServlet {
|
||||||
log.info("SolrUpdateServlet.init() done");
|
log.info("SolrUpdateServlet.init() done");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
BufferedReader requestReader = request.getReader();
|
BufferedReader requestReader = request.getReader();
|
||||||
response.setContentType(QueryResponseWriter.CONTENT_TYPE_XML_UTF8);
|
response.setContentType(QueryResponseWriter.CONTENT_TYPE_XML_UTF8);
|
||||||
|
|
||||||
SolrCore core = SolrCore.getSolrCore();
|
|
||||||
PrintWriter writer = response.getWriter();
|
PrintWriter writer = response.getWriter();
|
||||||
legacyUpdateHandler.doLegacyUpdate(core,requestReader, writer);
|
legacyUpdateHandler.doLegacyUpdate(requestReader, writer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue