Search in sources :

Example 71 with WebAppContext

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;
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) DispatcherType(javax.servlet.DispatcherType) File(java.io.File)

Example 72 with WebAppContext

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;
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext)

Example 73 with WebAppContext

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);
    }
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) org.eclipse.jetty.server(org.eclipse.jetty.server) EmbedServerException(com.blade.exception.EmbedServerException) Config(com.blade.kit.base.Config) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) BladeInitListener(com.blade.mvc.context.BladeInitListener) EmbedServerException(com.blade.exception.EmbedServerException) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet)

Example 74 with WebAppContext

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();
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Server(org.eclipse.jetty.server.Server)

Example 75 with WebAppContext

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());
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) Test(org.junit.Test)

Aggregations

WebAppContext (org.eclipse.jetty.webapp.WebAppContext)142 Server (org.eclipse.jetty.server.Server)58 File (java.io.File)37 Test (org.junit.Test)29 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)20 ServerConnector (org.eclipse.jetty.server.ServerConnector)18 URL (java.net.URL)16 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)10 URI (java.net.URI)10 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)9 FileWriter (java.io.FileWriter)7 Configuration (org.apache.hadoop.conf.Configuration)7 HashLoginService (org.eclipse.jetty.security.HashLoginService)7 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)7 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)7 ServletMapping (org.eclipse.jetty.servlet.ServletMapping)7 BeforeClass (org.junit.BeforeClass)7 OutputStream (java.io.OutputStream)6 InitialContext (javax.naming.InitialContext)6