@Override protected void postConfigure(WebAppContext context) { context.addFilter(GzipFilter.class, "/*", Handler.ALL); }
public Server buildHttpRestServer() throws Exception { int port = _senseiConf.getInt(SERVER_BROKER_PORT); String webappPath = _senseiConf.getString(SERVER_BROKER_WEBAPP_PATH, "sensei-core/src/main/webapp"); Server server = new Server(); QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setName("Sensei Broker(jetty) threads"); threadPool.setMinThreads(_senseiConf.getInt(SERVER_BROKER_MINTHREAD, 20)); threadPool.setMaxThreads(_senseiConf.getInt(SERVER_BROKER_MAXTHREAD, 50)); threadPool.setMaxIdleTimeMs(_senseiConf.getInt(SERVER_BROKER_MAXWAIT, 2000)); // threadPool.start(); server.setThreadPool(threadPool); logger.info("request threadpool started."); SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(port); server.addConnector(connector); DefaultSenseiJSONServlet senseiServlet = new DefaultSenseiJSONServlet(); ServletHolder senseiServletHolder = new ServletHolder(senseiServlet); SenseiHttpInvokerServiceServlet springServlet = new SenseiHttpInvokerServiceServlet(); ServletHolder springServletHolder = new ServletHolder(springServlet); AgentServlet jmxServlet = new AgentServlet(); ServletHolder jmxServletHolder = new ServletHolder(jmxServlet); WebAppContext senseiApp = new WebAppContext(); senseiApp.addFilter(GzipFilter.class, "/" + SENSEI_CONTEXT_PATH + "/*", 1); // HashMap<String, String> initParam = new HashMap<String, String>(); // if (_senseiConfFile != null) { // logger.info("Broker Configuration file: "+_senseiConfFile.getAbsolutePath()); // initParam.put("config.file", _senseiConfFile.getAbsolutePath()); // } // senseiApp.setInitParams(initParam); senseiApp.setAttribute("sensei.search.configuration", _senseiConf); senseiApp.setAttribute( SenseiConfigServletContextListener.SENSEI_CONF_PLUGIN_REGISTRY, pluginRegistry); senseiApp.setAttribute( "sensei.search.version.comparator", _gateway != null ? _gateway.getVersionComparator() : ZoieConfig.DEFAULT_VERSION_COMPARATOR); PartitionedLoadBalancerFactory<String> routerFactory = pluginRegistry.getBeanByFullPrefix( SenseiConfParams.SERVER_SEARCH_ROUTER_FACTORY, PartitionedLoadBalancerFactory.class); if (routerFactory == null) { routerFactory = new SenseiPartitionedLoadBalancerFactory(50); } senseiApp.setAttribute("sensei.search.router.factory", routerFactory); senseiApp.addEventListener(new SenseiConfigServletContextListener()); senseiApp.addServlet(senseiServletHolder, "/" + SENSEI_CONTEXT_PATH + "/*"); senseiApp.setResourceBase(webappPath); senseiApp.addServlet(springServletHolder, "/sensei-rpc/SenseiSpringRPCService"); senseiApp.addServlet(jmxServletHolder, "/admin/jmx/*"); server.setHandler(senseiApp); server.setStopAtShutdown(true); return server; }