public static void main(String[] args) throws Exception { String weppAppHome = args[0]; Integer port = 8080; Server server = new Server(port); WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/"); webapp.setCompactPath(true); webapp.setDescriptor(weppAppHome + "/WEB-INF/web.xml"); webapp.setResourceBase(weppAppHome); webapp.setParentLoaderPriority(true); server.setHandler(webapp); server.start(); server.join(); }
public JettyAdminServer(String address, int port, int timeout, String commandUrl) { this.port = port; this.idleTimeout = timeout; this.commandUrl = commandUrl; this.address = address; server = new Server(); ServerConnector connector = new ServerConnector(server); connector.setHost(address); connector.setPort(port); connector.setIdleTimeout(idleTimeout); server.addConnector(connector); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/*"); server.setHandler(context); context.addServlet(new ServletHolder(new CommandServlet()), commandUrl + "/*"); }
/** * Shuts down the web server. */ public void stop() throws Exception { // close all connectors and release all binding ports for (Connector connector : mServer.getConnectors()) { connector.stop(); } mServer.stop(); }
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); } } }
final String keyStorePath = getClass().getClassLoader().getResource("keystore.jks").getFile(); Server server = new Server(); HttpConfiguration https = new HttpConfiguration(); https.addCustomizer(new SecureRequestCustomizer()); sslContextFactory.setKeyManagerPassword("abc123"); ServerConnector sslConnector = new ServerConnector( server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https) ); sslConnector.setPort(0); server.setConnectors(new Connector[]{sslConnector}); server.start(); new Request( HttpMethod.GET, new URL(StringUtils.format("https://localhost:%d/", sslConnector.getLocalPort())) ), new StatusResponseHandler(StandardCharsets.UTF_8) server.stop();
Server server = new Server(8080); server.setStopAtShutdown(true); WebAppContext webAppContext = new WebAppContext(); webAppContext.setContextPath("/app"); webAppContext.setResourceBase("src/main/webapp"); webAppContext.setClassLoader(getClass().getClassLoader()); server.addHandler(webAppContext); server.start(); URL url = new URL("http://localhost:8080/app/some_call"); URLConnection connection = url.openConnection(); List<String> lines = IOUtils.readLines(connection.getInputStream()); System.out.println(lines.get(0));
public static Server createServer(int port) throws MalformedURLException, URISyntaxException { Server server = new Server(); server.setStopAtShutdown(true); ServerConnector connector = new ServerConnector(server); connector.setPort(port); connector.setReuseAddress(true); server.setConnectors(new Connector[]{connector}); WebAppContext webContext = new WebAppContext("webapp", CONTEXT); webContext.setBaseResource(Resource.newResource(new URL(ApiWebSite.class.getResource("/webapp/WEB-INF"), "."))); webContext.setClassLoader(ApiWebSite.class.getClassLoader()); server.setHandler(webContext); return server; }
public static void main(String[] args) throws Exception { Server server = new Server(8080); String rootPath = SimplestServer.class.getClassLoader().getResource(".").toString(); WebAppContext webapp = new WebAppContext(rootPath + "../../src/main/webapp", ""); server.setHandler(webapp); server.start(); server.join(); }
server = (Server) new XmlConfiguration(jettyInputStream).configure(); } else { server = new Server(port); server = new Server(port); webAppContext = new WebAppContext(); webAppContext.setParentLoaderPriority(true); webAppContext.setThrowUnavailableOnStartupException(true); classPath = classLoader.getResource(".").getPath(); rootPath = new File(classPath).getParentFile().getParentFile().getCanonicalFile().getAbsolutePath() + "/"; staticURL = staticUrls.nextElement(); if (staticURL != null) { resourceUrls.add(staticURL.toExternalForm()); sessionManager.setSessionIdPathParameterName(null); server.setHandler(webAppContext);
@Override public void start() { LOG.info("Starting Kaa Admin Web Server..."); server = new Server(adminPort); webAppContext = new WebAppContext(); webAppContext.setEventListeners(new EventListener[]{adminContextLoaderListener}); webAppContext.setContextPath("/"); String webXmlLocation = AdminInitializationService.class.getResource("/admin-web/WEB-INF/" + webXmlFile).toString(); webAppContext.setDescriptor(webXmlLocation); String resLocation = AdminInitializationService.class.getResource("/admin-web").toString(); webAppContext.setResourceBase(resLocation); webAppContext.setParentLoaderPriority(true); server.setHandler(webAppContext); try { server.start(); LOG.info("Kaa Admin Web Server started."); } catch (Exception ex) { LOG.error("Error starting Kaa Admin Web Server!", ex); } }
public static void main(String[] args) throws Exception { String configPort = "8080"; if(args.length > 0){ configPort = args[0]; } String port = System.getProperty("server.http.port", configPort); System.out.println("Server started on port: " + port); Server server = new Server(); server.setConnectors(new Connector[]{createConnector(server, Integer.parseInt(port))}); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); context.setContextPath("/api"); ServletHolder servletHolder = new ServletHolder(createJerseyServlet()); servletHolder.setInitOrder(1); context.addServlet(servletHolder, "/*"); WebAppContext webAppContext = new WebAppContext(); webAppContext.setServer(server); webAppContext.setContextPath("/"); String resourceBase = System.getProperty("resourceBase"); if(resourceBase != null){ webAppContext.setResourceBase(resourceBase); } else { webAppContext.setResourceBase(Main.class.getResource("/webapp").toExternalForm()); } HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[]{context, webAppContext}); server.setHandler(handlers); server.start(); server.join(); }
@Override @BeforeClass public void setUpGlobal() throws Exception { server = new Server(); ServerConnector connector = addHttpConnector(server); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); server.setHandler(context); context.addServlet(new ServletHolder(new MockTimeoutHttpServlet()), "/timeout/*"); server.start(); port1 = connector.getLocalPort(); }
m_server = new Server(m_pool); else m_server = new Server(); m_server.addBean(errorHandler); ServerConnector http = new ServerConnector(m_server); http.setHost(m_address.getHostName()); http.setPort(m_port); m_server.addConnector(http); sslContextFactory.setIncludeProtocols(m_protocols); ServerConnector https = new ServerConnector(m_server, new SslConnectionFactory(sslContextFactory,"http/1.1"), new HttpConnectionFactory(httpConfig)); https.setPort(m_sslPort); m_server.addConnector(https); ServletContextHandler servletContextHandler = new ServletContextHandler(); servletContextHandler.setSecurityHandler(basicAuth(m_authUser, m_authPassword, "kairos")); servletContextHandler.setContextPath("/"); m_server.setHandler(handlers); m_server.start();
FlumeBeanConfigurator.setConfigurationFields(threadPool, sourceContext); srv = new Server(threadPool); srv.addEventListener(mbContainer); srv.addBean(mbContainer); HttpConfiguration httpConfiguration = new HttpConfiguration(); httpConfiguration.addCustomizer(new SecureRequestCustomizer()); srv.addConnector(connector); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); srv.setHandler(context); context.addServlet(new ServletHolder(new FlumeHTTPServlet()),"/"); context.setSecurityHandler(HTTPServerConstraintUtil.enforceConstraints()); srv.start(); } catch (Exception ex) { LOG.error("Error while starting HTTPSource. Exception follows.", ex); Throwables.propagate(ex); Preconditions.checkArgument(srv.isRunning()); sourceCounter.start(); super.start();
@BeforeClass public static void startJettyServer() throws Exception { // Let server pick its own random, available port. jettyServer = new Server(0); ServletContextHandler handler = new ServletContextHandler(); MultipartConfigElement multipartConfig = new MultipartConfigElement(""); ServletHolder holder = new ServletHolder(partsServlet); holder.getRegistration().setMultipartConfig(multipartConfig); handler.addServlet(holder, "/parts"); holder = new ServletHolder(partListServlet); holder.getRegistration().setMultipartConfig(multipartConfig); handler.addServlet(holder, "/partlist"); jettyServer.setHandler(handler); jettyServer.start(); Connector[] connectors = jettyServer.getConnectors(); NetworkConnector connector = (NetworkConnector) connectors[0]; baseUrl = "http://localhost:" + connector.getLocalPort(); }
public void start() { server = new Server(); ServerConnector connector = new ServerConnector(server); connector.setPort(port); server.addConnector(connector); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); server.setHandler(context); try { ServerContainer wscontainer = WebSocketServerContainerInitializer.configureContext(context); wscontainer.addEndpoint(new RPDEndpointConfig()); server.start(); server.join(); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public void start() { jettyServer = new Server(); //We can use Contexts etc if we have many urls to handle. For one url, //specifying a handler directly is the most efficient. HttpConfiguration httpConfiguration = new HttpConfiguration(); ServerConnector connector = new ServerConnector(jettyServer, new HttpConnectionFactory(httpConfiguration)); connector.setReuseAddress(true); connector.setPort(port); jettyServer.addConnector(connector); jettyServer.setHandler(new HTTPMetricsHandler()); try { jettyServer.start(); while (!jettyServer.isStarted()) { Thread.sleep(500); } } catch (Exception ex) { LOG.error("Error starting Jetty. JSON Metrics may not be available.", ex); } }
private void start() throws Exception { server = new Server(); ServerConnector connector = new ServerConnector(server); server.addConnector(connector); sslContextFactory.setKeyStorePassword("serverKeystorepa55w0rd"); ServerConnector secureConnnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(new HttpConfiguration()) ); server.addConnector(secureConnnector); wac.addServlet(holder, "/hello"); addFakeAgentBinaryServlet(wac, "/admin/agent", TEST_AGENT, this); addFakeAgentBinaryServlet(wac, "/admin/agent-launcher.jar", TEST_AGENT_LAUNCHER, this); addlatestAgentStatusCall(wac); addDefaultServlet(wac); server.setHandler(wac); server.setStopAtShutdown(true); server.start(); port = connector.getLocalPort(); securePort = secureConnnector.getLocalPort();
ServletHolder sh = new ServletHolder(new ServletContainer(app)); server = new Server(0); LOG.info("configured " + ServletContainer.class.getName()); HttpConfiguration httpConfig = new HttpConfiguration(); httpConfig.setSendDateHeader(false); httpConfig.setSendServerVersion(false); ServerConnector serverConnector = new ServerConnector(server, new HttpConnectionFactory(httpConfig)); serverConnector.setPort(testServletPort); server.addConnector(serverConnector); ServletContextHandler ctxHandler = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS); ctxHandler.addServlet(sh, "/*"); for (String filter : filterClasses) { filter = filter.trim(); ctxHandler.addFilter(filter, "/*", EnumSet.of(DispatcherType.REQUEST)); server.start(); testServletPort = ((ServerConnector)server.getConnectors()[0]).getLocalPort();