Created
May 15, 2013 06:56
-
-
Save abyrd/5582094 to your computer and use it in GitHub Desktop.
Embedded Jetty Server for OTP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.opentripplanner.api.servlet; | |
import org.eclipse.jetty.server.Connector; | |
import org.eclipse.jetty.server.Server; | |
import org.eclipse.jetty.server.bio.SocketConnector; | |
import org.eclipse.jetty.webapp.WebAppContext; | |
import org.eclipse.jetty.webapp.WebInfConfiguration; | |
import org.eclipse.jetty.webapp.WebXmlConfiguration; | |
public class JettyServer { | |
private static final Server SERVER = new Server(); | |
public static void main(String[] args) { | |
String webapp = "./target/opentripplanner-api-webapp"; | |
if (args.length > 0) { | |
webapp = args[0]; | |
} | |
WebAppContext app = new WebAppContext(); | |
app.setContextPath("/otp"); // the context path of this app in the URL | |
app.setWar(webapp); | |
// Avoid the taglib configuration because its a PITA if you don't have a net connection | |
app.setConfigurationClasses(new String[] { WebInfConfiguration.class.getName(), | |
WebXmlConfiguration.class.getName() }); | |
app.setParentLoaderPriority(true); | |
// We explicitly use the SocketConnector because the SelectChannelConnector locks files | |
Connector connector = new SocketConnector(); | |
connector.setPort(Integer.parseInt(System.getProperty("jetty.port", "8080"))); | |
connector.setMaxIdleTime(60000); | |
JettyServer.SERVER.setConnectors(new Connector[] { connector }); | |
JettyServer.SERVER.setHandler( app ); | |
JettyServer.SERVER.setAttribute("org.mortbay.jetty.Request.maxFormContentSize", 0); | |
JettyServer.SERVER.setStopAtShutdown(true); | |
try { | |
JettyServer.SERVER.start(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment