/* * This file is part of Documancer (http://documancer.sf.net) * * Copyright (C) 2005 Vaclav Slavik * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * $Id: IndexerServer.java,v 1.1 2005/02/05 10:38:15 vaclavslavik Exp $ * * Fulltext indexer XML-RPC server for Java * */ import java.lang.ClassNotFoundException; import org.apache.xmlrpc.XmlRpc; import org.apache.xmlrpc.WebServer; /** XML-RPC server launcher. Starts XML-RPC server that provides Lucene fulltext indexing services as implemented in IndexerService class. */ public class IndexerServer { public static void main(String[] argv) throws ClassNotFoundException { // the default MinML parser is not good enough, it doesn't handle // Unicode input, use Xerces instead: XmlRpc.setDriver("org.apache.xerces.parsers.SAXParser"); XmlRpc.setKeepAlive(true); //XmlRpc.setDebug(true); if (argv.length != 1) { System.err.println("Usage: java IndexerServer "); System.exit(1); } int port = Integer.parseInt(argv[0]); WebServer server = new LocalhostWebServer(port); // register IndexerService as handler for toplevel namespace: server.addHandler("$default", new IndexerService(server)); try { server.start(); } catch (Exception e) { System.err.println("Error running XML-RPC server"); e.printStackTrace(); System.exit(2); } } /** XML-RPC web server that only accepts connections from localhost. */ public static class LocalhostWebServer extends WebServer { public LocalhostWebServer(int port) { super(port); setParanoid(true); } protected boolean allowConnection(java.net.Socket s) { // Only allow incoming connections from localhost: return s.getInetAddress().isLoopbackAddress(); } } }