Search in sources :

Example 41 with SessionHandler

use of org.eclipse.jetty.server.session.SessionHandler in project XRTB by benmfaul.

the class AddShutdownHook method startSeparateAdminServer.

/**
	 * Start a different handler for control and reporting functions
	 * 
	 * @throws Exception
	 *             if SSL is specified but is not configured
	 */
void startSeparateAdminServer() throws Exception {
    SSL ssl = Configuration.getInstance().ssl;
    QueuedThreadPool threadPool = new QueuedThreadPool(threads, 50);
    Server server = new Server(threadPool);
    ServerConnector connector;
    if (Configuration.getInstance().adminPort == 0)
        return;
    Controller.getInstance().sendLog(1, "initialization", ("Admin functions are available on port: " + Configuration.getInstance().adminPort));
    if (!Configuration.getInstance().adminSSL) {
        // adminPort
        connector = new ServerConnector(server);
        connector.setPort(Configuration.getInstance().adminPort);
        connector.setIdleTimeout(60000);
        server.setConnectors(new Connector[] { connector });
    } else {
        if (config.getInstance().ssl == null) {
            throw new Exception("Admin port set to SSL but no SSL credentials are configured.");
        }
        Controller.getInstance().sendLog(1, "initialization", "Admin functions are available by SSL only");
        HttpConfiguration https = new HttpConfiguration();
        https.addCustomizer(new SecureRequestCustomizer());
        SslContextFactory sslContextFactory = new SslContextFactory();
        sslContextFactory.setKeyStorePath(ssl.setKeyStorePath);
        sslContextFactory.setKeyStorePassword(ssl.setKeyStorePassword);
        sslContextFactory.setKeyManagerPassword(ssl.setKeyManagerPassword);
        ServerConnector sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https));
        sslConnector.setPort(Configuration.getInstance().adminPort);
        server.setConnectors(new Connector[] { sslConnector });
    }
    adminHandler = new AdminHandler();
    // org.eclipse.jetty.server.session.SessionHandler
    SessionHandler sh = new SessionHandler();
    sh.setHandler(adminHandler);
    // set session handle
    server.setHandler(sh);
    server.start();
    server.join();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) SSL(com.xrtb.common.SSL) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 42 with SessionHandler

use of org.eclipse.jetty.server.session.SessionHandler in project XRTB by benmfaul.

the class Handler method run.

/**
	 * Starts the JETTY server
	 */
public void run() {
    Server server = new Server(port);
    Handler handler = new Handler();
    try {
        // org.eclipse.jetty.server.session.SessionHandler
        SessionHandler sh = new SessionHandler();
        sh.addEventListener(new CustomListener());
        sh.setHandler(handler);
        server.setHandler(sh);
        server.start();
        server.join();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) Server(org.eclipse.jetty.server.Server) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) CustomListener(com.xrtb.bidder.CustomListener) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 43 with SessionHandler

use of org.eclipse.jetty.server.session.SessionHandler in project dropbox-sdk-java by dropbox.

the class Main method main.

// -------------------------------------------------------------------------------------------
// main()
// -------------------------------------------------------------------------------------------
// Parse command-line arguments and start server.
public static void main(String[] args) throws IOException {
    if (args.length != 3) {
        System.out.println("");
        System.out.println("Usage: COMMAND <http-listen-port> <app-info-file> <database-file>");
        System.out.println("");
        System.out.println(" <http-listen-port>: The port to run the HTTP server on.  For example,");
        System.out.println("    \"8080\").");
        System.out.println("");
        System.out.println(" <app-info-file>: A JSON file containing your Dropbox API app key, secret");
        System.out.println("    and access type.  For example, \"my-app.app\" with:");
        System.out.println("");
        System.out.println("    {");
        System.out.println("      \"key\": \"Your Dropbox app key...\",");
        System.out.println("      \"secret\": \"Your Dropbox app secret...\"");
        System.out.println("    }");
        System.out.println("");
        System.out.println(" <database-file>: Where you want this program to store its database.  For");
        System.out.println("    example, \"web-file-browser.db\".");
        System.out.println("");
        System.exit(1);
        return;
    }
    String argPort = args[0];
    String argAppInfo = args[1];
    String argDatabase = args[2];
    // Figure out what port to listen on.
    int port;
    try {
        port = Integer.parseInt(argPort);
        if (port < 1 || port > 65535) {
            System.err.println("Expecting <http-listen-port> to be a number from 1 to 65535.  Got: " + port + ".");
            System.exit(1);
            return;
        }
    } catch (NumberFormatException ex) {
        System.err.println("Expecting <http-listen-port> to be a number from 1 to 65535.  Got: " + jq(argPort) + ".");
        System.exit(1);
        return;
    }
    // Read app info file (contains app key and app secret)
    DbxAppInfo dbxAppInfo;
    try {
        dbxAppInfo = DbxAppInfo.Reader.readFromFile(argAppInfo);
    } catch (JsonReader.FileLoadException ex) {
        System.err.println("Error loading <app-info-file>: " + ex.getMessage());
        System.exit(1);
        return;
    }
    System.out.println("Loaded app info from " + jq(argAppInfo));
    File dbFile = new File(argDatabase);
    // Run server
    try {
        Main main = new Main(new PrintWriter(System.out, true), dbxAppInfo, dbFile);
        Server server = new Server(port);
        SessionHandler sessionHandler = new SessionHandler();
        sessionHandler.setServer(server);
        sessionHandler.setHandler(main);
        server.setHandler(sessionHandler);
        server.start();
        System.out.println("Server running: http://localhost:" + port + "/");
        server.join();
    } catch (Exception ex) {
        System.err.println("Error running server: " + ex.getMessage());
        System.exit(1);
    }
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) Server(org.eclipse.jetty.server.Server) DbxAppInfo(com.dropbox.core.DbxAppInfo) JsonReader(com.dropbox.core.json.JsonReader) File(java.io.File) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Aggregations

SessionHandler (org.eclipse.jetty.server.session.SessionHandler)43 Server (org.eclipse.jetty.server.Server)13 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)10 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)10 Test (org.junit.Test)10 IOException (java.io.IOException)8 ServletException (javax.servlet.ServletException)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 HashSessionManager (org.eclipse.jetty.server.session.HashSessionManager)5 File (java.io.File)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpSession (javax.servlet.http.HttpSession)4 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)4 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)4 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)4 BeforeClass (org.junit.BeforeClass)4 ConstraintSecurityHandler (org.eclipse.jetty.security.ConstraintSecurityHandler)3 LocalConnector (org.eclipse.jetty.server.LocalConnector)3 ServerConnector (org.eclipse.jetty.server.ServerConnector)3 SessionManager (org.eclipse.jetty.server.SessionManager)3