enable multiple solr webapps with JNDI config

git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@408501 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2006-05-21 21:55:12 +00:00
parent d63338bd35
commit 1a66aa3853
8 changed files with 61 additions and 34 deletions

View File

@ -1,11 +1,11 @@
<?xml version="1.0" ?>
<!-- The Solr schema file. This file should be named "schema.xml" and
should be in the solrconf directory or located where the classloader
for the Solr webapp can find it.
should be in the conf directory under the solr home
(i.e. ./solr/conf/schema.xml by default)
or located where the classloader for the Solr webapp can find it.
For more information, on how to customize this file, please see...
http://wiki.apache.org/solr/SchemaXml
-->
<schema name="example" version="1.1">

View File

@ -3,7 +3,7 @@
<config>
<!-- Used to specify an alternate directory to hold all index data
other than the default ./solr/data
other than the default ./data under the Solr home.
If replication is in use, this should match the replication configuration. -->
<!--
<dataDir>./solr/data</dataDir>

View File

@ -214,23 +214,32 @@ public class Config {
}
}
private static String instance = project;
public static void setInstanceName(String name) {
instance = name;
private static String instanceDir; // solr home directory
private static String normalizeDir(String path) {
if (path==null) return null;
if ( !(path.endsWith("/") || path.endsWith("\\")) ) {
path+='/';
}
public static String getInstanceName() {
return instance;
return path;
}
public static void setInstanceDir(String dir) {
instanceDir = normalizeDir(dir);
log.info("Solr home set to '" + instanceDir + "'");
}
public static String getInstanceDir() {
String str = System.getProperty(instance + ".solr.home");
if (str==null) {
str=instance + '/';
} else if ( !(str.endsWith("/") || str.endsWith("\\")) ) {
str+='/';
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 + "'");
} else {
log.info("Solr home set to '" + instanceDir + "' from system property " + prop);
}
return str;
}
return instanceDir;
}
// The directory where solr will look for config files by default.

View File

@ -15,12 +15,13 @@
"com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"/>
-->
<servlet>
<servlet-name>SolrServer</servlet-name>
<display-name>Solr</display-name>
<description>Solr Server</description>
<servlet-class>org.apache.solr.servlet.SolrServlet</servlet-class>
<load-on-startup>0</load-on-startup>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
@ -28,7 +29,7 @@
<display-name>SolrUpdate</display-name>
<description>Solr Update Handler</description>
<servlet-class>org.apache.solr.servlet.SolrUpdateServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>

View File

@ -3,6 +3,7 @@
org.apache.solr.schema.IndexSchema,
java.io.File"%>
<%@ page import="java.net.InetAddress"%>
<%@ page import="org.apache.solr.core.Config"%>
<%
SolrCore core = SolrCore.getSolrCore();
@ -25,4 +26,5 @@
String defaultSearch = SolrConfig.config.get("admin/defaultQuery/text()",null);
String cwd=System.getProperty("user.dir");
String solrHome= Config.getInstanceDir();
%>

View File

@ -17,4 +17,4 @@ var host_name="<%= hostname %>"
<%= enabledStatus==null ? "" : (isEnabled ? " - Enabled" : " - Disabled") %> </h1>
<%= hostname %>:<%= port %><br/>
<%= cwd %>
cwd=<%= cwd %> SolrHome=<%= solrHome %>

View File

@ -16,23 +16,23 @@
package org.apache.solr.servlet;
import org.apache.solr.core.*;
import org.apache.solr.request.*;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.util.StrUtils;
import org.apache.solr.core.Config;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrException;
import org.apache.solr.request.SolrQueryResponse;
import org.apache.solr.request.XMLResponseWriter;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.NoInitialContextException;
import javax.servlet.ServletException;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.util.logging.Logger;
import java.util.Map;
import java.util.Set;
import java.net.MalformedURLException;
/**
* @author yonik
@ -47,13 +47,27 @@ public class SolrServlet extends HttpServlet {
public void init() throws ServletException
{
ServletContext ctx = getServletContext();
log.info("SolrServlet.init()");
try {
System.out.println("RESOURCE URL FOR .="+ctx.getResource("/select"));
} catch (MalformedURLException e) {
e.printStackTrace();
}
Context c = new InitialContext();
/***
System.out.println("Enumerating JNDI Context=" + c);
NamingEnumeration<NameClassPair> en = c.list("java:comp/env");
while (en.hasMore()) {
NameClassPair ncp = en.next();
System.out.println(" ENTRY:" + ncp);
}
System.out.println("JNDI lookup=" + c.lookup("java:comp/env/solr/home"));
***/
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");
}
log.info("user.dir=" + System.getProperty("user.dir"));
core = SolrCore.getSolrCore();

View File

@ -42,6 +42,7 @@ public class SolrUpdateServlet extends HttpServlet {
public void init() throws ServletException
{
core = SolrCore.getSolrCore();
log.info("SolrUpdateServlet.init() done");
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {