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();
}
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();
}
}
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);
}
}
Aggregations