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


Java ServerConnector.setPort方法代码示例

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


在下文中一共展示了ServerConnector.setPort方法的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: 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

示例3: PrometheusExporter

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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: createDevServer

import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
public static Server createDevServer(int port, String contextPath) {

        Server server = new Server();
        server.setStopAtShutdown(true);

        ServerConnector connector = new ServerConnector(server);
        // 设置服务端口
        connector.setPort(port);
        connector.setReuseAddress(false);
        server.setConnectors(new Connector[] {connector});

        // 设置web资源根路径以及访问web的根路径
        WebAppContext webAppCtx = new WebAppContext(DEFAULT_APP_CONTEXT_PATH, contextPath);
        webAppCtx.setDescriptor(DEFAULT_APP_CONTEXT_PATH + "/WEB-INF/web.xml");
        webAppCtx.setResourceBase(DEFAULT_APP_CONTEXT_PATH);
        webAppCtx.setClassLoader(Thread.currentThread().getContextClassLoader());
        server.setHandler(webAppCtx);

        return server;
    }
 
开发者ID:quqiangsheng,项目名称:abhot,代码行数:21,代码来源:Launcher.java

示例10: JettyHttpTestServer

import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
public JettyHttpTestServer(String host, int port){
       this.host = host;
       this.port = port;
	server = new Server();

       ServerConnector http = new ServerConnector(server);
       http.setHost(host);
       http.setPort(port);
       http.setIdleTimeout(30000);

       server.addConnector(http);
       server.setHandler(new RequestHandler());

       try {
           server.start();
       } catch (Exception e) {
           e.printStackTrace();
       }

       this.port = http.getLocalPort();
}
 
开发者ID:yahoo,项目名称:parsec-libraries,代码行数:22,代码来源:JettyHttpTestServer.java

示例11: main

import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
public static void main(String[] args) {
	Server server = new Server();
	ServerConnector connector = new ServerConnector(server);
	connector.setPort(8080);
	server.addConnector(connector);

	// Setup the basic application "context" for this application at "/"
	// This is also known as the handler tree (in jetty speak)
	ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
	context.setContextPath("/");
	server.setHandler(context);

	ServletHolder holder = new ServletHolder("socket", WebServlet.class);
	context.addServlet(holder, "/socket/*");

	try {
		server.start();
		server.dump(System.err);
		server.join();
	} catch (Throwable t) {
		t.printStackTrace(System.err);
	}
}
 
开发者ID:nashkevin,项目名称:Shape-Shmup,代码行数:24,代码来源:MainServer.java

示例12: getDashboardJettyServer

import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
/**
 * Creates the Jetty server instance for the admin Dashboard and configures it with the @Named("DashboardContext").
 * @param port where the service is available
 * @param acceptorThreads no. of acceptors
 * @param maxWorkerThreads max no. of worker threads
 * @return Jetty Server instance
 */
@Named("DashboardJettyServer")
@Provides
@Singleton
Server getDashboardJettyServer(@Named("Dashboard.service.port") int port,
		@Named("Dashboard.service.acceptors") int acceptorThreads,
		@Named("Dashboard.service.selectors") int selectorThreads,
		@Named("Dashboard.service.workers") int maxWorkerThreads,
		@Named("DashboardContext") WebAppContext webappContext) {
	QueuedThreadPool threadPool = new QueuedThreadPool();
       threadPool.setMaxThreads(maxWorkerThreads);
	Server server = new Server(threadPool);
	ServerConnector http = new ServerConnector(server, acceptorThreads, selectorThreads);
	http.setPort(port);
	server.addConnector(http);
	server.setHandler(webappContext);
	server.setStopAtShutdown(true);
	return server;
}
 
开发者ID:flipkart-incubator,项目名称:flux,代码行数:26,代码来源:ContainerModule.java

示例13: addHttpsConnector

import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
public static void addHttpsConnector(Server server, int port) throws IOException, URISyntaxException {

        String keyStoreFile = resourceAsFile("ssltest-keystore.jks").getAbsolutePath();
        SslContextFactory sslContextFactory = new SslContextFactory(keyStoreFile);
        sslContextFactory.setKeyStorePassword("changeit");

        String trustStoreFile = resourceAsFile("ssltest-cacerts.jks").getAbsolutePath();
        sslContextFactory.setTrustStorePath(trustStoreFile);
        sslContextFactory.setTrustStorePassword("changeit");

        HttpConfiguration httpsConfig = new HttpConfiguration();
        httpsConfig.setSecureScheme("https");
        httpsConfig.setSecurePort(port);
        httpsConfig.addCustomizer(new SecureRequestCustomizer());

        ServerConnector connector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(httpsConfig));
        connector.setPort(port);

        server.addConnector(connector);
    }
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:21,代码来源:TestUtils.java

示例14: start

import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
/**
 * Initialize a websocket server
 */
public static void start() {
	if(isRunning()){
		return;
	}
	server = new Server();
	connector = new ServerConnector(server);
	connector.setPort(8787);
	server.addConnector(connector);

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

	try {
		ServerContainer wscontainer = WebSocketServerContainerInitializer
				.configureContext(context);
		wscontainer.addEndpoint(WebsocketEndpoint.class);
		synchronized (server) {
			server.start();
		}
	} catch (Throwable t) {
		t.printStackTrace(System.err);
	}
}
 
开发者ID:proteus-h2020,项目名称:proteus-incremental-analytics,代码行数:29,代码来源:WebsocketServer.java

示例15: installListeners

import org.eclipse.jetty.server.ServerConnector; //导入方法依赖的package包/类
private static void installListeners(Server server, Collection<? extends InetSocketAddress> addresses) {
    final List<Connector> connectors = new ArrayList<>(addresses.size());

    for (InetSocketAddress address : addresses) {
        final ServerConnector server_connector = new ServerConnector(server);
        server_connector.setReuseAddress(true);
        if (address.getAddress() != null) {
            if (!address.getAddress().isAnyLocalAddress()) {
                LOG.log(Level.INFO, "Binding API server address: {0}", address.getAddress().getHostAddress());
                server_connector.setHost(address.getAddress().getHostAddress());
            }
        } else if (address.getHostString() != null) {
            LOG.log(Level.INFO, "Binding API server address name: {0}", address.getHostString());
            server_connector.setHost(address.getHostString());
        }
        LOG.log(Level.INFO, "Binding API server port: {0}", address.getPort());
        server_connector.setPort(address.getPort());
        connectors.add(server_connector);
    }

    server.setConnectors(connectors.toArray(new Connector[connectors.size()]));
}
 
开发者ID:groupon,项目名称:monsoon,代码行数:23,代码来源:ApiServer.java


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