Java Code Examples for org.eclipse.jetty.server.Server#join()

The following examples show how to use org.eclipse.jetty.server.Server#join() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Application.java    From vk-java-sdk with MIT License 6 votes vote down vote up
private static void initServer(Properties properties) throws Exception {
    Integer port = Integer.valueOf(properties.getProperty("server.port"));
    String host = properties.getProperty("server.host");

    Integer clientId = Integer.valueOf(properties.getProperty("client.id"));
    String clientSecret = properties.getProperty("client.secret");

    HandlerCollection handlers = new HandlerCollection();

    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setDirectoriesListed(true);
    resourceHandler.setWelcomeFiles(new String[]{"index.html"});
    resourceHandler.setResourceBase(Application.class.getResource("/static").getPath());

    VkApiClient vk = new VkApiClient(new HttpTransportClient());
    handlers.setHandlers(new Handler[]{resourceHandler, new RequestHandler(vk, clientId, clientSecret, host)});

    Server server = new Server(port);
    server.setHandler(handlers);

    server.start();
    server.join();
}
 
Example 2
Source File: PrometheusServer.java    From monsoon with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    final ApiServer api = new ApiServer(new InetSocketAddress(9998));

    PrometheusConfig cfg = createPrometheusConfig(args);
    final Optional<File> _cfg = cfg.getConfiguration();
    if (_cfg.isPresent())
        registry_ = new PipelineBuilder(_cfg.get()).build();
    else
        registry_ = new PipelineBuilder(Configuration.DEFAULT).build();

    api.start();
    Runtime.getRuntime().addShutdownHook(new Thread(api::close));

    Server server = new Server(cfg.getPort());
    ContextHandler context = new ContextHandler();
    context.setClassLoader(Thread.currentThread().getContextClassLoader());
    context.setContextPath(cfg.getPath());
    context.setHandler(new DisplayMetrics(registry_));
    server.setHandler(context);
    server.start();
    server.join();
}
 
Example 3
Source File: Main.java    From openscoring with GNU Affero General Public License v3.0 6 votes vote down vote up
public void run() throws Exception {
	InetSocketAddress address;

	if(this.host != null){
		address = new InetSocketAddress(this.host, this.port);
	} else

	{
		address = new InetSocketAddress(this.port);
	}

	Server server = createServer(address);

	server.start();
	server.join();
}
 
Example 4
Source File: AmforeasJetty.java    From amforeas with GNU General Public License v3.0 6 votes vote down vote up
protected void startServer (final AmforeasConfiguration conf) throws Exception {
    final QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setMinThreads(conf.getServerThreadsMin());
    threadPool.setMaxThreads(conf.getServerThreadsMax());

    final Server server = new Server(threadPool);

    setupJerseyServlet(conf, server);
    setupHTTPConnection(conf, server);
    setupHTTPSConnection(conf, server);


    server.start();
    server.setStopAtShutdown(true);
    server.join();
}
 
Example 5
Source File: StatsServer.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) throws Exception {
    final Server server = new Server(8686);

    final ServletHolder staticHolder = new ServletHolder(new DefaultServlet());
    final ServletContextHandler staticContext = new ServletContextHandler();
    staticContext.setContextPath("/static");
    staticContext.addServlet(staticHolder, "/*");
    staticContext.setResourceBase(StatsServer.class.getResource("/web-ui").toURI().toString());

     // Register and map the dispatcher servlet
    final ServletHolder cxfServletHolder = new ServletHolder(new CXFServlet());
    final ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    context.addEventListener(new ContextLoaderListener());
    context.addServlet(cxfServletHolder, "/rest/*");
    context.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
    context.setInitParameter("contextConfigLocation", StatsConfig.class.getName());

    HandlerList handlers = new HandlerList();
    handlers.addHandler(staticContext);
    handlers.addHandler(context);

    server.setHandler(handlers);
    server.start();
    server.join();
}
 
Example 6
Source File: Bootstrap.java    From qmq with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    context.setResourceBase(System.getProperty("java.io.tmpdir"));
    DynamicConfig config = DynamicConfigLoader.load("metaserver.properties");
    final ServerWrapper wrapper = new ServerWrapper(config);
    wrapper.start(context.getServletContext());

    context.addServlet(MetaServerAddressSupplierServlet.class, "/meta/address");
    context.addServlet(MetaManagementServlet.class, "/management");
    context.addServlet(SubjectConsumerServlet.class, "/subject/consumers");
    context.addServlet(OnOfflineServlet.class, "/onoffline");
    context.addServlet(SlaveServerAddressSupplierServlet.class, "/slave/meta");

    // TODO(keli.wang): allow set port use env
    int port = config.getInt("meta.server.discover.port", 8080);
    final Server server = new Server(port);
    server.setHandler(context);
    server.start();
    server.join();
}
 
Example 7
Source File: MainServer.java    From JrebelBrainsLicenseServerforJava with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Map<String, String> arguments = parseArguments(args);
    String port = arguments.get("p");

    if (port == null || !port.matches("\\d+")) {
        port = "8081";
    }

    Server server = new Server(Integer.parseInt(port));
    server.setHandler(new MainServer());
    server.start();

    System.out.println("License Server started at http://localhost:" + port);
    System.out.println("JetBrains Activation address was: http://localhost:" + port + "/");
    System.out.println("JRebel 7.1 and earlier version Activation address was: http://localhost:" + port + "/{tokenname}, with any email.");
    System.out.println("JRebel 2018.1 and later version Activation address was: http://localhost:" + port + "/{guid}(eg:http://localhost:" + port + "/"+ UUID.randomUUID().toString()+"), with any email.");

    server.join();
}
 
Example 8
Source File: FileServer.java    From cs601 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
      Server server = new Server(8080);
      ResourceHandler resource_handler = new ResourceHandler();
      resource_handler.setDirectoriesListed(true);
resource_handler.setResourceBase(".");                    // must set root dir

      HandlerList handlers = new HandlerList();
      handlers.setHandlers(new Handler[] { resource_handler, 	  // file handler
									 new DefaultHandler() // handles 404 etc...
});
      server.setHandler(handlers);

      server.start();
      server.join();
  }
 
Example 9
Source File: ExampleExporter.java    From client_java with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  Server server = new Server(1234);
  ServletContextHandler context = new ServletContextHandler();
  context.setContextPath("/");
  server.setHandler(context);
  context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics");
  g.set(1);
  c.inc(2);
  s.observe(3);
  h.observe(4);
  l.labels("foo").inc(5);
  server.start();
  server.join();
}
 
Example 10
Source File: Starter.java    From jumbune with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void start() {

		Server server = new Server(9080);
		ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
		servletContextHandler.setContextPath("/");
		servletContextHandler.setResourceBase("src/main/webapp");

		final String webAppDirectory = JumbuneInfo.getHome() + "modules/webapp";
		final ResourceHandler resHandler = new ResourceHandler();
		resHandler.setResourceBase(webAppDirectory);
		final ContextHandler ctx = new ContextHandler("/");
		ctx.setHandler(resHandler);
		servletContextHandler.setSessionHandler(new SessionHandler());

		ServletHolder servletHolder = servletContextHandler.addServlet(ServletContainer.class, "/apis/*");
		servletHolder.setInitOrder(0);
		servletHolder.setAsyncSupported(true);
		servletHolder.setInitParameter("jersey.config.server.provider.packages", "org.jumbune.web.services");
		servletHolder.setInitParameter("jersey.config.server.provider.classnames",
				"org.glassfish.jersey.media.multipart.MultiPartFeature");

		try {
			server.insertHandler(servletContextHandler);
			server.insertHandler(resHandler);
			server.start();
			server.join();
		} catch (Exception e) {
			LOGGER.error("Error occurred while starting Jetty", e);
			System.exit(1);
		}
	}
 
Example 11
Source File: Main.java    From backstopper with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Server server = createServer(Integer.parseInt(System.getProperty(PORT_SYSTEM_PROP_KEY, "8080")));

    try {
        server.start();
        server.join();
    }
    finally {
        server.destroy();
    }
}
 
Example 12
Source File: Main.java    From wingtips with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Server server = createServer(Integer.parseInt(System.getProperty(PORT_SYSTEM_PROP_KEY, "8080")));

    try {
        server.start();
        server.join();
    }
    finally {
        server.destroy();
    }
}
 
Example 13
Source File: WebServer.java    From cloudwatch_exporter with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (args.length < 2) {
        System.err.println("Usage: WebServer <port> <yml configuration file>");
        System.exit(1);
    }

    configFilePath = args[1];
    CloudWatchCollector collector = null;
    FileReader reader = null;

    try {
      reader = new FileReader(configFilePath);
      collector = new CloudWatchCollector(new FileReader(configFilePath)).register();
    } finally {
      if (reader != null) {
        reader.close();
      }
    }

    ReloadSignalHandler.start(collector);

    int port = Integer.parseInt(args[0]);
    Server server = new Server(port);
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    server.setHandler(context);
    context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics");
    context.addServlet(new ServletHolder(new DynamicReloadServlet(collector)), "/-/reload");
    context.addServlet(new ServletHolder(new HealthServlet()), "/-/healthy");
    context.addServlet(new ServletHolder(new HealthServlet()), "/-/ready");
    context.addServlet(new ServletHolder(new HomePageServlet()), "/");
    server.start();
    server.join();
}
 
Example 14
Source File: Main.java    From heroku-maven-plugin with MIT License 5 votes vote down vote up
public static void main(String[] args) throws Exception{
  Server server = new Server(Integer.valueOf(System.getenv("PORT")));
  ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
  context.setContextPath("/");
  server.setHandler(context);
  context.addServlet(new ServletHolder(new Main()),"/*");
  server.start();
  server.join();
}
 
Example 15
Source File: WebSessionServerStart.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param args Arguments.
 * @throws Exception In case of error.
 */
public static void main(String[] args) throws Exception {
    Server srv = jettyServer(Integer.valueOf(args[0]), Boolean.valueOf(args[1]) ?
        new SessionCheckServlet() : new SessionCreateServlet());

    srv.start();
    srv.join();
}
 
Example 16
Source File: FuzzerServer.java    From graphicsfuzz with Apache License 2.0 4 votes vote down vote up
public void start() throws Exception {

    FuzzerServiceImpl fuzzerService = new FuzzerServiceImpl(
        Paths.get(workingDir, processingDir).toString(),
        executorService);

    FuzzerService.Processor processor =
        new FuzzerService.Processor<FuzzerService.Iface>(fuzzerService);

    FuzzerServiceManagerImpl fuzzerServiceManager = new FuzzerServiceManagerImpl(fuzzerService,
          new PublicServerCommandDispatcher());
    FuzzerServiceManager.Processor managerProcessor =
        new FuzzerServiceManager.Processor<FuzzerServiceManager.Iface>(fuzzerServiceManager);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");

    {
      ServletHolder sh = new ServletHolder();
      sh.setServlet(new TServlet(processor, new TBinaryProtocol.Factory()));
      context.addServlet(sh, "/request");
    }
    {
      ServletHolder serveltHolderJson = new ServletHolder();
      serveltHolderJson.setServlet(new TServlet(processor, new TJSONProtocol.Factory()));
      context.addServlet(serveltHolderJson, "/requestJSON");
    }

    {
      ServletHolder shManager = new ServletHolder();
      shManager.setServlet(new TServlet(managerProcessor, new TBinaryProtocol.Factory()));
      context.addServlet(shManager, "/manageAPI");
    }

    final String staticDir = ToolPaths.getStaticDir();
    context.addServlet(
          new ServletHolder(
                new FileDownloadServlet(
                    (pathInfo, worker) -> Paths.get(staticDir, pathInfo).toFile(), staticDir)),
          "/static/*");

    HandlerList handlerList = new HandlerList();
    handlerList.addHandler(context);

    GzipHandler gzipHandler = new GzipHandler();
    gzipHandler.setHandler(handlerList);

    Server server = new Server(port);

    server.setHandler(gzipHandler);
    server.start();
    server.join();
  }
 
Example 17
Source File: Start.java    From wicket-orientdb with Apache License 2.0 4 votes vote down vote up
/**
 * Main function, starts the jetty server.
 *
 * @param args
 */
public static void main(String[] args)
{
	System.setProperty("wicket.configuration", "development");

	Server server = new Server();

	HttpConfiguration http_config = new HttpConfiguration();
	http_config.setSecureScheme("https");
	http_config.setSecurePort(8443);
	http_config.setOutputBufferSize(32768);

	ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config));
	http.setPort(8080);
	http.setIdleTimeout(1000 * 60 * 60);

	server.addConnector(http);

	Resource keystore = Resource.newClassPathResource("/keystore");
	if (keystore != null && keystore.exists())
	{
		// if a keystore for a SSL certificate is available, start a SSL
		// connector on port 8443.
		// By default, the quickstart comes with a Apache Wicket Quickstart
		// Certificate that expires about half way september 2021. Do not
		// use this certificate anywhere important as the passwords are
		// available in the source.

		SslContextFactory sslContextFactory = new SslContextFactory();
		sslContextFactory.setKeyStoreResource(keystore);
		sslContextFactory.setKeyStorePassword("wicket");
		sslContextFactory.setKeyManagerPassword("wicket");

		HttpConfiguration https_config = new HttpConfiguration(http_config);
		https_config.addCustomizer(new SecureRequestCustomizer());

		ServerConnector https = new ServerConnector(server, new SslConnectionFactory(
			sslContextFactory, "http/1.1"), new HttpConnectionFactory(https_config));
		https.setPort(8443);
		https.setIdleTimeout(500000);

		server.addConnector(https);
		System.out.println("SSL access to the examples has been enabled on port 8443");
		System.out
			.println("You can access the application using SSL on https://localhost:8443");
		System.out.println();
	}

	WebAppContext bb = new WebAppContext();
	bb.setServer(server);
	bb.setContextPath("/");
	bb.setWar("src/main/webapp");

	// uncomment next line if you want to test with JSESSIONID encoded in the urls
	// ((AbstractSessionManager)
	// bb.getSessionHandler().getSessionManager()).setUsingCookies(false);

	server.setHandler(bb);

	MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
	MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
	server.addEventListener(mBeanContainer);
	server.addBean(mBeanContainer);

	try
	{
		server.start();
		server.join();
	}
	catch (Exception e)
	{
		e.printStackTrace();
		System.exit(100);
	}
}
 
Example 18
Source File: Application.java    From cloud-security-xsuaa-integration with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
	Server server = createJettyServer();
	server.start();
	server.join();
}
 
Example 19
Source File: JettyLauncher.java    From logsniffer with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Starts Jetty.
 * 
 * @param args
 * @throws Exception
 */
public void start(final String[] args, final URL warLocation) throws Exception {
	Server server = new Server();
	ServerConnector connector = new ServerConnector(server);

	// Set JSP to use Standard JavaC always
	System.setProperty("org.apache.jasper.compiler.disablejsr199", "false");

	// Set some timeout options to make debugging easier.
	connector.setIdleTimeout(1000 * 60 * 60);
	connector.setSoLingerTime(-1);
	connector.setPort(Integer.parseInt(System.getProperty("logsniffer.httpPort", "8082")));
	connector.setHost(System.getProperty("logsniffer.httpListenAddress", "0.0.0.0"));
	server.setConnectors(new Connector[] { connector });

	// Log.setLog(new Slf4jLog());

	// This webapp will use jsps and jstl. We need to enable the
	// AnnotationConfiguration in order to correctly
	// set up the jsp container
	Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(server);
	classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
			"org.eclipse.jetty.annotations.AnnotationConfiguration");

	WebContextWithExtraConfigurations ctx = createWebAppContext();

	ctx.setServer(server);
	ctx.setWar(warLocation.toExternalForm());
	String ctxPath = System.getProperty("logsniffer.contextPath", "/");
	if (!ctxPath.startsWith("/")) {
		ctxPath = "/" + ctxPath;
	}
	ctx.setContextPath(ctxPath);
	configureWebAppContext(ctx);
	ctx.freezeConfigClasses();
	server.setHandler(ctx);

	server.setStopAtShutdown(true);
	try {
		server.start();
		server.join();
	} catch (Exception e) {
		e.printStackTrace();
		System.exit(100);
	}
}
 
Example 20
Source File: TestServer.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Starts the server and returns a {@link CompletableFuture}. The {@link CompletableFuture} gets completed as soon
 * as the server is ready to accept connections.
 *
 * @return a {@link CompletableFuture} which completes as soon as the server is ready to accept connections.
 */
public CompletableFuture<Boolean> startServer() {
    final CompletableFuture<Boolean> serverStarted = new CompletableFuture<>();

    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            server = new Server();
            ServletHandler handler = new ServletHandler();
            handler.addServletWithMapping(servletHolder, "/*");
            server.setHandler(handler);

            // HTTP connector
            ServerConnector http = new ServerConnector(server);
            http.setHost(host);
            http.setPort(port);
            http.setIdleTimeout(timeout);

            server.addConnector(http);

            try {
                server.start();
                serverStarted.complete(true);
                server.join();
            } catch (InterruptedException ex) {
                logger.error("Server got interrupted", ex);
                serverStarted.completeExceptionally(ex);
                return;
            } catch (Exception e) {
                logger.error("Error in starting the server", e);
                serverStarted.completeExceptionally(e);
                return;
            }

        }
    });

    thread.start();

    return serverStarted;
}