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


Java ServerConnector类代码示例

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


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

示例1: JettyAdminServer

import org.eclipse.jetty.server.ServerConnector; //导入依赖的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.ServerConnector; //导入依赖的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: beforeClass

import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() throws Exception {
    jettyServer = new Server(0);

    WebAppContext webApp = new WebAppContext();
    webApp.setServer(jettyServer);
    webApp.setContextPath(CONTEXT_PATH);
    webApp.setWar("src/test/webapp");

    jettyServer.setHandler(webApp);
    jettyServer.start();
    serverPort = ((ServerConnector)jettyServer.getConnectors()[0]).getLocalPort();

    testRestTemplate = new TestRestTemplate(new RestTemplateBuilder()
            .rootUri("http://localhost:" + serverPort + CONTEXT_PATH));
}
 
开发者ID:opentracing-contrib,项目名称:java-spring-web,代码行数:17,代码来源:MVCJettyITest.java

示例4: customize

import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
@Override
public void customize(Server server) {
    // HTTPS Configuration
    HttpConfiguration httpsConfig = new HttpConfiguration();
    httpsConfig.setSecureScheme("https");
    httpsConfig.setSecurePort(8443);
    httpsConfig.addCustomizer(new SecureRequestCustomizer());

    // SSL Context Factory for HTTPS and HTTP/2
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStoreResource(newClassPathResource("keystore"));
    sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
    sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
    sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);

    // SSL Connection Factory
    SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, "h2");

    // HTTP/2 Connector
    ServerConnector http2Connector = new ServerConnector(server, ssl, new HTTP2ServerConnectionFactory(httpsConfig));
    http2Connector.setPort(8443);
    server.addConnector(http2Connector);
}
 
开发者ID:thinline72,项目名称:rpc-example,代码行数:24,代码来源:JettyHttp2ServerConfig.java

示例5: start

import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
public void start(int listenPort, String dbname) throws Exception {
    if (Objects.nonNull(server) && server.isRunning()) {
        LOG.info("ineternal webui already running at port [" + listenPort + "].");
        throw new Exception("already running at port[" + listenPort + "]");
    }
    // remove old connectors
    Connector[] oldConnectors = server.getConnectors();
    if (Objects.nonNull(oldConnectors)) {
        for (Connector oldc : oldConnectors) {
            server.removeConnector(oldc);
        }
    }
    // add new connector
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(listenPort);
    server.setConnectors(new Connector[] { connector });
    // set dbname
    ServletContextHandler contextHandler = (ServletContextHandler) server.getHandler();
    contextHandler.setAttribute("dbname", dbname);
    server.start();
    LOG.info("internal webui server started with listening port [" + listenPort + "].");
}
 
开发者ID:SecureSkyTechnology,项目名称:burpextender-proxyhistory-webui,代码行数:23,代码来源:WebUIApp.java

示例6: startJetty

import org.eclipse.jetty.server.ServerConnector; //导入依赖的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

示例7: LegacyHttpServer

import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
private LegacyHttpServer(int port, int threads) {
  this.server = new Server(new QueuedThreadPool(threads));
  server.setHandler(
      new AbstractHandler() {
        @Override
        public void handle(
            String target,
            Request baseRequest,
            HttpServletRequest request,
            HttpServletResponse response)
            throws IOException {
          final String method = baseRequest.getParameter("method");
          if ("helloworld.Greeter/SayHello".equals(method)) {
            baseRequest.setHandled(true);
            sayHello(baseRequest, response);
          }
        }
      });

  final ServerConnector connector = new ServerConnector(server);
  connector.setPort(port);
  server.addConnector(connector);
}
 
开发者ID:codahale,项目名称:grpc-proxy,代码行数:24,代码来源:LegacyHttpServer.java

示例8: setUp

import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
  System.out.println("Jetty [Configuring]");

  ServletContextHandler servletContext = new ServletContextHandler();
  servletContext.setContextPath("/");
  servletContext.addServlet(PingPongServlet.class, PingPongServlet.PATH);
  servletContext.addServlet(ExceptionServlet.class, ExceptionServlet.PATH);
  ServletHolder servletHolder = servletContext.addServlet(AsyncServlet.class, AsyncServlet.PATH);
  servletHolder.setAsyncSupported(true);

  jetty = new Server(0);
  jetty.setHandler(servletContext);
  System.out.println("Jetty [Starting]");
  jetty.start();
  System.out.println("Jetty [Started]");
  serverPort = ((ServerConnector) jetty.getConnectors()[0]).getLocalPort();
}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:19,代码来源:JettyFilterInstrumentationTest.java

示例9: attachServerConnector

import org.eclipse.jetty.server.ServerConnector; //导入依赖的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

示例10: extractTableRowForDefaultServer

import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
private static List<ApplicationUrlsGenerator> extractTableRowForDefaultServer(Environment environment, ServerConnector connector) {
    String protocol = connector.getDefaultProtocol();
    int port = connector.getLocalPort();

    if ("admin".equals(connector.getName())) {
        String adminContextPath = environment.getAdminContext().getContextPath();

        return ImmutableList.of(
            new ApplicationUrlsGenerator(ADMIN_URL_TYPE, isHttps(protocol), port, adminContextPath),
            new ApplicationUrlsGenerator(HEALTHCHECK_URL_TYPE, isHttps(protocol), port, adminContextPath)
        );
    }

    return ImmutableList.of(
        new ApplicationUrlsGenerator(APPLICATION_URL_TYPE, isHttps(protocol), port, environment.getApplicationContext().getContextPath())
    );
}
 
开发者ID:alphagov,项目名称:verify-service-provider,代码行数:18,代码来源:UsefulApplicationUrlsTableFormatter.java

示例11: extractRowsForSimpleServer

import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
private static List<ApplicationUrlsGenerator> extractRowsForSimpleServer(Environment environment, ServerConnector connector) {
    return ImmutableList.of(
        new ApplicationUrlsGenerator(
            APPLICATION_URL_TYPE,
            isHttps(connector.getDefaultProtocol()),
            connector.getLocalPort(),
            environment.getApplicationContext().getContextPath()
        ),
        new ApplicationUrlsGenerator(
            ADMIN_URL_TYPE,
            isHttps(connector.getDefaultProtocol()),
            connector.getLocalPort(),
            environment.getAdminContext().getContextPath()
        ),
        new ApplicationUrlsGenerator(
            HEALTHCHECK_URL_TYPE,
            isHttps(connector.getDefaultProtocol()),
            connector.getLocalPort(),
            environment.getAdminContext().getContextPath()
        )
    );
}
 
开发者ID:alphagov,项目名称:verify-service-provider,代码行数:23,代码来源:UsefulApplicationUrlsTableFormatter.java

示例12: run

import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
public void run(final int port) {
    try {
        final Server server = createServer();

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

        for (final MinijaxApplication application : applications) {
            addApplication(context, application);
        }

        final ServerConnector connector = createConnector(server);
        connector.setPort(port);
        server.setConnectors(new Connector[] { connector });
        server.start();
        server.join();

    } catch (final Exception ex) {
        throw new MinijaxException(ex);
    }
}
 
开发者ID:minijax,项目名称:minijax,代码行数:23,代码来源:Minijax.java

示例13: createConnector

import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
/**
 * Creates a server connector.
 *
 * If an HTTPS key store is configured, returns a SSL connector for HTTPS.
 *
 * Otherwise, returns a normal HTTP connector by default.
 *
 * @param server The server.
 * @return The server connector.
 */
@SuppressWarnings("squid:S2095")
private ServerConnector createConnector(final Server server) {
    final String keyStorePath = (String) configuration.get(MinijaxProperties.SSL_KEY_STORE_PATH);

    if (keyStorePath == null || keyStorePath.isEmpty()) {
        // Normal HTTP
        return new ServerConnector(server);
    }

    final String keyStorePassword = (String) configuration.get(MinijaxProperties.SSL_KEY_STORE_PASSWORD);
    final String keyManagerPassword = (String) configuration.get(MinijaxProperties.SSL_KEY_MANAGER_PASSWORD);

    final HttpConfiguration https = new HttpConfiguration();
    https.addCustomizer(new SecureRequestCustomizer());

    final SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(Minijax.class.getClassLoader().getResource(keyStorePath).toExternalForm());
    sslContextFactory.setKeyStorePassword(keyStorePassword);
    sslContextFactory.setKeyManagerPassword(keyManagerPassword);

    return new ServerConnector(server,
            new SslConnectionFactory(sslContextFactory, "http/1.1"),
            new HttpConnectionFactory(https));
}
 
开发者ID:minijax,项目名称:minijax,代码行数:35,代码来源:Minijax.java

示例14: prepare

import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
public void prepare() {
    try {
        Tools.verifyLocalPort("DBServer ", port());
        server = new Server();
        DefaultHandler webHandler = new DefaultHandler();
        HandlerList handlers = new HandlerList();
        handlers.setHandlers(new Handler[]{getResourceHandler(),
            getUIWSHandler(), webHandler});

        ServerConnector connector = new ServerConnector(server);
        connector.setPort(port());
        server.setConnectors(new Connector[]{connector});
        server.setHandler(handlers);

        LOG.log(Level.INFO, "DB Server on : http://{0}:{1}",
                new Object[]{Tools.IP(), port() + ""});

    } catch (Exception ex) {
        LOG.log(Level.SEVERE, ex.getMessage(), ex);
    }
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:22,代码来源:DashBoardServer.java

示例15: RestServer

import org.eclipse.jetty.server.ServerConnector; //导入依赖的package包/类
/**
 * Create a REST server for this herder using the specified configs.
 */
public RestServer(WorkerConfig config) {
    this.config = config;

    // To make the advertised port available immediately, we need to do some configuration here
    String hostname = config.getString(WorkerConfig.REST_HOST_NAME_CONFIG);
    Integer port = config.getInt(WorkerConfig.REST_PORT_CONFIG);

    jettyServer = new Server();

    ServerConnector connector = new ServerConnector(jettyServer);
    if (hostname != null && !hostname.isEmpty())
        connector.setHost(hostname);
    connector.setPort(port);
    jettyServer.setConnectors(new Connector[]{connector});
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:19,代码来源:RestServer.java


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