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); } } }
public TestJettyWebSocketServer(final WebSocketHandler webSocketHandler) { this.server = new Server(); ServerConnector connector = new ServerConnector(this.server); connector.setPort(0); this.server.addConnector(connector); this.server.setHandler(new org.eclipse.jetty.websocket.server.WebSocketHandler() { @Override public void configure(WebSocketServletFactory factory) { factory.setCreator(new WebSocketCreator() { @Override public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) { if (!CollectionUtils.isEmpty(req.getSubProtocols())) { resp.setAcceptedSubProtocol(req.getSubProtocols().get(0)); } JettyWebSocketSession session = new JettyWebSocketSession(null, null); return new JettyWebSocketHandlerAdapter(webSocketHandler, session); } }); } }); }
@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(); }
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(); }
@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(); }
threadPool.setMaxThreads(webThreadCount * 2 + 100); mServer = new Server(threadPool); mServletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); mServletContextHandler.setContextPath(AlluxioURI.SEPARATOR); mServer.setHandler(handlers);
@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"); }
private static Server makeTestDeleteServer(int port, final CountDownLatch latch) { Server server = new Server(port); ServletHandler handler = new ServletHandler(); handler.addServletWithMapping(new ServletHolder(new HttpServlet() { @Override protected void doDelete(HttpServletRequest req, HttpServletResponse resp) { latch.countDown(); resp.setStatus(200); } }), "/default/*"); server.setHandler(handler); return server; }
jetty = new Server(); this.contextHandler = new ServletContextHandler(jetty, getContextPath()); this.contextHandler.addServlet(DefaultServlet.class, "/");
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"); }
private void createServer(final Map<String, String> sslProperties) { jetty = new Server(); // create the unsecure connector createConnector(); // create the secure connector if sslProperties are specified if (sslProperties != null) { createSecureConnector(sslProperties); } jetty.setHandler(new HandlerCollection(true)); }
/** * Start the server. * @param port the port it shuld listen on, or null/<= 0 to pick a free ephemeral port. */ public void serve(Integer port) { try { if (server != null) { throw new RuntimeException("The server is already running"); } if (port == null || port <= 0) { ServerSocket s = new ServerSocket(0); port = s.getLocalPort(); s.close(); } server = new Server(port); this.port = port; url = "http://" + InetAddress.getLocalHost().getHostName() + ":" + this.port + "/"; ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); server.setHandler(context); context.addServlet(new ServletHolder(new MetricsCollectionServlet()),"/*"); server.start(); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
@BeforeClass(alwaysRun = true) public void setUpGlobal() throws Exception { server = new Server(); ServerConnector connector = addHttpConnector(server); server.setHandler(new IdleStateHandler()); server.start(); port1 = connector.getLocalPort(); logger.info("Local HTTP server started successfully"); }
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: "