Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

running couchdb-lucene using .war file #118

Merged
merged 4 commits into from

2 participants

@cliffano

couchdb-lucene-.war can now be generated using mvn war:war.
coucdbb-lucene--dist.zip stays the same, built using the assembly descriptor.

Extracted config handling to com.github.rnewson.couchdb.lucene.Config, now used by both com.github.rnewson.couchdb.lucene.Main and com.github.rnewson.couchdb.lucene.LuceneServlet no-argument constructor. LuceneServlet no-arg constructor is useful for web.xml config.

cliffano added some commits
@cliffano cliffano Added no-argument constructor to LuceneServlet, handy for web.xml set…
…ting when running via Tomcat. Extracted configuration handling to Config class, used by Main and LuceneServlet's no-arg constructor.
2977df2
@cliffano cliffano Added web.xml and renamed main/conf to main/resources, both to simpli…
…fy war file build using mvn war:war. Assembly descriptor still puts those resources files to conf dir in -dist.zip .
a260e07
@cliffano cliffano Added documentation about building a .war file. 1c08058
@cliffano

Forgot to add, the .war file is handy for running couchdb-lucene on a servlet container like Tomcat.

@cliffano cliffano closed this
@cliffano cliffano reopened this
@rnewson
Owner

Hi Cliffano,

I like the idea of running (optionally) from a WAR file. The commits contain a considerable about of reformatting / white space changes, which makes it hard to see the substantive changes, I'd be grateful if you could fix those and send an updated pull request.

@cliffano

Whoops, didn't realise I mangled the indentation. It's all good now.

I think my last commit is automatically included in this pull request https://github.com/rnewson/couchdb-lucene/pull/118/files .

@rnewson rnewson merged commit 0081272 into rnewson:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 19, 2011
  1. @cliffano

    Added no-argument constructor to LuceneServlet, handy for web.xml set…

    cliffano authored
    …ting when running via Tomcat. Extracted configuration handling to Config class, used by Main and LuceneServlet's no-arg constructor.
Commits on May 25, 2011
  1. @cliffano

    Added web.xml and renamed main/conf to main/resources, both to simpli…

    cliffano authored
    …fy war file build using mvn war:war. Assembly descriptor still puts those resources files to conf dir in -dist.zip .
  2. @cliffano
Commits on May 26, 2011
  1. @cliffano
This page is out of date. Refresh to see the latest.
View
6 README.md
@@ -42,6 +42,12 @@ brew install couchdb-lucene
The zip file contains all the couchdb-lucene code, dependencies, startup scripts and configuration files you need, so unzip it wherever you wish to install couchdb-lucene.
+If you want to run couchdb-lucene on a servlet container like Tomcat, you can build the war file using Maven
+
+<pre>
+mvn war:war
+</pre>
+
<h1>Configure CouchDB</h1>
The following settings are needed in CouchDB's local.ini file in order for it to communicate with couchdb-lucene;
View
4 src/main/assembly/dist.xml
@@ -26,12 +26,12 @@
<outputDirectory>/bin</outputDirectory>
</file>
<file>
- <source>${project.basedir}/src/main/conf/couchdb-lucene.ini</source>
+ <source>${project.basedir}/src/main/resources/couchdb-lucene.ini</source>
<fileMode>644</fileMode>
<outputDirectory>/conf</outputDirectory>
</file>
<file>
- <source>${project.basedir}/src/main/conf/log4j.xml</source>
+ <source>${project.basedir}/src/main/resources/log4j.xml</source>
<fileMode>644</fileMode>
<outputDirectory>/conf</outputDirectory>
</file>
View
54 src/main/java/com/github/rnewson/couchdb/lucene/Config.java
@@ -0,0 +1,54 @@
+package com.github.rnewson.couchdb.lucene;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalINIConfiguration;
+import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;
+import org.apache.http.client.HttpClient;
+import org.apache.log4j.Logger;
+
+public final class Config {
+
+ private static final Logger LOG = Logger.getLogger(Config.class);
+
+ private static final String CONFIG_FILE = "couchdb-lucene.ini";
+ private static final String LUCENE_DIR = "lucene.dir";
+ private static final String DEFAULT_DIR = "indexes";
+
+ private final HierarchicalINIConfiguration configuration;
+
+ public Config() throws ConfigurationException {
+ this.configuration = new HierarchicalINIConfiguration(Config.class
+ .getClassLoader().getResource(CONFIG_FILE));
+ this.configuration
+ .setReloadingStrategy(new FileChangedReloadingStrategy());
+ }
+
+ public final HierarchicalINIConfiguration getConfiguration() {
+ return this.configuration;
+ }
+
+ public final File getDir() throws IOException {
+ final File dir = new File(this.configuration.getString(LUCENE_DIR,
+ DEFAULT_DIR));
+ if (!dir.exists() && !dir.mkdir()) {
+ throw new IOException("Could not create " + dir.getCanonicalPath());
+ }
+ if (!dir.canRead()) {
+ throw new IOException(dir + " is not readable.");
+ }
+ if (!dir.canWrite()) {
+ throw new IOException(dir + " is not writable.");
+ }
+ LOG.info("Index output goes to: " + dir.getCanonicalPath());
+ return dir;
+ }
+
+ public final HttpClient getClient() throws MalformedURLException {
+ HttpClientFactory.setIni(this.configuration);
+ return HttpClientFactory.getInstance();
+ }
+}
View
7 src/main/java/com/github/rnewson/couchdb/lucene/LuceneServlet.java
@@ -30,6 +30,7 @@
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.HierarchicalINIConfiguration;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
@@ -61,6 +62,12 @@
private final Map<Database, Thread> threads = new HashMap<Database, Thread>();
+ public LuceneServlet() throws ConfigurationException, IOException {
+ final Config config = new Config();
+ this.client = config.getClient();
+ this.root = config.getDir();
+ this.ini = config.getConfiguration();
+ }
public LuceneServlet(final HttpClient client, final File root,
final HierarchicalINIConfiguration ini) {
this.client = client;
View
36 src/main/java/com/github/rnewson/couchdb/lucene/Main.java
@@ -17,13 +17,7 @@
*/
import java.io.File;
-import java.io.IOException;
-import java.util.Iterator;
-import org.apache.commons.configuration.HierarchicalINIConfiguration;
-import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;
-import org.apache.commons.io.FileUtils;
-import org.apache.http.client.HttpClient;
import org.apache.log4j.Logger;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Handler;
@@ -42,30 +36,13 @@
* Run couchdb-lucene.
*/
public static void main(String[] args) throws Exception {
- final HierarchicalINIConfiguration configuration = new HierarchicalINIConfiguration(
- Main.class.getClassLoader().getResource("couchdb-lucene.ini"));
- configuration.setReloadingStrategy(new FileChangedReloadingStrategy());
-
- final File dir = new File(configuration.getString("lucene.dir", "indexes"));
-
- if (!dir.exists() && !dir.mkdir()) {
- LOG.error("Could not create " + dir.getCanonicalPath());
- System.exit(1);
- }
- if (!dir.canRead()) {
- LOG.error(dir + " is not readable.");
- System.exit(1);
- }
- if (!dir.canWrite()) {
- LOG.error(dir + " is not writable.");
- System.exit(1);
- }
- LOG.info("Index output goes to: " + dir.getCanonicalPath());
+ final Config config = new Config();
+ final File dir = config.getDir();
final Server server = new Server();
final SelectChannelConnector connector = new SelectChannelConnector();
- connector.setHost(configuration.getString("lucene.host", "localhost"));
- connector.setPort(configuration.getInt("lucene.port", 5985));
+ connector.setHost(config.getConfiguration().getString("lucene.host", "localhost"));
+ connector.setPort(config.getConfiguration().getInt("lucene.port", 5985));
LOG.info("Accepting connections with " + connector);
@@ -73,10 +50,7 @@ public static void main(String[] args) throws Exception {
server.setStopAtShutdown(true);
server.setSendServerVersion(false);
- HttpClientFactory.setIni(configuration);
- final HttpClient httpClient = HttpClientFactory.getInstance();
-
- final LuceneServlet servlet = new LuceneServlet(httpClient, dir, configuration);
+ final LuceneServlet servlet = new LuceneServlet(config.getClient(), dir, config.getConfiguration());
final Context context = new Context(server, "/", Context.NO_SESSIONS | Context.NO_SECURITY);
context.addServlet(new ServletHolder(servlet), "/*");
View
0  src/main/conf/couchdb-lucene.ini → src/main/resources/couchdb-lucene.ini
File renamed without changes
View
0  src/main/conf/log4j.xml → src/main/resources/log4j.xml
File renamed without changes
View
19 src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<web-app>
+
+ <display-name>couchdb-lucene</display-name>
+ <description>Enables full-text searching of CouchDB documents using Lucene</description>
+
+ <servlet>
+ <servlet-name>lucene</servlet-name>
+ <servlet-class>com.github.rnewson.couchdb.lucene.LuceneServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>lucene</servlet-name>
+ <url-pattern>/</url-pattern>
+ </servlet-mapping>
+
+</web-app>
View
64 src/test/java/com/github/rnewson/couchdb/lucene/ConfigTest.java
@@ -0,0 +1,64 @@
+package com.github.rnewson.couchdb.lucene;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalINIConfiguration;
+import org.apache.http.client.HttpClient;
+import org.junit.Test;
+
+public class ConfigTest {
+
+ @Test
+ public void testGetConfiguration() {
+ try {
+ final Config config = new Config();
+ HierarchicalINIConfiguration configuration = config
+ .getConfiguration();
+ assertEquals("localhost", configuration.getString("lucene.host"));
+ assertEquals(5985, configuration.getInt("lucene.port"));
+ } catch (ConfigurationException ce) {
+ fail("ConfigurationException shouldn't have been thrown."
+ + ce.getMessage());
+ }
+ }
+
+ @Test
+ public void testGetDir() {
+ try {
+ final Config config = new Config();
+ File dir = config.getDir();
+ assertTrue(dir.exists());
+ assertTrue(dir.canRead());
+ assertTrue(dir.canWrite());
+ assertEquals("target/indexes", dir.getPath());
+ } catch (ConfigurationException ce) {
+ fail("ConfigurationException shouldn't have been thrown."
+ + ce.getMessage());
+ } catch (IOException ioe) {
+ fail("IOException shouldn't have been thrown." + ioe.getMessage());
+ }
+ }
+
+ @Test
+ public void testGetClient() {
+ try {
+ final Config config = new Config();
+ HttpClient client = config.getClient();
+ assertNotNull(client);
+ } catch (ConfigurationException ce) {
+ fail("ConfigurationException shouldn't have been thrown."
+ + ce.getMessage());
+ } catch (MalformedURLException mue) {
+ fail("MalformedURLException shouldn't have been thrown."
+ + mue.getMessage());
+ }
+ }
+}
Something went wrong with that request. Please try again.