mirror of https://github.com/apache/lucene.git
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:
parent
d63338bd35
commit
1a66aa3853
|
@ -1,11 +1,11 @@
|
||||||
<?xml version="1.0" ?>
|
<?xml version="1.0" ?>
|
||||||
<!-- The Solr schema file. This file should be named "schema.xml" and
|
<!-- The Solr schema file. This file should be named "schema.xml" and
|
||||||
should be in the solrconf directory or located where the classloader
|
should be in the conf directory under the solr home
|
||||||
for the Solr webapp can find it.
|
(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...
|
For more information, on how to customize this file, please see...
|
||||||
http://wiki.apache.org/solr/SchemaXml
|
http://wiki.apache.org/solr/SchemaXml
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<schema name="example" version="1.1">
|
<schema name="example" version="1.1">
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<config>
|
<config>
|
||||||
|
|
||||||
<!-- Used to specify an alternate directory to hold all index data
|
<!-- 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. -->
|
If replication is in use, this should match the replication configuration. -->
|
||||||
<!--
|
<!--
|
||||||
<dataDir>./solr/data</dataDir>
|
<dataDir>./solr/data</dataDir>
|
||||||
|
|
|
@ -214,23 +214,32 @@ public class Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String instanceDir; // solr home directory
|
||||||
private static String instance = project;
|
private static String normalizeDir(String path) {
|
||||||
public static void setInstanceName(String name) {
|
if (path==null) return null;
|
||||||
instance = name;
|
if ( !(path.endsWith("/") || path.endsWith("\\")) ) {
|
||||||
|
path+='/';
|
||||||
}
|
}
|
||||||
public static String getInstanceName() {
|
return path;
|
||||||
return instance;
|
}
|
||||||
|
|
||||||
|
public static void setInstanceDir(String dir) {
|
||||||
|
instanceDir = normalizeDir(dir);
|
||||||
|
log.info("Solr home set to '" + instanceDir + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getInstanceDir() {
|
public static String getInstanceDir() {
|
||||||
String str = System.getProperty(instance + ".solr.home");
|
if (instanceDir==null) {
|
||||||
if (str==null) {
|
String prop = project + ".solr.home";
|
||||||
str=instance + '/';
|
instanceDir = normalizeDir(System.getProperty(prop));
|
||||||
} else if ( !(str.endsWith("/") || str.endsWith("\\")) ) {
|
if (instanceDir==null) {
|
||||||
str+='/';
|
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.
|
// The directory where solr will look for config files by default.
|
||||||
|
|
|
@ -15,12 +15,13 @@
|
||||||
"com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"/>
|
"com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"/>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>SolrServer</servlet-name>
|
<servlet-name>SolrServer</servlet-name>
|
||||||
<display-name>Solr</display-name>
|
<display-name>Solr</display-name>
|
||||||
<description>Solr Server</description>
|
<description>Solr Server</description>
|
||||||
<servlet-class>org.apache.solr.servlet.SolrServlet</servlet-class>
|
<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>
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
|
@ -28,7 +29,7 @@
|
||||||
<display-name>SolrUpdate</display-name>
|
<display-name>SolrUpdate</display-name>
|
||||||
<description>Solr Update Handler</description>
|
<description>Solr Update Handler</description>
|
||||||
<servlet-class>org.apache.solr.servlet.SolrUpdateServlet</servlet-class>
|
<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>
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
org.apache.solr.schema.IndexSchema,
|
org.apache.solr.schema.IndexSchema,
|
||||||
java.io.File"%>
|
java.io.File"%>
|
||||||
<%@ page import="java.net.InetAddress"%>
|
<%@ page import="java.net.InetAddress"%>
|
||||||
|
<%@ page import="org.apache.solr.core.Config"%>
|
||||||
|
|
||||||
<%
|
<%
|
||||||
SolrCore core = SolrCore.getSolrCore();
|
SolrCore core = SolrCore.getSolrCore();
|
||||||
|
@ -25,4 +26,5 @@
|
||||||
|
|
||||||
String defaultSearch = SolrConfig.config.get("admin/defaultQuery/text()",null);
|
String defaultSearch = SolrConfig.config.get("admin/defaultQuery/text()",null);
|
||||||
String cwd=System.getProperty("user.dir");
|
String cwd=System.getProperty("user.dir");
|
||||||
|
String solrHome= Config.getInstanceDir();
|
||||||
%>
|
%>
|
||||||
|
|
|
@ -17,4 +17,4 @@ var host_name="<%= hostname %>"
|
||||||
<%= enabledStatus==null ? "" : (isEnabled ? " - Enabled" : " - Disabled") %> </h1>
|
<%= enabledStatus==null ? "" : (isEnabled ? " - Enabled" : " - Disabled") %> </h1>
|
||||||
|
|
||||||
<%= hostname %>:<%= port %><br/>
|
<%= hostname %>:<%= port %><br/>
|
||||||
<%= cwd %>
|
cwd=<%= cwd %> SolrHome=<%= solrHome %>
|
||||||
|
|
|
@ -16,23 +16,23 @@
|
||||||
|
|
||||||
package org.apache.solr.servlet;
|
package org.apache.solr.servlet;
|
||||||
|
|
||||||
import org.apache.solr.core.*;
|
import org.apache.solr.core.Config;
|
||||||
import org.apache.solr.request.*;
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.schema.IndexSchema;
|
import org.apache.solr.core.SolrException;
|
||||||
import org.apache.solr.util.StrUtils;
|
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.ServletException;
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
import javax.servlet.http.HttpServlet;
|
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 java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yonik
|
* @author yonik
|
||||||
|
@ -47,13 +47,27 @@ public class SolrServlet extends HttpServlet {
|
||||||
|
|
||||||
public void init() throws ServletException
|
public void init() throws ServletException
|
||||||
{
|
{
|
||||||
ServletContext ctx = getServletContext();
|
log.info("SolrServlet.init()");
|
||||||
try {
|
try {
|
||||||
System.out.println("RESOURCE URL FOR .="+ctx.getResource("/select"));
|
Context c = new InitialContext();
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
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"));
|
log.info("user.dir=" + System.getProperty("user.dir"));
|
||||||
core = SolrCore.getSolrCore();
|
core = SolrCore.getSolrCore();
|
||||||
|
|
|
@ -42,6 +42,7 @@ public class SolrUpdateServlet extends HttpServlet {
|
||||||
public void init() throws ServletException
|
public void init() throws ServletException
|
||||||
{
|
{
|
||||||
core = SolrCore.getSolrCore();
|
core = SolrCore.getSolrCore();
|
||||||
|
log.info("SolrUpdateServlet.init() done");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
|
Loading…
Reference in New Issue