use of org.eclipse.jetty.webapp.WebAppContext in project zeppelin by apache.
the class ZeppelinServer method setupWebAppContext.
private static WebAppContext setupWebAppContext(ContextHandlerCollection contexts, ZeppelinConfiguration conf) {
WebAppContext webApp = new WebAppContext();
webApp.setContextPath(conf.getServerContextPath());
File warPath = new File(conf.getString(ConfVars.ZEPPELIN_WAR));
if (warPath.isDirectory()) {
// Development mode, read from FS
// webApp.setDescriptor(warPath+"/WEB-INF/web.xml");
webApp.setResourceBase(warPath.getPath());
webApp.setParentLoaderPriority(true);
} else {
// use packaged WAR
webApp.setWar(warPath.getAbsolutePath());
File warTempDirectory = new File(conf.getRelativeDir(ConfVars.ZEPPELIN_WAR_TEMPDIR));
warTempDirectory.mkdir();
LOG.info("ZeppelinServer Webapp path: {}", warTempDirectory.getPath());
webApp.setTempDirectory(warTempDirectory);
}
// Explicit bind to root
webApp.addServlet(new ServletHolder(new DefaultServlet()), "/*");
contexts.addHandler(webApp);
webApp.addFilter(new FilterHolder(CorsFilter.class), "/*", EnumSet.allOf(DispatcherType.class));
webApp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", Boolean.toString(conf.getBoolean(ConfVars.ZEPPELIN_SERVER_DEFAULT_DIR_ALLOWED)));
return webApp;
}
use of org.eclipse.jetty.webapp.WebAppContext in project hive by apache.
the class HttpServer method createWebAppContext.
/**
* Create the web context for the application of specified name
*/
WebAppContext createWebAppContext(Builder b) {
WebAppContext ctx = new WebAppContext();
setContextAttributes(ctx.getServletContext(), b.contextAttrs);
ctx.setDisplayName(b.name);
ctx.setContextPath("/");
ctx.setWar(appDir + "/" + b.name);
return ctx;
}
use of org.eclipse.jetty.webapp.WebAppContext 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.webapp.WebAppContext in project jetty.project by eclipse.
the class DemoServer method main.
public static void main(String[] args) throws Exception {
String jetty_home = System.getProperty("jetty.home", ".");
Server server = new Server(Integer.getInteger("jetty.http.port", 8080).intValue());
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
webapp.setWar(jetty_home + "/target/async-rest/");
webapp.setParentLoaderPriority(true);
webapp.setServerClasses(new String[] {});
server.setHandler(webapp);
server.start();
server.join();
}
use of org.eclipse.jetty.webapp.WebAppContext in project jetty.project by eclipse.
the class TestSecurityAnnotationConversions method testPermitAll.
@Test
public void testPermitAll() throws Exception {
//Assume we found 1 servlet with a @ServletSecurity security annotation
WebAppContext wac = makeWebAppContext(PermitServlet.class.getCanonicalName(), "permitServlet", new String[] { "/foo/*", "*.foo" });
ServletSecurityAnnotationHandler annotationHandler = new ServletSecurityAnnotationHandler(wac);
AnnotationIntrospector introspector = new AnnotationIntrospector();
introspector.registerHandler(annotationHandler);
//set up the expected outcomes - no constraints at all as per Servlet Spec 3.1 pg 129
//1 ConstraintMapping per ServletMapping pathSpec
ConstraintMapping[] expectedMappings = new ConstraintMapping[] {};
introspector.introspect(PermitServlet.class);
compareResults(expectedMappings, ((ConstraintAware) wac.getSecurityHandler()).getConstraintMappings());
}
Aggregations