use of com.xrtb.common.SSL in project XRTB by benmfaul.
the class AddShutdownHook method run.
/**
* Establishes the HTTP Handler, creates the Jetty server and attaches the
* handler and then joins the server. This method does not return, but it is
* interruptable by calling the halt() method.
*/
@Override
public void run() {
SSL ssl = Configuration.getInstance().ssl;
if (Configuration.getInstance().port == 0 && ssl == null) {
try {
logger.error("Neither HTTP or HTTPS configured, error, stop");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return;
}
QueuedThreadPool threadPool = new QueuedThreadPool(threads, 50);
server = new Server(threadPool);
ServerConnector connector = null;
if (Configuration.getInstance().port != 0) {
connector = new ServerConnector(server);
connector.setPort(Configuration.getInstance().port);
connector.setIdleTimeout(60000);
}
if (config.getInstance().ssl != null) {
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().sslPort);
if (connector != null)
server.setConnectors(new Connector[] { connector, sslConnector });
else
server.setConnectors(new Connector[] { sslConnector });
try {
logger.info("SSL configured on port {}", Configuration.getInstance().sslPort);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else
server.setConnectors(new Connector[] { connector });
Handler handler = new Handler();
node = null;
try {
new WebMQ(7379, null);
BidRequest.compile();
// org.eclipse.jetty.server.session.SessionHandler
SessionHandler sh = new SessionHandler();
sh.setHandler(handler);
// set session handle
server.setHandler(sh);
startPeridocLogger();
/**
* Override the start state if the deadmanswitch object is not null
* and the key doesn't exist
*/
if (Configuration.getInstance().deadmanSwitch != null) {
if (Configuration.getInstance().deadmanSwitch.canRun() == false) {
RTBServer.stopped = true;
}
}
server.start();
Thread.sleep(500);
ready = true;
// qps timer
deltaTime = System.currentTimeMillis();
if (Controller.getInstance().responseQueue != null)
Controller.getInstance().responseQueue.add(getStatus());
logger.info("********************* System start on port: {}/{}", Performance.getInternalAddress(), Configuration.getInstance().port);
startSeparateAdminServer();
startedLatch.countDown();
server.join();
} catch (Exception error) {
if (error.toString().contains("Interrupt"))
try {
logger.error("HALT: : {}", error.toString());
if (node != null)
node.halt();
} catch (Exception e) {
e.printStackTrace();
}
else
error.printStackTrace();
} finally {
if (node != null)
node.stop();
}
}
use of com.xrtb.common.SSL 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;
logger.info("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.");
}
logger.info("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();
}
Aggregations