public void startServletContainer(Configuration conf) throws Exception { if (server != null) { LOG.error("ServletContainer already running"); return; } // Inject the conf for the test by being first to make singleton RESTServlet.getInstance(conf); // set up the Jersey servlet container for Jetty ServletHolder sh = new ServletHolder(ServletContainer.class); sh.setInitParameter( "com.sun.jersey.config.property.resourceConfigClass", ResourceConfig.class.getCanonicalName()); sh.setInitParameter("com.sun.jersey.config.property.packages", "jetty"); LOG.info("configured " + ServletContainer.class.getName()); // set up Jetty and run the embedded server server = new Server(0); server.setSendServerVersion(false); server.setSendDateHeader(false); // set up context Context context = new Context(server, "/", Context.SESSIONS); context.addServlet(sh, "/*"); context.addFilter(GzipFilter.class, "/*", 0); // start the server server.start(); // get the port testServletPort = server.getConnectors()[0].getLocalPort(); LOG.info("started " + server.getClass().getName() + " on port " + testServletPort); }