Search in sources :

Example 36 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList in project alluxio by Alluxio.

the class WebServer method addHandler.

/**
   * Adds a handler.
   *
   * @param handler the handler to add
   */
public void addHandler(AbstractHandler handler) {
    HandlerList handlers = new HandlerList();
    handlers.addHandler(handler);
    for (Handler h : mServer.getHandlers()) {
        handlers.addHandler(h);
    }
    mServer.setHandler(handlers);
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) Handler(org.eclipse.jetty.server.Handler) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler)

Example 37 with HandlerList

use of org.eclipse.jetty.server.handler.HandlerList in project leopard by tanhaichao.

the class WebappDaoImpl method getHandlerList.

protected Handler getHandlerList(List<String> hostList) {
    // jettyServer.getWebappService().addHandler(new HostResourceHandler("ftrade.leopard.io", "/data/src/ftrade_html/"));
    if (hostList.contains("fshop.leopard.io")) {
        if (false) {
            return new HostResourceHandler("fshop.leopard.io", "/data/src/fshop_html/");
        }
        HandlerList handlerList = new HandlerList();
        handlerList.addHandler(new HostResourceHandler("fshop.leopard.io", "/data/src/fshop_html/"));
        handlerList.addHandler(new HostResourceHandler("ftrade.leopard.io", "/data/src/ftrade_html/"));
        try {
            handlerList.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return handlerList;
    }
    return null;
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) HostResourceHandler(io.leopard.jetty.handler.HostResourceHandler) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 38 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);
    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 handlerList = new HandlerList();
        if (httpsEnabled && redirectHttpToHttps) {
            ContextHandler redirectHandler = new ContextHandler();
            redirectHandler.setContextPath("/");
            redirectHandler.setHandler(new SecuredRedirectHandler());
            redirectHandler.setVirtualHosts(httpVirtualHost);
            handlerList.addHandler(redirectHandler);
        }
        addWarsToHandlerList(handlerList, defaultVirtualHost);
        server.setHandler(handlerList);
        String schedulerHost = ProActiveInet.getInstance().getHostname();
        return startServer(server, schedulerHost, restPort, httpProtocol);
    }
    return new ArrayList<>();
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Server(org.eclipse.jetty.server.Server) SecuredRedirectHandler(org.eclipse.jetty.server.handler.SecuredRedirectHandler) ArrayList(java.util.ArrayList)

Example 39 with HandlerList

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

the class JettyStarter method printDeployedApplications.

private List<String> printDeployedApplications(Server server, String schedulerHost, int restPort, String httpProtocol) {
    HandlerList handlerList = (HandlerList) server.getHandler();
    ArrayList<String> applicationsUrls = new ArrayList<>();
    if (handlerList.getHandlers() != null) {
        for (Handler handler : handlerList.getHandlers()) {
            if (!(handler instanceof WebAppContext)) {
                continue;
            }
            WebAppContext webAppContext = (WebAppContext) handler;
            Throwable startException = webAppContext.getUnavailableException();
            if (startException == null) {
                if (!"/".equals(webAppContext.getContextPath())) {
                    String applicationUrl = getApplicationUrl(httpProtocol, schedulerHost, restPort, webAppContext);
                    applicationsUrls.add(applicationUrl);
                    logger.info("The web application " + webAppContext.getContextPath() + " created on " + applicationUrl);
                }
            } else {
                logger.warn("Failed to start context " + webAppContext.getContextPath(), startException);
            }
        }
        logger.info("*** Get started at " + httpProtocol + "://" + schedulerHost + ":" + restPort + " ***");
    }
    return applicationsUrls;
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ArrayList(java.util.ArrayList) Handler(org.eclipse.jetty.server.Handler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) SecuredRedirectHandler(org.eclipse.jetty.server.handler.SecuredRedirectHandler)

Example 40 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 MalformedURLException, IOException {
    Server server = new Server();
    HttpConfiguration https_config = new HttpConfiguration();
    https_config.setSecureScheme("https");
    int port = 0;
    try (ServerSocket socket = new ServerSocket(0)) {
        port = socket.getLocalPort();
    }
    https_config.setSecurePort(port);
    https_config.setOutputBufferSize(32768);
    String keystorePath = DEFAULT_SERVER_KEY_STORE;
    SslContextFactory sslContextFactory = new SslContextFactory();
    File keystoreFile = new File(keystorePath);
    if (!keystoreFile.exists()) {
        throw new FileNotFoundException();
    }
    String trustStorePath = DEFAULT_CA_TRUST_STORE;
    File trustStoreFile = new File(trustStorePath);
    if (!trustStoreFile.exists()) {
        throw new FileNotFoundException();
    }
    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) 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)

Aggregations

HandlerList (org.eclipse.jetty.server.handler.HandlerList)40 Server (org.eclipse.jetty.server.Server)22 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)18 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)13 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)11 Handler (org.eclipse.jetty.server.Handler)9 ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)9 IOException (java.io.IOException)7 ServerConnector (org.eclipse.jetty.server.ServerConnector)7 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 File (java.io.File)5 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)5 ServletException (javax.servlet.ServletException)4 DefaultServlet (org.eclipse.jetty.servlet.DefaultServlet)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 URI (java.net.URI)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)3