Search in sources :

Example 56 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project gocd by gocd.

the class AssetsContextHandlerInitializerTest method shouldNotInitializeHandlerOnOtherWebappContextLifeCycleEvents.

@Test
public void shouldNotInitializeHandlerOnOtherWebappContextLifeCycleEvents() throws IOException {
    AssetsContextHandler handler = mock(AssetsContextHandler.class);
    WebAppContext webAppContext = mock(WebAppContext.class);
    AssetsContextHandlerInitializer initializer = new AssetsContextHandlerInitializer(handler, webAppContext);
    initializer.lifeCycleStarting(null);
    verify(handler, never()).init(webAppContext);
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Test(org.junit.Test)

Example 57 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project gocd by gocd.

the class AssetsContextHandlerInitializerTest method shouldInitializeHandlerOnWebappContextLifeCycleStarted.

@Test
public void shouldInitializeHandlerOnWebappContextLifeCycleStarted() throws IOException {
    AssetsContextHandler handler = mock(AssetsContextHandler.class);
    WebAppContext webAppContext = mock(WebAppContext.class);
    AssetsContextHandlerInitializer initializer = new AssetsContextHandlerInitializer(handler, webAppContext);
    initializer.lifeCycleStarted(null);
    verify(handler, times(1)).init(webAppContext);
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Test(org.junit.Test)

Example 58 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project mysql_perf_analyzer by yahoo.

the class App method createDeployedApplicationInstance.

private WebAppContext createDeployedApplicationInstance(File workDirectory, String deployedApplicationPath) {
    WebAppContext deployedApplication = new WebAppContext();
    deployedApplication.setContextPath(this.getContextPath());
    deployedApplication.setWar(deployedApplicationPath);
    deployedApplication.setAttribute("javax.servlet.context.tempdir", workDirectory.getAbsolutePath());
    deployedApplication.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/.*taglibs.*\\.jar$");
    deployedApplication.setAttribute("org.eclipse.jetty.containerInitializers", jspInitializers());
    deployedApplication.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
    deployedApplication.addBean(new ServletContainerInitializersStarter(deployedApplication), true);
    // webapp.setClassLoader(new URLClassLoader(new
    // URL[0],App.class.getClassLoader()));
    deployedApplication.addServlet(jspServletHolder(), "*.jsp");
    return deployedApplication;
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) InstanceManager(org.apache.tomcat.InstanceManager) SimpleInstanceManager(org.apache.tomcat.SimpleInstanceManager) ServletContainerInitializersStarter(org.eclipse.jetty.annotations.ServletContainerInitializersStarter) SimpleInstanceManager(org.apache.tomcat.SimpleInstanceManager)

Example 59 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project opennms by OpenNMS.

the class JUnitServer method initializeServerWithConfig.

protected void initializeServerWithConfig(final JUnitHttpServer config) {
    Server server = null;
    if (config.https()) {
        server = new Server();
        // SSL context configuration
        SslContextFactory sslContextFactory = new SslContextFactory();
        sslContextFactory.setKeyStorePath(config.keystore());
        sslContextFactory.setKeyStorePassword(config.keystorePassword());
        sslContextFactory.setKeyManagerPassword(config.keyPassword());
        sslContextFactory.setTrustStorePath(config.keystore());
        sslContextFactory.setTrustStorePassword(config.keystorePassword());
        // HTTP Configuration
        HttpConfiguration http_config = new HttpConfiguration();
        http_config.setSecureScheme("https");
        http_config.setSecurePort(config.port());
        http_config.setOutputBufferSize(32768);
        http_config.setRequestHeaderSize(8192);
        http_config.setResponseHeaderSize(8192);
        http_config.setSendServerVersion(true);
        http_config.setSendDateHeader(false);
        // SSL HTTP Configuration
        HttpConfiguration https_config = new HttpConfiguration(http_config);
        https_config.addCustomizer(new SecureRequestCustomizer());
        // SSL Connector
        ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(https_config));
        sslConnector.setPort(config.port());
        server.addConnector(sslConnector);
    } else {
        server = new Server(config.port());
    }
    m_server = server;
    final ContextHandler context1 = new ContextHandler();
    context1.setContextPath("/");
    context1.setWelcomeFiles(new String[] { "index.html" });
    context1.setResourceBase(config.resource());
    context1.setClassLoader(Thread.currentThread().getContextClassLoader());
    context1.setVirtualHosts(config.vhosts());
    final ContextHandler context = context1;
    Handler topLevelHandler = null;
    final HandlerList handlers = new HandlerList();
    if (config.basicAuth()) {
        // check for basic auth if we're configured to do so
        LOG.debug("configuring basic auth");
        final HashLoginService loginService = new HashLoginService("MyRealm", config.basicAuthFile());
        loginService.setHotReload(true);
        m_server.addBean(loginService);
        final ConstraintSecurityHandler security = new ConstraintSecurityHandler();
        final Set<String> knownRoles = new HashSet<String>();
        knownRoles.add("user");
        knownRoles.add("admin");
        knownRoles.add("moderator");
        final Constraint constraint = new Constraint();
        constraint.setName("auth");
        constraint.setAuthenticate(true);
        constraint.setRoles(knownRoles.toArray(new String[0]));
        final ConstraintMapping mapping = new ConstraintMapping();
        mapping.setPathSpec("/*");
        mapping.setConstraint(constraint);
        security.setConstraintMappings(Collections.singletonList(mapping), knownRoles);
        security.setAuthenticator(new BasicAuthenticator());
        security.setLoginService(loginService);
        security.setRealmName("MyRealm");
        security.setHandler(context);
        topLevelHandler = security;
    } else {
        topLevelHandler = context;
    }
    final Webapp[] webapps = config.webapps();
    if (webapps != null) {
        for (final Webapp webapp : webapps) {
            final WebAppContext wac = new WebAppContext();
            String path = null;
            if (!"".equals(webapp.pathSystemProperty()) && System.getProperty(webapp.pathSystemProperty()) != null) {
                path = System.getProperty(webapp.pathSystemProperty());
            } else {
                path = webapp.path();
            }
            if (path == null || "".equals(path)) {
                throw new IllegalArgumentException("path or pathSystemProperty of @Webapp points to a null or blank value");
            }
            wac.setWar(path);
            wac.setContextPath(webapp.context());
            handlers.addHandler(wac);
        }
    }
    final ResourceHandler rh = new ResourceHandler();
    rh.setWelcomeFiles(new String[] { "index.html" });
    rh.setResourceBase(config.resource());
    handlers.addHandler(rh);
    // fall through to default
    handlers.addHandler(new DefaultHandler());
    context.setHandler(handlers);
    m_server.setHandler(topLevelHandler);
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) Constraint(org.eclipse.jetty.util.security.Constraint) Handler(org.eclipse.jetty.server.Handler) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HashLoginService(org.eclipse.jetty.security.HashLoginService) BasicAuthenticator(org.eclipse.jetty.security.authentication.BasicAuthenticator) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) HashSet(java.util.HashSet) Webapp(org.opennms.core.test.http.annotations.Webapp)

Example 60 with WebAppContext

use of org.eclipse.jetty.webapp.WebAppContext in project Synthese_2BIN by TheYoungSensei.

the class MyServer method main.

public static void main(String[] args) throws Exception {
    // lie le server � un port
    Server server = new Server(8000);
    // instancie un WebAppContext pour configurer le server
    WebAppContext context = new WebAppContext();
    // O� se trouvent les fichiers (ils seront servis par un DefaultServlet)
    context.setResourceBase("www");
    // MaServlet r�pondra aux requ�tes commen�ant par /chemin/
    context.addServlet(new ServletHolder(new MachineServlet()), "/Machine");
    // Le DefaultServlet sert des fichiers (html, js, css, images, ...). Il est en g�n�ral ajout� en dernier pour que les autres servlets soient prioritaires sur l�interpr�tation des URLs.
    context.addServlet(new ServletHolder(new DefaultServlet()), "/");
    // ce server utilise ce context
    server.setHandler(context);
    // allons-y
    server.start();
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet)

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