Search in sources :

Example 51 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList in project scheduling by ow2-proactive.

the class JettyStarter method deployWebApplications.

public List<String> deployWebApplications(String rmUrl, String schedulerUrl) {
    initializeRestProperties();
    setSystemPropertyIfNotDefined("rm.url", rmUrl);
    setSystemPropertyIfNotDefined("scheduler.url", schedulerUrl);
    System.setProperty(CentralPAPropertyRepository.JAVAX_XML_TRANSFORM_TRANSFORMERFACTORY.getName(), DEFAULT_XML_TRANSFORMER);
    if (WebProperties.WEB_DEPLOY.getValueAsBoolean()) {
        logger.info("Starting the web applications...");
        int httpPort = getJettyHttpPort();
        int httpsPort = 443;
        if (WebProperties.WEB_HTTPS_PORT.isSet()) {
            httpsPort = WebProperties.WEB_HTTPS_PORT.getValueAsInt();
        }
        boolean httpsEnabled = WebProperties.WEB_HTTPS.getValueAsBoolean();
        boolean redirectHttpToHttps = WebProperties.WEB_REDIRECT_HTTP_TO_HTTPS.getValueAsBoolean();
        int restPort = httpPort;
        String httpProtocol;
        String[] defaultVirtualHost;
        String[] httpVirtualHost = new String[] { "@" + HTTP_CONNECTOR_NAME };
        if (httpsEnabled) {
            httpProtocol = "https";
            defaultVirtualHost = new String[] { "@" + HTTPS_CONNECTOR_NAME };
            restPort = httpsPort;
        } else {
            defaultVirtualHost = httpVirtualHost;
            httpProtocol = "http";
        }
        Server server = createHttpServer(httpPort, httpsPort, httpsEnabled, redirectHttpToHttps);
        server.setStopAtShutdown(true);
        HandlerList topLevelHandlerList = new HandlerList();
        if (httpsEnabled && redirectHttpToHttps) {
            ContextHandler redirectHandler = new ContextHandler();
            redirectHandler.setContextPath("/");
            redirectHandler.setHandler(new SecuredRedirectHandler());
            redirectHandler.setVirtualHosts(httpVirtualHost);
            topLevelHandlerList.addHandler(redirectHandler);
        }
        topLevelHandlerList.addHandler(createSecurityHeadersHandler());
        if (WebProperties.JETTY_LOG_FILE.isSet()) {
            String pathToJettyLogFile = FileStorageSupportFactory.relativeToHomeIfNotAbsolute(WebProperties.JETTY_LOG_FILE.getValueAsString());
            File jettyLogFile = new File(pathToJettyLogFile);
            if (!jettyLogFile.getParentFile().exists() && !jettyLogFile.getParentFile().mkdirs()) {
                logger.error("Could not create jetty log file in: " + WebProperties.JETTY_LOG_FILE.getValueAsString());
            } else {
                NCSARequestLog requestLog = new NCSARequestLog(pathToJettyLogFile);
                requestLog.setAppend(true);
                requestLog.setExtended(false);
                requestLog.setLogTimeZone("GMT");
                requestLog.setLogLatency(true);
                requestLog.setRetainDays(WebProperties.JETTY_LOG_RETAIN_DAYS.getValueAsInt());
                RequestLogHandler requestLogHandler = new RequestLogHandler();
                requestLogHandler.setRequestLog(requestLog);
                topLevelHandlerList.addHandler(requestLogHandler);
            }
        }
        RewriteHandler rewriteHandler = null;
        HandlerList contextHandlerList = null;
        if (WebProperties.WEB_PCA_PROXY_REWRITE_ENABLED.getValueAsBoolean()) {
            rewriteHandler = new RewriteHandler();
            PCAProxyRule proxyRule = new PCAProxyRule();
            rewriteHandler.addRule(proxyRule);
            rewriteHandler.setRewriteRequestURI(true);
            rewriteHandler.setRewritePathInfo(false);
            rewriteHandler.setOriginalPathAttribute(PCAProxyRule.originalPathAttribute);
            rewriteHandler.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);
            contextHandlerList = new HandlerList();
        } else {
            contextHandlerList = topLevelHandlerList;
        }
        addWarsToHandlerList(contextHandlerList, defaultVirtualHost);
        if (WebProperties.WEB_PCA_PROXY_REWRITE_ENABLED.getValueAsBoolean()) {
            rewriteHandler.setHandler(contextHandlerList);
            topLevelHandlerList.addHandler(rewriteHandler);
        }
        server.setHandler(topLevelHandlerList);
        if (logger.isDebugEnabled()) {
            server.setDumpAfterStart(true);
        }
        String schedulerHost = ProActiveInet.getInstance().getHostname();
        return startServer(server, schedulerHost, restPort, httpProtocol);
    }
    return new ArrayList<>();
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) Server(org.eclipse.jetty.server.Server) SecuredRedirectHandler(org.eclipse.jetty.server.handler.SecuredRedirectHandler) ArrayList(java.util.ArrayList) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) NCSARequestLog(org.eclipse.jetty.server.NCSARequestLog) File(java.io.File) RewriteHandler(org.eclipse.jetty.rewrite.handler.RewriteHandler)

Example 52 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList in project athenz by yahoo.

the class SSLUtilsTest method createHttpsJettyServer.

private static JettyServer createHttpsJettyServer(boolean clientAuth) throws IOException {
    Server server = new Server();
    HttpConfiguration https_config = new HttpConfiguration();
    https_config.setSecureScheme("https");
    int port;
    try (ServerSocket socket = new ServerSocket(0)) {
        port = socket.getLocalPort();
    }
    https_config.setSecurePort(port);
    https_config.setOutputBufferSize(32768);
    SslContextFactory.Server sslContextFactory = new SslContextFactory.Server();
    File keystoreFile = new File(DEFAULT_SERVER_KEY_STORE);
    if (!keystoreFile.exists()) {
        throw new FileNotFoundException();
    }
    String trustStorePath = DEFAULT_CA_TRUST_STORE;
    File trustStoreFile = new File(trustStorePath);
    if (!trustStoreFile.exists()) {
        throw new FileNotFoundException();
    }
    sslContextFactory.setEndpointIdentificationAlgorithm(null);
    sslContextFactory.setTrustStorePath(trustStorePath);
    sslContextFactory.setTrustStoreType(DEFAULT_SSL_STORE_TYPE);
    sslContextFactory.setTrustStorePassword(DEFAULT_CERT_PWD);
    sslContextFactory.setKeyStorePath(keystoreFile.getAbsolutePath());
    sslContextFactory.setKeyStoreType(DEFAULT_SSL_STORE_TYPE);
    sslContextFactory.setKeyStorePassword(DEFAULT_CERT_PWD);
    sslContextFactory.setProtocol(DEFAULT_SSL_PROTOCOL);
    sslContextFactory.setNeedClientAuth(clientAuth);
    ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(https_config));
    https.setPort(port);
    https.setIdleTimeout(500000);
    server.setConnectors(new Connector[] { https });
    HandlerList handlers = new HandlerList();
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setBaseResource(Resource.newResource("."));
    handlers.setHandlers(new Handler[] { resourceHandler, new DefaultHandler() });
    server.setHandler(handlers);
    return new JettyServer(server, port);
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) FileNotFoundException(java.io.FileNotFoundException) ServerSocket(java.net.ServerSocket) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) File(java.io.File)

Example 53 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList in project NMEAParser by tvesalainen.

the class CommandLine method start.

private void start() throws IOException, InterruptedException, JAXBException, Exception {
    config("starting NMEA Server");
    Path configfile = getArgument("configuration file");
    Config config = new Config(configfile);
    String address = config.getNmeaMulticastAddress();
    int nmeaPort = config.getNmeaMulticastPort();
    int httpPort = config.getHttpPort();
    config("NMEA Multicast Address=%s", address);
    config("NMEA Multicast Port=%s", nmeaPort);
    config("HTTP Port=%s", httpPort);
    CachedScheduledThreadPool executor = new CachedScheduledThreadPool(64);
    config("ThreadPool started %s", executor);
    NMEAService nmeaService = new NMEAService(address, nmeaPort, executor);
    PropertyServer propertyServer = new PropertyServer(Clock.systemDefaultZone(), config, executor);
    nmeaService.addNMEAObserver(propertyServer);
    nmeaService.start();
    config("NMEA Service started");
    JavaUtilLog log = new JavaUtilLog();
    // make jetty use java.util.logger
    Log.setLog(log);
    Server server = new Server(httpPort);
    HandlerList handlers = new HandlerList();
    ServletContextHandler context = new ServletContextHandler();
    context.addServlet(ResourceServlet.class, "/");
    ServletHolder holder = new ServletHolder(SseServlet.class);
    holder.setAsyncSupported(true);
    context.addServlet(holder, "/sse");
    context.addServlet(ResourceServlet.class, "*.js");
    context.addServlet(ResourceServlet.class, "*.css");
    context.addServlet(ResourceServlet.class, "*.gif");
    context.addServlet(ResourceServlet.class, "*.png");
    context.addServlet(ResourceServlet.class, "*.ico");
    context.addServlet(PrefsServlet.class, "/prefs");
    context.addServlet(I18nServlet.class, "/i18n");
    SessionHandler sessionHandler = new SessionHandler();
    context.setSessionHandler(sessionHandler);
    handlers.addHandler(context);
    server.setHandler(handlers);
    server.setSessionIdManager(new DefaultSessionIdManager(server));
    ServletContext servletContext = context.getServletContext().getContext("/sse");
    servletContext.setAttribute(PropertyServer.class.getName(), propertyServer);
    server.start();
    executor.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}
Also used : Path(java.nio.file.Path) HandlerList(org.eclipse.jetty.server.handler.HandlerList) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) DefaultSessionIdManager(org.eclipse.jetty.server.session.DefaultSessionIdManager) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) CachedScheduledThreadPool(org.vesalainen.util.concurrent.CachedScheduledThreadPool) JavaUtilLog(org.eclipse.jetty.util.log.JavaUtilLog) ServletContext(javax.servlet.ServletContext) NMEAService(org.vesalainen.parsers.nmea.NMEAService) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 54 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList in project cia by Hack23.

the class CitizenIntelligenceAgencyServer method init.

/**
 * Inits the.
 *
 * @throws Exception
 *             the exception
 */
public final void init() throws Exception {
    initialised = true;
    server = new Server();
    Security.addProvider(new BouncyCastleProvider());
    // Setup JMX
    final MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
    server.addBean(mbContainer);
    // Enable parsing of jndi-related parts of web.xml and jetty-env.xml
    final org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
    classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
    classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");
    final HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    http_config.setSecurePort(28443);
    final HttpConfiguration https_config = new HttpConfiguration(http_config);
    https_config.addCustomizer(new SecureRequestCustomizer());
    final SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStoreType("JKS");
    sslContextFactory.setKeyStorePath("target/keystore.jks");
    sslContextFactory.setTrustStorePath("target/keystore.jks");
    sslContextFactory.setKeyStorePassword("changeit");
    sslContextFactory.setTrustStorePassword("changeit");
    sslContextFactory.setKeyManagerPassword("changeit");
    sslContextFactory.setCertAlias("jetty");
    sslContextFactory.setIncludeCipherSuites("TLS_DHE_RSA.*", "TLS_ECDHE.*");
    sslContextFactory.setExcludeProtocols("SSL", "SSLv2", "SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.1");
    sslContextFactory.setIncludeProtocols("TLSv1.2");
    final ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https_config), new HTTP2CServerConnectionFactory(https_config));
    sslConnector.setPort(PORT);
    server.setConnectors(new ServerConnector[] { sslConnector });
    final WebAppContext handler = new WebAppContext("src/main/webapp", "/");
    handler.setExtraClasspath("target/classes");
    handler.setParentLoaderPriority(true);
    handler.setConfigurationDiscovered(true);
    handler.setClassLoader(Thread.currentThread().getContextClassLoader());
    final HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { handler, new DefaultHandler() });
    server.setHandler(handlers);
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) 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) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 55 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList in project selenium_java by sergueik.

the class RunScriptTest method beforeSuiteMethod.

@BeforeSuite
public void beforeSuiteMethod() throws Exception {
    ((StdErrLog) Log.getRootLogger()).setLevel(StdErrLog.LEVEL_OFF);
    webServer = new Server(new QueuedThreadPool(5));
    ServerConnector connector = new ServerConnector(webServer, new HttpConnectionFactory());
    connector.setPort(8080);
    webServer.addConnector(connector);
    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setWelcomeFiles(new String[] { "index.html" });
    resource_handler.setResourceBase("src/test/webapp");
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
    webServer.setHandler(handlers);
    webServer.start();
    driver = new FirefoxDriver();
    driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
    wait = new WebDriverWait(driver, flexibleWait);
    wait.pollingEvery(pollingInterval, TimeUnit.MILLISECONDS);
    hashesFinderScript = getScriptContent("hashesFinder.js");
    resultFinderScript = getScriptContent("resultFinder.js");
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) HandlerList(org.eclipse.jetty.server.handler.HandlerList) StdErrLog(org.eclipse.jetty.util.log.StdErrLog) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) BeforeSuite(org.testng.annotations.BeforeSuite)

Aggregations

HandlerList (org.eclipse.jetty.server.handler.HandlerList)71 Server (org.eclipse.jetty.server.Server)44 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)32 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)26 ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)21 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)20 ServerConnector (org.eclipse.jetty.server.ServerConnector)16 IOException (java.io.IOException)13 Handler (org.eclipse.jetty.server.Handler)12 File (java.io.File)11 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)10 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)10 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)8 DefaultServlet (org.eclipse.jetty.servlet.DefaultServlet)8 ArrayList (java.util.ArrayList)7 ServletException (javax.servlet.ServletException)6 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)6 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)6 Test (org.junit.Test)6 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)5