当前位置: 首页>>代码示例>>Java>>正文


Java Server.addConnector方法代码示例

本文整理汇总了Java中org.eclipse.jetty.server.Server.addConnector方法的典型用法代码示例。如果您正苦于以下问题:Java Server.addConnector方法的具体用法?Java Server.addConnector怎么用?Java Server.addConnector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jetty.server.Server的用法示例。


在下文中一共展示了Server.addConnector方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: JettyAdminServer

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
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 + "/*");
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:20,代码来源:JettyAdminServer.java

示例2: jettyServer

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
@Bean
public Server jettyServer(ApplicationContext context) throws Exception {
    HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
    Servlet servlet = new JettyHttpHandlerAdapter(handler);

    Server server = new Server();
    ServletContextHandler contextHandler = new ServletContextHandler(server, "");
    contextHandler.addServlet(new ServletHolder(servlet), "/");
    contextHandler.start();

    ServerConnector connector = new ServerConnector(server);
    connector.setHost("localhost");
    connector.setPort(port);
    server.addConnector(connector);

    return server;
}
 
开发者ID:hantsy,项目名称:spring-reactive-sample,代码行数:18,代码来源:Application.java

示例3: startJetty

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
private void startJetty() throws Exception {
	QueuedThreadPool jettyThreadPool = new QueuedThreadPool(jettyServerThreads);
	Server server = new Server(jettyThreadPool);

	ServerConnector http = new ServerConnector(server, new HttpConnectionFactory());
	http.setPort(jettyListenPort);
	
	server.addConnector(http);
	
	ContextHandler contextHandler = new ContextHandler();
	contextHandler.setHandler(botSocketHandler);
	server.setHandler(contextHandler);
	
   	server.start();
   	server.join();
}
 
开发者ID:BuaBook,项目名称:buabook-api-interface,代码行数:17,代码来源:BuaBookApiInterface.java

示例4: attachServerConnector

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
/**
 * Attaches a server connector listening on the specified port to the server. Further the connector
 * is hooked into the configuration system to received runtime port changes
 *
 * @param server
 *         the Jetty server
 *
 * @return the created conector
 */
private static ServerConnector attachServerConnector(final Server server) {

    int initialHttpPort = Configuration.getInteger("jetty.http.port", 8080);

    //TODO config set accept queue size
    //TODO config acceptor num
    //TODO config selector num
    //TODO config idle timeout
    final ServerConnector connector = new ServerConnector(server);
    connector.setPort(initialHttpPort);
    server.addConnector(connector);

    Configuration.addListener(ConfigChangeListener.forConfigProperty("jetty.http.port", (k, v) -> {
        LOG.info("Changing http port to " + v);
        connector.setPort(Integer.parseInt(v));
        try {
            connector.stop();
            connector.start();
            LOG.info("HTTP Port changed");
        } catch (Exception e) {
            LOG.log(Level.SEVERE, "Restarting connector failed", e);
        }
    }));
    return connector;
}
 
开发者ID:gmuecke,项目名称:boutique-de-jus,代码行数:35,代码来源:BoutiqueDeJusWebServer.java

示例5: PrometheusExporter

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
public PrometheusExporter(int port, String path) {
    
    QueuedThreadPool threadPool = new QueuedThreadPool(25);
    server = new Server(threadPool);

    ServerConnector connector = new ServerConnector(server);
    connector.setPort(port);
    server.addConnector(connector);

    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    server.setHandler(context);

    CollectorRegistry collectorRegistry = new CollectorRegistry();
    
    collectorRegistry.register(new PrometheusExports(CassandraMetricsRegistry.Metrics));

    MetricsServlet metricsServlet = new MetricsServlet(collectorRegistry);

    context.addServlet(new ServletHolder(metricsServlet), "/" + path);
    try {
        server.start();
    } catch (Exception e) {
        System.err.println("cannot start metrics http server " + e.getMessage());
    }
}
 
开发者ID:nabto,项目名称:cassandra-prometheus,代码行数:27,代码来源:PrometheusExporter.java

示例6: createServer

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
private Server createServer() {
    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(8384);
    server.addConnector(connector);

    ServletHandler handler = new ServletHandler();
    Servlet servlet = new HttpServlet() {
        private static final long serialVersionUID = 1L;

        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
            String path = req.getServletPath().substring(1);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
            resp.getWriter().append(path);
        }
        
    };
    handler.addServletWithMapping(new ServletHolder(servlet), "/");
    server.setHandler(handler);
    return server;
}
 
开发者ID:cschneider,项目名称:reactive-components,代码行数:27,代码来源:TestRs.java

示例7: run

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
/**
 * Run Jetty web server serving out supplied path on supplied port
 * 
 * @param path
 * @param port
 */
public void run(String path, String port) {
	Server server = new Server();
	SelectChannelConnector connector = new SelectChannelConnector();
       connector.setPort(Integer.parseInt(port));
       server.addConnector(connector);

       ResourceHandler resource_handler = new ResourceHandler();
       resource_handler.setDirectoriesListed(true);
       resource_handler.setWelcomeFiles(new String[]{ "index.html" });

       resource_handler.setResourceBase(path);

       HandlerList handlers = new HandlerList();
       handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
       server.setHandler(handlers);

       LOGGER.info("Serving out contents of: [{}] on http://localhost:{}/", path, port);
       LOGGER.info("(To stop server hit CTRL-C)");
       
       try {
		server.start();
		server.join();
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:ghaseminya,项目名称:jbake-rtl-jalaali,代码行数:33,代码来源:JettyServer.java

示例8: prepare

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
public void prepare(Handler handler) throws Exception {
    QueuedThreadPool serverThreads = new QueuedThreadPool();
    serverThreads.setName("server");
    server = new Server(serverThreads);
    connector = new ServerConnector(server);
    server.addConnector(connector);
    server.setHandler(handler);
    server.start();

    QueuedThreadPool clientThreads = new QueuedThreadPool();
    clientThreads.setName("client");
    httpClient = new HttpClient();
    httpClient.setExecutor(clientThreads);
    httpClient.start();
}
 
开发者ID:jetty-project,项目名称:jetty-reactive-httpclient,代码行数:16,代码来源:Usage.java

示例9: startServer

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
public static void startServer() throws ServletException {
    QueuedThreadPool threadPool = new QueuedThreadPool(10);
    threadPool.setDaemon(true);
    threadPool.setMaxThreads(10);
    Server server = new Server(threadPool);
    server.addBean(new ScheduledExecutorScheduler("JettyScheduler", true), true);
    ServerConnector http = new ServerConnector(server, new HttpConnectionFactory());
    http.setPort(2992);
    server.addConnector(http);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    context.setBaseResource(Resource.newClassPathResource("/org/lwjglx/debug/static"));
    context.setWelcomeFiles(new String[] { "index.html" });
    server.setHandler(context);

    WebSocketUpgradeFilter wsfilter = WebSocketUpgradeFilter.configureContext(context);
    // wsfilter.getFactory().getPolicy().setIdleTimeout(5000);
    wsfilter.addMapping(new ServletPathSpec("/ws"), new ProfilingConnectionCreator());

    ServletHolder holderDefault = new ServletHolder("default", DefaultServlet.class);
    holderDefault.setInitParameter("dirAllowed", "true");
    context.addServlet(holderDefault, "/");

    try {
        server.start();
    } catch (Exception e) {
        throw new AssertionError("Could not start profiling server", e);
    }
}
 
开发者ID:LWJGLX,项目名称:debug,代码行数:31,代码来源:Profiling.java

示例10: initSocketServer

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
public void initSocketServer() {
    server = new Server();
    ServerConnector connector = getServerConnector();
    server.addConnector(connector);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    context.addServlet(new ServletHolder(new HttpServlet() {
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                throws ServletException, IOException {
            try {
                resp.setContentType("text/html; charset=utf-8");
                resp.setStatus(HttpServletResponse.SC_OK);
                resp.getWriter().println("<div class=\"svg\" style=\"display: flex;align-items: center;justify-content: center;margin-top: 10%;\">\n"
                        + "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"100\" height=\"100\" viewBox=\"-265 235 30 30\" >\n"
                        + "    <g fill=\"white\" stroke=\"#8EC343\" stroke-width=\"3\">\n"
                        + "      <circle  cx=\"-250.5\" cy=\"249.5\" r=\"10\"/>\n"
                        + "      <path d=\"M-257 250l4 3.6 8-8\"/>\n"
                        + "    </g>\n"
                        + "  </svg>\n"
                        + "</div>");
            } catch (Exception ex) {

            }
        }
    }), "/status/*");
    server.setHandler(context);

    // Add a websocket to a specific path spec
    ServletHolder holderEvents = new ServletHolder("ws-events", EventServlet.class);
    context.addServlet(holderEvents, "/");

}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:34,代码来源:EventServer.java

示例11: setUp

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
	registry = spy(new MetricRegistry());
	client = new HttpClient();
	server = new Server();
	when(registry.getNanos()).thenAnswer(i -> now += 123456789);
	ServerConnector connector = new ServerConnector(server);
	InstrumentedHandler handler = new InstrumentedHandler(registry);
	handler.setHandler(new HelloWorldHandler());
	server.addConnector(connector);
	server.setHandler(handler);
	server.start();
	client.start();
	url = "http://localhost:" + connector.getLocalPort();
}
 
开发者ID:mevdschee,项目名称:tqdev-metrics,代码行数:16,代码来源:InstrumentedHandlerTest.java

示例12: createServer

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
private Server createServer() {
    Server server = new Server();
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(8384);
    server.addConnector(connector);

    ServletContextHandler handler = new ServletContextHandler();
    handler.setContextPath("/");
    handler.addServlet(new ServletHolder(new TestAsyncServlet()), "/");
    server.setHandler(handler);
    return server;
}
 
开发者ID:cschneider,项目名称:reactive-components,代码行数:13,代码来源:TestServlet.java

示例13: configureServerForHttp2

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
/**
 * Configure the http2 server.
 *
 * @param server the server
 * @return the server
 */
@VisibleForTesting
Server configureServerForHttp2(Server server) {
  // HTTP Configuration
  HttpConfiguration http11Config = new HttpConfiguration();
  http11Config.setSecureScheme("https");
  http11Config.setSecurePort(httpsPort);

  // SSL Context Factory for HTTPS and HTTP/2
  SslContextFactory sslContextFactory = new SslContextFactory();
  sslContextFactory.setKeyStoreResource(newClassPathResource("sample.jks"));
  sslContextFactory.setKeyStorePassword("secret");
  sslContextFactory.setKeyManagerPassword("secret");
  sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);
  sslContextFactory.setUseCipherSuitesOrder(true);

  // HTTPS Configuration
  HttpConfiguration httpsConfig = new HttpConfiguration(http11Config);
  httpsConfig.addCustomizer(new SecureRequestCustomizer());

  // HTTP/2 Connection Factory
  HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(httpsConfig);

  NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable();
  ALPNServerConnectionFactory alpnServerConnectionFactory = new ALPNServerConnectionFactory();
  alpnServerConnectionFactory.setDefaultProtocol("h2");
  alpnServerConnectionFactory.getALPNProcessor();

  // SSL Connection Factory
  SslConnectionFactory sslConnectionFactory =
      new SslConnectionFactory(sslContextFactory,
          alpnServerConnectionFactory.getProtocol());

  // HTTP/2 Connector
  ServerConnector http2Connector =
      new ServerConnector(server, sslConnectionFactory, alpnServerConnectionFactory, h2,
          new HttpConnectionFactory(httpsConfig));
  http2Connector.setPort(httpPort);
  server.addConnector(http2Connector);

  return server;
}
 
开发者ID:janweinschenker,项目名称:servlet4-demo,代码行数:48,代码来源:ApplicationConfig.java

示例14: main

import org.eclipse.jetty.server.Server; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    int timeout = (int) Duration.ONE_HOUR.getMilliseconds();

    Server server = new Server();
    SocketConnector connector = new SocketConnector();

    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(timeout);
    connector.setSoLingerTime(-1);
    connector.setPort(8080);
    server.addConnector(connector);

    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.

        connector.setConfidentialPort(8443);

        SslContextFactory factory = new SslContextFactory();
        factory.setKeyStoreResource(keystore);
        factory.setKeyStorePassword("wicket");
        factory.setTrustStoreResource(keystore);
        factory.setKeyManagerPassword("wicket");
        SslSocketConnector sslConnector = new SslSocketConnector(factory);
        sslConnector.setMaxIdleTime(timeout);
        sslConnector.setPort(8443);
        sslConnector.setAcceptors(4);
        server.addConnector(sslConnector);

        System.out.println("SSL access to the quickstart 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");

    // START JMX SERVER
    // MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    // MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer);
    // server.getContainer().addEventListener(mBeanContainer);
    // mBeanContainer.start();

    server.setHandler(bb);

    try {
        System.out.println(">>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP");
        server.start();
        System.in.read();
        System.out.println(">>> STOPPING EMBEDDED JETTY SERVER");
        server.stop();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
 
开发者ID:sparsick,项目名称:ansible-docker-talk,代码行数:65,代码来源:Start.java


注:本文中的org.eclipse.jetty.server.Server.addConnector方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。