/** * * @param webapp * @return */ private static ContextHandlerCollection setupHttpsRedirect(WebAppContext webapp) { /*HANDLERS BUSINESS*/ SecuredRedirectHandler securedRedirect = new SecuredRedirectHandler(); // Establish all handlers that have a context ContextHandlerCollection contextHandlers = new ContextHandlerCollection(); webapp.setVirtualHosts(new String[]{"@secured"}); // handles requests that come through the sslConnector connector ... ContextHandler redirectHandler = new ContextHandler(); redirectHandler.setContextPath("/"); redirectHandler.setHandler(securedRedirect); redirectHandler.setVirtualHosts(new String[]{"@unsecured"}); // handls requests that come through the Connector (unsecured) ... contextHandlers.setHandlers(new Handler[]{redirectHandler, webapp}); return contextHandlers; }
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<>(); }
@Override public void initWebContext() { if (server == null) throw new IllegalStateException("Jetty has to be initialized before adding a web context"); if (server.isStarted() || server.isStarting()) throw new IllegalStateException("Jetty cannot be started before adding a web context"); appContext = new WebAppContext(); if (ResourceUtils.isRunningInJar()) { appContext.setAttribute(JettyAttributes.jarPattern, ClasspathAttributes.jar); try { appContext.setClassLoader(getClass().getClassLoader()); } catch (Exception e) { throw new IllegalStateException("Unable to set custom classloader for Jetty"); } } else { appContext.setAttribute(JettyAttributes.jarPattern, ClasspathAttributes.exploded); } appContext.setParentLoaderPriority(true); appContext.setResourceBase(ResourceUtils.getProjectWebResources()); appContext.setContextPath(serverConfig.getContextPath()); if (!Boolean.TRUE.equals(serverConfig.getDirBrowsing())) { appContext.setInitParameter(JettyAttributes.dirBrowsing, "false"); } log.info("Starting KumuluzEE with context root '" + serverConfig.getContextPath() + "'"); // Set the secured redirect handler in case the force https option is selected if (serverConfig.getForceHttps()) { HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[] {new SecuredRedirectHandler(), appContext}); server.setHandler(handlers); } else { server.setHandler(appContext); } }