use of org.eclipse.jetty.server.handler.HandlerList in project jetty.project by eclipse.
the class AsyncContextDispatchWithQueryStrings method setUp.
@Before
public void setUp() throws Exception {
_connector.setIdleTimeout(30000);
_server.setConnectors(new Connector[] { _connector });
_contextHandler.setContextPath("/");
_contextHandler.addServlet(new ServletHolder(new TestServlet()), "/initialCall");
_contextHandler.addServlet(new ServletHolder(new TestServlet()), "/firstDispatchWithNewQueryString");
_contextHandler.addServlet(new ServletHolder(new TestServlet()), "/secondDispatchNewValueForExistingQueryString");
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { _contextHandler, new DefaultHandler() });
_server.setHandler(handlers);
_server.start();
}
use of org.eclipse.jetty.server.handler.HandlerList in project jetty.project by eclipse.
the class AsyncContextTest method setUp.
@Before
public void setUp() throws Exception {
_server = new Server();
_connector = new LocalConnector(_server);
_connector.setIdleTimeout(5000);
_connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().setSendDateHeader(false);
_server.addConnector(_connector);
_contextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
_contextHandler.setContextPath("/ctx");
_contextHandler.addServlet(new ServletHolder(new TestServlet()), "/servletPath");
_contextHandler.addServlet(new ServletHolder(new TestServlet()), "/path with spaces/servletPath");
_contextHandler.addServlet(new ServletHolder(new TestServlet2()), "/servletPath2");
_contextHandler.addServlet(new ServletHolder(new TestStartThrowServlet()), "/startthrow/*");
_contextHandler.addServlet(new ServletHolder(new ForwardingServlet()), "/forward");
_contextHandler.addServlet(new ServletHolder(new AsyncDispatchingServlet()), "/dispatchingServlet");
_contextHandler.addServlet(new ServletHolder(new ExpireServlet()), "/expire/*");
_contextHandler.addServlet(new ServletHolder(new BadExpireServlet()), "/badexpire/*");
_contextHandler.addServlet(new ServletHolder(new ErrorServlet()), "/error/*");
ErrorPageErrorHandler error_handler = new ErrorPageErrorHandler();
_contextHandler.setErrorHandler(error_handler);
error_handler.addErrorPage(500, "/error/500");
error_handler.addErrorPage(IOException.class.getName(), "/error/IOE");
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { _contextHandler, new DefaultHandler() });
_server.setHandler(handlers);
_server.start();
}
use of org.eclipse.jetty.server.handler.HandlerList in project blade by biezhi.
the class EmbedJettyServer method startup.
@Override
public void startup(int port, String contextPath, String webRoot) throws EmbedServerException {
this.port = port;
Config config = Blade.$().config();
int minThreads = config.getInt("server.jetty.min-threads", 8);
int maxThreads = config.getInt("server.jetty.max-threads", 200);
String poolName = config.get("server.jetty.pool-name", "blade-pool");
// Setup Threadpool
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMinThreads(minThreads);
threadPool.setMaxThreads(maxThreads);
threadPool.setName(poolName);
this.server = new org.eclipse.jetty.server.Server(threadPool);
this.webAppContext = new WebAppContext();
this.webAppContext.setContextPath(contextPath);
this.webAppContext.setResourceBase("");
int securePort = config.getInt("server.jetty.http.secure-port", 9443);
int outputBufferSize = config.getInt("server.jetty.http.output-buffersize", 32 * 1024);
int requestHeaderSize = config.getInt("server.jetty.http.request-headersize", 8 * 1024);
int responseHeaderSize = config.getInt("server.jetty.http.response-headersize", 8 * 1024);
// HTTP Configuration
HttpConfiguration http_config = new HttpConfiguration();
http_config.setSecurePort(securePort);
http_config.setOutputBufferSize(outputBufferSize);
http_config.setRequestHeaderSize(requestHeaderSize);
http_config.setResponseHeaderSize(responseHeaderSize);
long idleTimeout = config.getLong("server.jetty.http.idle-timeout", 30000L);
String host = config.get("server.host", "0.0.0.0");
ServerConnector serverConnector = new ServerConnector(server, new HttpConnectionFactory(http_config));
serverConnector.setHost(host);
serverConnector.setPort(this.port);
serverConnector.setIdleTimeout(idleTimeout);
server.setConnectors(new Connector[] { serverConnector });
boolean isAsync = config.getBoolean("server.async", false);
Class<? extends Servlet> servlet = isAsync ? AsyncDispatcherServlet.class : DispatcherServlet.class;
ServletHolder servletHolder = new ServletHolder(servlet);
servletHolder.setAsyncSupported(isAsync);
servletHolder.setInitOrder(1);
webAppContext.addEventListener(new BladeInitListener());
Set<String> statics = Blade.$().bConfig().getStatics();
defaultHolder = new ServletHolder(DefaultServlet.class);
defaultHolder.setInitOrder(0);
if (StringKit.isNotBlank(classPath)) {
LOGGER.info("add classpath : {}", classPath);
defaultHolder.setInitParameter("resourceBase", classPath);
}
statics.forEach(s -> {
if (s.indexOf(".") != -1) {
webAppContext.addServlet(defaultHolder, s);
} else {
s = s.endsWith("/") ? s + '*' : s + "/*";
webAppContext.addServlet(defaultHolder, s);
}
});
webAppContext.addServlet(defaultHolder, "/favicon.ico");
webAppContext.addServlet(servletHolder, "/");
try {
this.loadServlets(webAppContext);
this.loadFilters(webAppContext);
HandlerList handlerList = new HandlerList();
handlerList.setHandlers(new Handler[] { webAppContext, new DefaultHandler() });
server.setHandler(handlerList);
server.setStopAtShutdown(true);
server.start();
LOGGER.info("Blade Server Listen on {}:{}", host, this.port);
server.join();
} catch (Exception e) {
throw new EmbedServerException(e);
}
}
use of org.eclipse.jetty.server.handler.HandlerList in project Anserini by castorini.
the class TweetSearcher method main.
public static void main(String[] args) throws IOException, InterruptedException, ParseException {
Options options = new Options();
options.addOption(INDEX_OPTION, true, "index path");
options.addOption(PORT_OPTION, true, "port");
CommandLine cmdline = null;
CommandLineParser parser = new GnuParser();
try {
cmdline = parser.parse(options, args);
} catch (org.apache.commons.cli.ParseException e) {
System.err.println("Error parsing command line: " + e.getMessage());
System.exit(-1);
}
if (!cmdline.hasOption(INDEX_OPTION)) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(TweetSearcher.class.getName(), options);
System.exit(-1);
}
int port = cmdline.hasOption(PORT_OPTION) ? Integer.parseInt(cmdline.getOptionValue(PORT_OPTION)) : 8080;
TweetSearcher nrtsearch = new TweetSearcher(cmdline.getOptionValue(INDEX_OPTION));
TweetStreamIndexer its = new TweetStreamIndexer();
Thread itsThread = new Thread(its);
itsThread.start();
LOG.info("Starting HTTP server on port " + port);
HandlerList mainHandler = new HandlerList();
Server server = new Server(port);
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setWelcomeFiles(new String[] { "index.html" });
resource_handler.setResourceBase("src/main/java/io/anserini/nrts/public");
ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS);
handler.setContextPath("/");
ServletHolder jerseyServlet = new ServletHolder(ServletContainer.class);
jerseyServlet.setInitParameter("jersey.config.server.provider.classnames", TweetSearcherAPI.class.getCanonicalName());
handler.addServlet(jerseyServlet, "/*");
mainHandler.addHandler(resource_handler);
mainHandler.addHandler(handler);
server.setHandler(mainHandler);
try {
server.start();
LOG.info("Accepting connections on port " + port);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
server.join();
itsThread.join();
nrtsearch.close();
}
use of org.eclipse.jetty.server.handler.HandlerList in project webtools.servertools by eclipse.
the class PreviewStarter method run.
protected void run() {
try {
System.setProperty("org.mortbay.log.class", "org.eclipse.wst.server.preview.internal.WTPLogger");
ServerConfig config = new ServerConfig(configPath);
System.out.println("Starting preview server on port " + config.getPort());
System.out.println();
Module[] m = config.getModules();
int size = m.length;
if (size > 0) {
System.out.println("Modules:");
for (Module mm : m) System.out.println(" " + mm.getName() + " (" + mm.getContext() + ")");
System.out.println();
}
server = new Server(config.getPort());
server.setStopAtShutdown(true);
WTPErrorHandler errorHandler = new WTPErrorHandler();
HandlerList handlers = new HandlerList();
for (Module module : m) {
if (module.isStaticWeb()) {
ContextResourceHandler resourceHandler = new ContextResourceHandler();
resourceHandler.setResourceBase(module.getPath());
resourceHandler.setContext(module.getContext());
handlers.addHandler(resourceHandler);
} else {
WebAppContext wac = new WebAppContext();
wac.setContextPath(module.getContext());
wac.setWar(module.getPath());
wac.setErrorHandler(errorHandler);
handlers.addHandler(wac);
}
}
handlers.addHandler(new WTPDefaultHandler(config.getPort(), m));
server.setHandler(handlers);
try {
server.start();
} catch (Exception e) {
e.printStackTrace();
}
} catch (Throwable e) {
e.printStackTrace();
}
}
Aggregations