}
shPojoMap.setInitParameter(JSONConfiguration.FEATURE_POJO_MAPPING, "true");
// set up Jetty and run the embedded server
Server server = new Server();
Connector connector = new SelectChannelConnector();
if(conf.getBoolean(REST_SSL_ENABLED, false)) {
SslSelectChannelConnector sslConnector = new SslSelectChannelConnector();
String keystore = conf.get(REST_SSL_KEYSTORE_STORE);
String password = conf.get(REST_SSL_KEYSTORE_PASSWORD);
String keyPassword = conf.get(REST_SSL_KEYSTORE_KEYPASSWORD, password);
sslConnector.setKeystore(keystore);
sslConnector.setPassword(password);
sslConnector.setKeyPassword(keyPassword);
connector = sslConnector;
}
connector.setPort(servlet.getConfiguration().getInt("hbase.rest.port", 8080));
connector.setHost(servlet.getConfiguration().get("hbase.rest.host", "0.0.0.0"));
server.addConnector(connector);
// Set the default max thread number to 100 to limit
// the number of concurrent requests so that REST server doesn't OOM easily.
// Jetty set the default max thread number to 250, if we don't set it.
//
// Our default min thread number 2 is the same as that used by Jetty.
int maxThreads = servlet.getConfiguration().getInt("hbase.rest.threads.max", 100);
int minThreads = servlet.getConfiguration().getInt("hbase.rest.threads.min", 2);
QueuedThreadPool threadPool = new QueuedThreadPool(maxThreads);
threadPool.setMinThreads(minThreads);
server.setThreadPool(threadPool);
server.setSendServerVersion(false);
server.setSendDateHeader(false);
server.setStopAtShutdown(true);
// set up context
Context context = new Context(server, "/", Context.SESSIONS);
context.addServlet(shPojoMap, "/status/cluster");
context.addServlet(sh, "/*");
if (authFilter != null) {
context.addFilter(authFilter, "/*", 1);
}
// Load filters from configuration.
String[] filterClasses = servlet.getConfiguration().getStrings(FILTER_CLASSES,
ArrayUtils.EMPTY_STRING_ARRAY);
for (String filter : filterClasses) {
filter = filter.trim();
context.addFilter(Class.forName(filter), "/*", 0);
}
// Put up info server.
int port = conf.getInt("hbase.rest.info.port", 8085);
if (port >= 0) {
conf.setLong("startcode", System.currentTimeMillis());
String a = conf.get("hbase.rest.info.bindAddress", "0.0.0.0");
InfoServer infoServer = new InfoServer("rest", a, port, false, conf);
infoServer.setAttribute("hbase.conf", conf);
infoServer.start();
}
// start server
server.start();
server.join();
}