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); } } }
@Override synchronized public void registerServlet(String contextPath, Servlet servlet) { if (server.getHandler() != null) { return; } log.info("Registering UPnP servlet under context path: " + contextPath); ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); if (contextPath != null && contextPath.length() > 0) servletHandler.setContextPath(contextPath); ServletHolder s = new ServletHolder(servlet); servletHandler.addServlet(s, "/*"); server.setHandler(servletHandler); }
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(); }
/** Constructs a server to run on the named port on the specified address. */ public HttpServer(ResponderServlet servlet, String bindAddress, int port) throws IOException { this.server = new org.eclipse.jetty.server.Server(); ServerConnector connector = new ServerConnector(this.server); connector.setAcceptQueueSize(128); connector.setIdleTimeout(10000); if (bindAddress != null) { connector.setHost(bindAddress); } connector.setPort(port); server.addConnector(connector); ServletHandler handler = new ServletHandler(); handler.addServletWithMapping(new ServletHolder(servlet), "/*"); ServletContextHandler sch = new ServletContextHandler(); sch.setServletHandler(handler); server.setHandler(sch); }
/** * 启动内嵌的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(); }
/** 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); } }
protected void startWithHandler(Handler handler) throws Exception { server.setHandler(handler); server.start(); } }
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"; }
/** * Config filter. * @param server Server * @param servlet Servlet * @param filtersConfs FiltersConfs * @param params Filter params */ public static void configFilter(Server server, Servlet servlet, List<FilterConfiguration> filtersConfs, Map<String, String> params) { if (filtersConfs != null) { ServletHolder servletHolder = new ServletHolder(servlet); servletHolder.setInitOrder(0); if (params != null) { servletHolder.setInitParameters(params); } ServletContextHandler context = new ServletContextHandler(server, "/"); context.addServlet(servletHolder, "/"); configFilters(context, filtersConfs); server.setHandler(context); } }
threadPool.setMaxThreads(webThreadCount * 2 + 100); mServer = new Server(threadPool); mServletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); mServletContextHandler.setContextPath(AlluxioURI.SEPARATOR); mServer.setHandler(handlers);
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)); }
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(); }
private void initJettyContextHandler(final CoreConfigure cfg) { final ServletContextHandler context = new ServletContextHandler(NO_SESSIONS); final String contextPath = "/sandbox/" + cfg.getNamespace(); context.setContextPath(contextPath); context.setClassLoader(getClass().getClassLoader()); // web-socket-servlet final String wsPathSpec = "/module/websocket/*"; logger.info("initializing ws-http-handler. path={}", contextPath + wsPathSpec); context.addServlet(new ServletHolder(new WebSocketAcceptorServlet(coreModuleManager, moduleResourceManager)), wsPathSpec); // module-http-servlet final String pathSpec = "/module/http/*"; logger.info("initializing http-handler. path={}", contextPath + pathSpec); context.addServlet(new ServletHolder(new ModuleHttpServlet(coreModuleManager, moduleResourceManager)), pathSpec); httpServer.setHandler(context); }
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; }
/** * 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"); }
httpsTsPath, httpsTsPassword, httpsTsType, httpsNeedClientAuth, httpsWantClientAuth); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); context.setContextPath("/"); ret.setHandler(context); ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, "/*"); jerseyServlet.setInitOrder(1); jerseyServlet.setInitParameter("javax.ws.rs.Application", DRPCApplication.class.getName());