private void startJetty(int port, SeimiHttpHandler seimiHttpHandler) { Server server = new Server(port); server.setHandler(seimiHttpHandler); try { server.start(); server.join(); } catch (Exception e) { logger.error("http service start error,{}", e.getMessage(), e); } } }
protected void startWithHandler(Handler handler) throws Exception { server.setHandler(handler); server.start(); } }
@Override protected void startUp() throws Exception { LOGGER.info("Starting the admin web server"); this.server = new Server(new InetSocketAddress(this.serverUri.getHost(), this.serverUri.getPort())); HandlerCollection handlerCollection = new HandlerCollection(); handlerCollection.addHandler(buildSettingsHandler()); handlerCollection.addHandler(buildStaticResourceHandler()); this.server.setHandler(handlerCollection); this.server.start(); }
@BeforeClass public static void init() throws Exception { Map<String, Object> map = new HashMap<>(); map.put("key", "value1"); map.put("num", 42); JSON_RESPONSE = objectMapper.writeValueAsString(map); server = new Server(7009); ServletContextHandler servletContextHandler = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS); servletContextHandler.setHandler(new EchoHandler()); server.start(); }
/** * 启动内嵌的RESTful服务器. * * @param packages RESTful实现类所在包 * @param resourcePath 资源路径 * @param servletPath servlet路径 * @throws Exception 启动服务器异常 */ public void start(final String packages, final Optional<String> resourcePath, final Optional<String> servletPath) throws Exception { log.info("Elastic Job: Start RESTful server"); HandlerList handlers = new HandlerList(); if (resourcePath.isPresent()) { servletContextHandler.setBaseResource(Resource.newClassPathResource(resourcePath.get())); servletContextHandler.addServlet(new ServletHolder(DefaultServlet.class), "/*"); } String servletPathStr = (servletPath.isPresent() ? servletPath.get() : "") + "/*"; servletContextHandler.addServlet(getServletHolder(packages), servletPathStr); handlers.addHandler(servletContextHandler); server.setHandler(handlers); server.start(); }
@BeforeClass(alwaysRun = true) @Override public void setUpGlobal() throws Exception { server = new Server(); ServerConnector connector = addHttpConnector(server); addDigestAuthHandler(server, configureHandler()); server.start(); port1 = connector.getLocalPort(); logger.info("Local HTTP server started successfully"); }
/** recreates the server so that it uses the supplied trace configuration */ public final void init() { stop(); server = newServer(port); ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); server.setHandler(context); init(context); try { server.start(); port = getLocalPort(server); } catch (Exception e) { throw new IllegalStateException("Failed to start server.", e); } }
public void start() throws Exception { if (!isBuild) { throw new ServerException("You must build it before start"); } if (Constant.devEnable) { reloadRunnable = new ReloadRunnable(this); reloadObserver = new ReloadObserver(reloadRunnable, this); reloadRunnable.addObserver(reloadObserver); watchThread = new Thread(reloadRunnable, "RestyServer-Watcher");//启动文件监控线程 watchThread.start(); } server.start(); server.join(); }
Server server = new Server(8080); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); context.addServlet(org.eclipse.jetty.servlet.DefaultServlet.class, "/"); context.addFilter(AppFilter.class, "/*", EnumSet.of(DispatcherType.INCLUDE,DispatcherType.REQUEST)); server.setHandler(context); server.start(); server.join();
private static void startServer() throws Exception { File warFile = findWar(); server = new Server(8080); WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/"); webapp.setWar(warFile.getAbsolutePath()); server.setHandler(webapp); server.start(); eurekaServiceUrl = "http://localhost:8080/v2"; }
threadPool.setMinThreads(threads); server = new Server(threadPool); ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS); context.setServletHandler(servletHandler); ServletManager.getInstance().addServletContext(url.getParameter(Constants.BIND_PORT_KEY, url.getPort()), context.getServletContext()); server.start(); } catch (Exception e) { throw new IllegalStateException("Failed to start jetty server on " + url.getParameter(Constants.BIND_IP_KEY) + ":" + url.getParameter(Constants.BIND_PORT_KEY) + ", cause: "
Server server = new Server(8080); WebSocketHandler wsHandler = new WebSocketHandler() { @Override public void configure(WebSocketServletFactory factory) { factory.register(MyEchoSocket.class); } }; ContextHandler context = new ContextHandler(); context.setContextPath("/echo"); context.setHandler(wsHandler); server.addHandler(context); server.start(); server.join();
@BeforeClass(alwaysRun = true) @Override public void setUpGlobal() throws Exception { server = new Server(); ServerConnector connector1 = addHttpConnector(server); addBasicAuthHandler(server, configureHandler()); server.start(); port1 = connector1.getLocalPort(); logger.info("Local HTTP server started successfully"); }
public static void main(String[] args) throws Exception { Movie movie = MovieCreator.build("/home/sannies/CSI.S13E02.HDTV.x264-LOL.mp4"); Server server = new Server(8080); server.setHandler(new ServeMp4(movie)); server.start(); server.join(); }
public StatsServer(StatsPlugin plugin, int port) throws Exception { this.httpServer = new Server(port); this.plugin = plugin; ServletHandler handler = new ServletHandler(); httpServer.setHandler(handler); handler.addServletWithMapping(new ServletHolder(new StaticServlet()), "/"); handler.addServletWithMapping(new ServletHolder(new StatsServlet(plugin)), "/"); httpServer.start(); }
threadPool.setMinThreads(threads); server = new Server(threadPool); ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS); context.setServletHandler(servletHandler); ServletManager.getInstance().addServletContext(url.getParameter(Constants.BIND_PORT_KEY, url.getPort()), context.getServletContext()); server.start(); } catch (Exception e) { throw new IllegalStateException("Failed to start jetty server on " + url.getParameter(Constants.BIND_IP_KEY) + ":" + url.getParameter(Constants.BIND_PORT_KEY) + ", cause: "
@BeforeClass(alwaysRun = true) @Override public void setUpGlobal() throws Exception { server = new Server(); ServerConnector connector1 = addHttpConnector(server); addBasicAuthHandler(server, configureHandler()); server.start(); port1 = connector1.getLocalPort(); server2 = new Server(); ServerConnector connector2 = addHttpConnector(server2); addDigestAuthHandler(server2, configureHandler()); server2.start(); port2 = connector2.getLocalPort(); logger.info("Local HTTP server started successfully"); }