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


Java Connector类代码示例

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


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

示例1: reverseProxy

import org.eclipse.jetty.server.Connector; //导入依赖的package包/类
private static void reverseProxy() throws Exception{
  Server server = new Server();

  SocketConnector connector = new SocketConnector();
  connector.setHost("127.0.0.1");
  connector.setPort(8888);

  server.setConnectors(new Connector[]{connector});

  // Setup proxy handler to handle CONNECT methods
  ConnectHandler proxy = new ConnectHandler();
  server.setHandler(proxy);

  // Setup proxy servlet
  ServletContextHandler context = new ServletContextHandler(proxy, "/", ServletContextHandler.SESSIONS);
  ServletHolder proxyServlet = new ServletHolder(ProxyServlet.Transparent.class);
  proxyServlet.setInitParameter("ProxyTo", "https://localhost:54321/");
  proxyServlet.setInitParameter("Prefix", "/");
  context.addServlet(proxyServlet, "/*");

  server.start();
}
 
开发者ID:tomkraljevic,项目名称:jetty-embed-reverse-proxy-example,代码行数:23,代码来源:ProxyServer.java

示例2: start

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

import org.eclipse.jetty.server.Connector; //导入依赖的package包/类
public void afterPropertiesSet() throws Exception {
    Resource configXml = Resource.newSystemResource(config);
    XmlConfiguration configuration = new XmlConfiguration(configXml.getInputStream());
    server = (Server) configuration.configure();
    Integer port = getPort();
    if (port != null && port > 0) {
        Connector[] connectors = server.getConnectors();
        for (Connector connector : connectors) {
            connector.setPort(port);
        }
    }

    Handler handler = server.getHandler();
    if (handler != null && handler instanceof ServletContextHandler) {
        ServletContextHandler servletHandler = (ServletContextHandler) handler;
        servletHandler.getInitParams().put("org.eclipse.jetty.servlet.Default.resourceBase", htdocsDir);
    }

    server.start();
    if (logger.isInfoEnabled()) {
        logger.info("##Jetty Embed Server is startup!");
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:24,代码来源:JettyEmbedServer.java

示例4: main

import org.eclipse.jetty.server.Connector; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
    Resource jetty_xml = Resource.newSystemResource("jetty/jetty.xml");
    XmlConfiguration configuration = new XmlConfiguration(jetty_xml.getInputStream());
    Server server = (Server) configuration.configure();
    int port = 8081;
    Connector[] connectors = server.getConnectors();
    for (Connector connector : connectors) {
        connector.setPort(port);
    }

    Handler handler = server.getHandler();
    if (handler != null && handler instanceof ServletContextHandler) {
        ServletContextHandler servletHandler = (ServletContextHandler) handler;
        servletHandler.getInitParams().put("org.eclipse.jetty.servlet.Default.resourceBase", "/tmp/");
    }

    server.start();
    server.join();
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:20,代码来源:JettyEmbedIntegration.java

示例5: run

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

示例6: prepare

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

示例7: RestServer

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

示例8: createDevServer

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

示例9: installListeners

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

示例10: lifeCycleStarted

import org.eclipse.jetty.server.Connector; //导入依赖的package包/类
@Override
public void lifeCycleStarted(LifeCycle bean) {
  if (bean instanceof Server) {
    Server server = (Server)bean;
    Connector[] connectors = server.getConnectors();
    if (connectors == null || connectors.length == 0) {
      server.dumpStdErr();
      throw new IllegalStateException("No Connector");
    } else if (!Arrays.stream(connectors).allMatch(Connector::isStarted)) {
      server.dumpStdErr();
      throw new IllegalStateException("Connector not started");
    }
    ContextHandler context = server.getChildHandlerByClass(ContextHandler.class);
    if (context == null || !context.isAvailable()) {
      server.dumpStdErr();
      throw new IllegalStateException("No Available Context");
    }
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:jetty-runtime,代码行数:20,代码来源:DeploymentCheck.java

示例11: getEmbeddedServletContainer

import org.eclipse.jetty.server.Connector; //导入依赖的package包/类
@Override
public EmbeddedServletContainer getEmbeddedServletContainer(
		ServletContextInitializer... initializers) {
	JettyEmbeddedWebAppContext context = new JettyEmbeddedWebAppContext();
	int port = (getPort() >= 0 ? getPort() : 0);
	InetSocketAddress address = new InetSocketAddress(getAddress(), port);
	Server server = createServer(address);
	configureWebAppContext(context, initializers);
	server.setHandler(addHandlerWrappers(context));
	this.logger.info("Server initialized with port: " + port);
	if (getSsl() != null && getSsl().isEnabled()) {
		SslContextFactory sslContextFactory = new SslContextFactory();
		configureSsl(sslContextFactory, getSsl());
		AbstractConnector connector = getSslServerConnectorFactory()
				.getConnector(server, sslContextFactory, port);
		server.setConnectors(new Connector[] { connector });
	}
	for (JettyServerCustomizer customizer : getServerCustomizers()) {
		customizer.customize(server);
	}
	if (this.useForwardHeaders) {
		new ForwardHeadersCustomizer().customize(server);
	}
	return getJettyEmbeddedServletContainer(server);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:26,代码来源:JettyEmbeddedServletContainerFactory.java

示例12: removeFromServer

import org.eclipse.jetty.server.Connector; //导入依赖的package包/类
public void removeFromServer(Server server) {
    for (Connector connector : server.getConnectors()) {
        if (connector instanceof NetworkTrafficServerConnector) {
            NetworkTrafficServerConnector serverConnector = (NetworkTrafficServerConnector)connector;
            if (serverConnector.getPort() == port && serverConnector.getHost().equals(host)) {
                server.removeConnector(serverConnector);
                if (server.isStarted()) {
                    try {
                        serverConnector.stop();
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }
    }
}
 
开发者ID:factoryfx,项目名称:factoryfx,代码行数:18,代码来源:HttpServerConnectorCreator.java

示例13: createServerInSource

import org.eclipse.jetty.server.Connector; //导入依赖的package包/类
/**
 * 创建用于开发运行调试的Jetty Server, 以src/main/webapp为Web应用目录.
 */
public static Server createServerInSource(int port, String contextPath) {
	Server server = new Server();
	// 设置在JVM退出时关闭Jetty的钩子。
	server.setStopAtShutdown(true);

	SelectChannelConnector connector = new SelectChannelConnector();
	connector.setPort(port);
	// 解决Windows下重复启动Jetty居然不报告端口冲突的问题.
	connector.setReuseAddress(false);
	server.setConnectors(new Connector[] { connector });

	WebAppContext webContext = new WebAppContext(DEFAULT_WEBAPP_PATH, contextPath);
	// 修改webdefault.xml,解决Windows下Jetty Lock住静态文件的问题.
	webContext.setDefaultsDescriptor(WINDOWS_WEBDEFAULT_PATH);
	server.setHandler(webContext);

	return server;
}
 
开发者ID:pengqiuyuan,项目名称:g2,代码行数:22,代码来源:JettyFactory.java

示例14: start

import org.eclipse.jetty.server.Connector; //导入依赖的package包/类
/**
 * Creates and starts the server with the current state (credentials, port). After startup, the method will return
 * and not block.
 *
 * @throws IllegalStateException if the server has already been started
 * @throws Exception             if creation of the server fails
 */
public void start() throws Exception {
    if (jettyServer != null) {
        throw new IllegalStateException("Server already started");
    }

    jettyServer = new Server(0);

    connector = new ServerConnector(jettyServer); // NOSONAR
    connector.setPort(getPort());
    jettyServer.setConnectors(new Connector[]{connector});

    HttpManagerBuilder builder = new HttpManagerBuilder();
    builder.setResourceFactory(new MiltonWebDAVResourceFactory(this.rootFolder, userCredentials));
    builder.setEnableBasicAuth(userCredentials != null && !userCredentials.isEmpty());
    HttpManager mgr = builder.buildHttpManager();

    jettyServer.setHandler(new MiltonHandler(mgr));

    jettyServer.start();

    while (!jettyServer.isStarted()) {
        Thread.sleep(50);
    }
}
 
开发者ID:TheMagican,项目名称:webdav-embedded-server,代码行数:32,代码来源:MiltonWebDAVFileServer.java

示例15: testHttpConnectorsHttpsOnly

import org.eclipse.jetty.server.Connector; //导入依赖的package包/类
@Test
public void testHttpConnectorsHttpsOnly() {
    
    System.setProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_PATH, "file:///tmp/keystore");
    System.setProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_TYPE, "PKCS12");
    System.setProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_PASSWORD, "pass123");
    System.setProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_PATH, "file:///tmp/truststore");
    System.setProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_TYPE, "PKCS12");
    System.setProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_PASSWORD, "pass123");
    System.setProperty(AthenzConsts.ATHENZ_PROP_KEYMANAGER_PASSWORD, "pass123");
    System.setProperty(AthenzConsts.ATHENZ_PROP_IDLE_TIMEOUT, "10001");
    
    AthenzJettyContainer container = new AthenzJettyContainer();
    container.createServer(100);
    
    HttpConfiguration httpConfig = container.newHttpConfiguration();
    container.addHTTPConnectors(httpConfig, 0, 8082, 0);
    
    Server server = container.getServer();
    Connector[] connectors = server.getConnectors();
    assertEquals(connectors.length, 1);
    
    assertTrue(connectors[0].getProtocols().contains("http/1.1"));
    assertTrue(connectors[0].getProtocols().contains("ssl"));
}
 
开发者ID:yahoo,项目名称:athenz,代码行数:26,代码来源:AthenzJettyContainerTest.java


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