put back the simple standalone embedded Jetty setup we had for Main some time ago

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@797707 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew Kyle Purtell 2009-07-25 02:47:21 +00:00
parent db8a3e2346
commit 9b13bf2f33
1 changed files with 18 additions and 46 deletions

View File

@ -24,17 +24,11 @@ import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.Options; import org.apache.commons.cli.Options;
import org.apache.commons.cli.PosixParser; import org.apache.commons.cli.PosixParser;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.NCSARequestLog;
import org.mortbay.jetty.Server; import org.mortbay.jetty.Server;
import org.mortbay.jetty.deployer.WebAppDeployer; import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.handler.ContextHandlerCollection; import org.mortbay.jetty.servlet.ServletHolder;
import org.mortbay.jetty.handler.DefaultHandler;
import org.mortbay.jetty.handler.HandlerCollection; import com.sun.jersey.spi.container.servlet.ServletContainer;
import org.mortbay.jetty.handler.RequestLogHandler;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.thread.QueuedThreadPool;
/** /**
* Main class for launching Stargate as a servlet hosted by an embedded Jetty * Main class for launching Stargate as a servlet hosted by an embedded Jetty
@ -58,45 +52,23 @@ public class Main {
port = Integer.valueOf(cmd.getOptionValue("p")); port = Integer.valueOf(cmd.getOptionValue("p"));
} }
/* // set up the Jersey servlet container for Jetty
* poached from: ServletHolder sh = new ServletHolder(ServletContainer.class);
* http://jetty.mortbay.org/xref/org/mortbay/jetty/example/LikeJettyXml.html sh.setInitParameter(
*/ "com.sun.jersey.config.property.resourceConfigClass",
String jetty_home = "."; ResourceConfig.class.getCanonicalName());
Server server = new Server(); sh.setInitParameter("com.sun.jersey.config.property.packages",
"jetty");
QueuedThreadPool threadPool = new QueuedThreadPool(); // set up Jetty and run the embedded server
threadPool.setMaxThreads(100);
server.setThreadPool(threadPool);
Connector connector = new SelectChannelConnector(); Server server = new Server(port);
connector.setPort(port); server.setSendServerVersion(false);
connector.setMaxIdleTime(30000); server.setSendDateHeader(false);
server.setConnectors(new Connector[] { connector });
HandlerCollection handlers = new HandlerCollection();
ContextHandlerCollection contexts = new ContextHandlerCollection();
RequestLogHandler requestLogHandler = new RequestLogHandler();
handlers.setHandlers(new Handler[] { contexts, new DefaultHandler(),
requestLogHandler });
server.setHandler(handlers);
WebAppDeployer deployer1 = new WebAppDeployer();
deployer1.setContexts(contexts);
deployer1.setWebAppDir(jetty_home + "/webapps");
deployer1.setParentLoaderPriority(false);
deployer1.setExtract(true);
deployer1.setAllowDuplicates(false);
// deployer1.setDefaultsDescriptor(jetty_home + "/etc/webdefault.xml");
server.addLifeCycle(deployer1);
NCSARequestLog requestLog = new NCSARequestLog(jetty_home
+ "/logs/jetty-yyyy_mm_dd.log");
requestLog.setExtended(false);
requestLogHandler.setRequestLog(requestLog);
server.setStopAtShutdown(true); server.setStopAtShutdown(true);
server.setSendServerVersion(true); // set up context
Context context = new Context(server, "/", Context.SESSIONS);
context.addServlet(sh, "/*");
server.start(); server.start();
server.join(); server.join();
} }