Java 类org.eclipse.jetty.server.handler.SecuredRedirectHandler 实例源码

项目:service-base    文件:JServer.java   
/**
 *
 * @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;
}
项目:scheduling    文件:JettyStarter.java   
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<>();
}
项目:kumuluzee    文件:JettyServletServer.java   
@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);
    }
}