* @param config
*/
static void start(ProxyConfig config) throws Exception {
Engine.setRestletLogLevel(Level.INFO);
Component c = new Component();
// turn off Restlet url access logging
c.getLogService().setEnabled(config.getAccessLog());
// specify the Jetty helpers
String httpHelper = "org.restlet.ext.jetty.HttpServerHelper";
String httpsHelper = "org.restlet.ext.jetty.HttpsServerHelper";
// create a Restlet server
if (config.getBindAddresses().size() == 0) {
// start server on all available addresses
if (config.getHttpPort() > 0) {
Server server = new Server(null, Arrays.asList(Protocol.HTTP), null, config.getHttpPort(), c, httpHelper);
c.getServers().add(server);
}
if (config.getHttpsPort() > 0) {
Server server = new Server(null, Arrays.asList(Protocol.HTTPS), null, config.getHttpsPort(), c, httpsHelper);
c.getServers().add(server);
configureHttps(server, config);
}
} else {
// start server on specific address(es)
for (String address : config.getBindAddresses()) {
if (config.getHttpPort() > 0) {
Server server = new Server(null, Arrays.asList(Protocol.HTTP), address, config.getHttpPort(), c, httpHelper);
c.getServers().add(server);
}
if (config.getHttpsPort() > 0) {
Server server = new Server(null, Arrays.asList(Protocol.HTTPS), address, config.getHttpsPort(), c, httpsHelper);
c.getServers().add(server);
configureHttps(server, config);
}
}
}
// add client classpath protocol to enable resource loading from the jar
c.getClients().add(Protocol.CLAP);
// add client file protocol to enable serving artifacts from filesystem
c.getClients().add(Protocol.FILE);
// override the default error pages
c.setStatusService(new ErrorStatusService(c.getContext()));
// get the default virtual host
VirtualHost host = c.getDefaultHost();
MoxieProxy app = new MoxieProxy(config);
// Guard Moxie Proxy with BASIC authentication.
Authenticator guard = new Authenticator(app);
host.attachDefault(guard);
guard.setNext(app);
// start the shutdown monitor
if (config.getShutdownPort() > 0) {
Thread shutdownMonitor = new ShutdownMonitorThread(c, app, config);
shutdownMonitor.start();
}
// start the Restlet http/https server
c.start();
}