當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。