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


Java SslSocketConnector类代码示例

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


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

示例1: buildSslListener

import org.eclipse.jetty.server.ssl.SslSocketConnector; //导入依赖的package包/类
/**
 * Creates a SSLListener with all the default options. The listener will use all the default options.
 * @param address - The address the listener will listen to.
 * @param port - The port the listener will listen to.
 * @return - Newly created listener
 * @throws UnknownHostException
 */
public static SslSocketConnector buildSslListener(String address, int port) throws UnknownHostException {
    int listeners = 0;
    if (_server != null) {
        listeners = _server.getConnectors().length;
    }

    SslSocketConnector ssl = new SslSocketConnector();
    ssl.setProvider(_secMan.getSecurityProvider());
    //ssl.setCipherSuites(_secMan.getSupprtedSSLCipherSuites()); Removed in Jetty 5->6 port.
    ssl.setHost(address);
    ssl.setPort(port);
    ssl.setWantClientAuth(false); // Don't care about client authentication.
    ssl.setPassword(KeyStoreProvider.DEFAULT_KEYSTORE_PASSWORD);
    ssl.setKeyPassword(KeyStoreProvider.DEFAULT_KEYSTORE_PASSWORD);
    ssl.setKeystoreType(KeyStore.getDefaultType());
    ssl.setKeystore(KeyStoreProvider.getKeyStoreLocation());
    ssl.setName("SSL Listener-" + ++listeners);

    return ssl;
}
 
开发者ID:i2p,项目名称:i2p.plugins.i2pcontrol,代码行数:28,代码来源:I2PControlController.java

示例2: startHttps

import org.eclipse.jetty.server.ssl.SslSocketConnector; //导入依赖的package包/类
/**
 * This implementation is based on http://blog.denevell.org/jetty-9-ssl-https.html
 *
 * @throws Exception
 */
private void startHttps() throws Exception {
  _server = new Server();

  SslContextFactory sslContextFactory = new SslContextFactory(_args.jks);
  sslContextFactory.setKeyStorePassword(_args.jks_pass);

  SslSocketConnector httpsConnector = new SslSocketConnector(sslContextFactory);

  if (getIp() != null) {
    httpsConnector.setHost(getIp());
  }
  httpsConnector.setPort(getPort());

  createServer(httpsConnector);
}
 
开发者ID:h2oai,项目名称:h2o-3,代码行数:21,代码来源:AbstractHTTPD.java

示例3: enableSSL

import org.eclipse.jetty.server.ssl.SslSocketConnector; //导入依赖的package包/类
/**
 * Enables SSL
 * 
 */
private void enableSSL() {
    String keyStorePath = this.getFile().getParent() + "/data/" + keystoreFile;
    try (FileInputStream keyStoreInputStream = new FileInputStream(keyStorePath)) {
        KeyStore keyStore = KeyStore.getInstance(keystoreType);
        keyStore.load(keyStoreInputStream, keystorePassword.toCharArray());
        SslContextFactory sslContextFactory = new SslContextFactory();
        sslContextFactory.setKeyStore(keyStore);
        sslContextFactory.setKeyStorePassword(keystorePassword);
        sslContextFactory.setKeyStoreType(keystoreType);
        SslSocketConnector sslConnector = new SslSocketConnector(sslContextFactory);
        sslConnector.setPort(sslPort);
        sslConnector.setMaxIdleTime(30000);
        LOG.info("Webserver now listens on SSL port {}", sslPort);
        server.addConnector(sslConnector);
    } catch (Exception ex) {
        LOG.error("Cannot load java keystore for reason: ", Freedomotic.getStackTraceInfo(ex));
    }
}
 
开发者ID:freedomotic,项目名称:freedomotic,代码行数:23,代码来源:ApplicationServer.java

示例4: findLocalHttpPort

import org.eclipse.jetty.server.ssl.SslSocketConnector; //导入依赖的package包/类
/**
 * Finds the port the specified server is listening for HTTP connections on.
 *
 * @param webServer started web server
 * @return HTTP port, or -1 if no HTTP port was found
 */
public static int findLocalHttpPort(Server webServer) {
    for (Connector connector : webServer.getConnectors()) {
        if (!(connector instanceof SslSocketConnector)) {
            return connector.getLocalPort();
        }
    }

    return -1;
}
 
开发者ID:wxyzZ,项目名称:little_mitm,代码行数:16,代码来源:TestUtils.java

示例5: findLocalHttpsPort

import org.eclipse.jetty.server.ssl.SslSocketConnector; //导入依赖的package包/类
/**
 * Finds the port the specified server is listening for HTTPS connections on.
 *
 * @param webServer started web server
 * @return HTTP port, or -1 if no HTTPS port was found
 */
public static int findLocalHttpsPort(Server webServer) {
    for (Connector connector : webServer.getConnectors()) {
        if (connector instanceof SslSocketConnector) {
            return connector.getLocalPort();
        }
    }

    return -1;
}
 
开发者ID:wxyzZ,项目名称:little_mitm,代码行数:16,代码来源:TestUtils.java

示例6: getHttpsConnectionsTotal

import org.eclipse.jetty.server.ssl.SslSocketConnector; //导入依赖的package包/类
public long getHttpsConnectionsTotal() {
    long retval = 0;
    for (Connector conn : m_server.getConnectors()) {
        if (conn instanceof SslSocketConnector) {
            retval += conn.getConnections();
        }
    }
    return retval;
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:10,代码来源:JettyServer.java

示例7: getHttpsConnectionsOpen

import org.eclipse.jetty.server.ssl.SslSocketConnector; //导入依赖的package包/类
public long getHttpsConnectionsOpen() {
    long retval = 0;
    for (Connector conn : m_server.getConnectors()) {
        if (conn instanceof SslSocketConnector) {
            retval += conn.getConnectionsOpen();
        }
    }
    return retval;
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:10,代码来源:JettyServer.java

示例8: getHttpsConnectionsOpenMax

import org.eclipse.jetty.server.ssl.SslSocketConnector; //导入依赖的package包/类
public long getHttpsConnectionsOpenMax() {
    long retval = 0;
    for (Connector conn : m_server.getConnectors()) {
        if (conn instanceof SslSocketConnector) {
            retval += conn.getConnectionsOpenMax();
        }
    }
    return retval;
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:10,代码来源:JettyServer.java

示例9: getConnector

import org.eclipse.jetty.server.ssl.SslSocketConnector; //导入依赖的package包/类
private SocketConnector getConnector() {
  if ( sslConfig != null ) {
    log.logBasic( BaseMessages.getString( PKG, "WebServer.Log.SslModeUsing" ) );
    SslSocketConnector connector = new SslSocketConnector();
    connector.setKeystore( sslConfig.getKeyStore() );
    connector.setPassword( sslConfig.getKeyStorePassword() );
    connector.setKeyPassword( sslConfig.getKeyPassword() );
    connector.setKeystoreType( sslConfig.getKeyStoreType() );
    return connector;
  } else {
    return new SocketConnector();
  }

}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:15,代码来源:WebServer.java

示例10: main

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

示例11: main

import org.eclipse.jetty.server.ssl.SslSocketConnector; //导入依赖的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(8090);
    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:acdh-oeaw,项目名称:vlo-curation,代码行数:65,代码来源:Start.java

示例12: startWebServer

import org.eclipse.jetty.server.ssl.SslSocketConnector; //导入依赖的package包/类
/**
 * Creates and starts an embedded web server on JVM-assigned HTTP and HTTPS ports.
 * Each response has a body that indicates how many bytes were received with a message like
 * "Received x bytes\n".
 *
 * @param enableHttps if true, an HTTPS connector will be added to the web server
 * @return Instance of Server
 */
public static Server startWebServer(boolean enableHttps) {
    final Server httpServer = new Server(0);

    httpServer.setHandler(new AbstractHandler() {
        public void handle(String target, Request baseRequest,
                HttpServletRequest request, HttpServletResponse response)
                throws IOException, ServletException {
            if (request.getRequestURI().contains("hang")) {
                System.out.println("Hanging as requested");
                try {
                    Thread.sleep(90000);
                } catch (InterruptedException ie) {
                    System.out.println("Stopped hanging due to interruption");
                }
            }
            
            long numberOfBytesRead = 0;
            InputStream in = new BufferedInputStream(request
                    .getInputStream());
            while (in.read() != -1) {
                numberOfBytesRead += 1;
            }
            System.out.println("Done reading # of bytes: "
                    + numberOfBytesRead);
            response.setStatus(HttpServletResponse.SC_OK);
            baseRequest.setHandled(true);
            byte[] content = ("Received " + numberOfBytesRead + " bytes\n").getBytes();
            response.addHeader("Content-Length", Integer.toString(content.length));
            response.getOutputStream().write(content);
        }
    });
    if (enableHttps) {
        // Add SSL connector
        org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory = new org.eclipse.jetty.util.ssl.SslContextFactory();

        SelfSignedSslEngineSource contextSource = new SelfSignedSslEngineSource();
        SSLContext sslContext = contextSource.getSslContext();

        sslContextFactory.setSslContext(sslContext);
        SslSocketConnector connector = new SslSocketConnector(
                sslContextFactory);
        connector.setPort(0);
        /*
         * <p>Ox: For some reason, on OS X, a non-zero timeout can causes
         * sporadic issues. <a href="http://stackoverflow.com/questions
         * /16191236/tomcat-startup-fails
         * -due-to-java-net-socketexception-invalid-argument-on-mac-o">This
         * StackOverflow thread</a> has some insights into it, but I don't
         * quite get it.</p>
         * 
         * <p>This can cause problems with Jetty's SSL handshaking, so I
         * have to set the handshake timeout and the maxIdleTime to 0 so
         * that the SSLSocket has an infinite timeout.</p>
         */
        connector.setHandshakeTimeout(0);
        connector.setMaxIdleTime(0);
        httpServer.addConnector(connector);
    }

    try {
        httpServer.start();
    } catch (Exception e) {
        throw new RuntimeException("Error starting Jetty web server", e);
    }

    return httpServer;
}
 
开发者ID:wxyzZ,项目名称:little_mitm,代码行数:76,代码来源:TestUtils.java

示例13: startWebServerWithResponse

import org.eclipse.jetty.server.ssl.SslSocketConnector; //导入依赖的package包/类
/**
 * Creates and starts an embedded web server on JVM-assigned HTTP and HTTPS ports.
 * Each response has a body that contains the specified contents.
 *
 * @param enableHttps if true, an HTTPS connector will be added to the web server
 * @param content The response the server will return
 * @return Instance of Server
 */
public static Server startWebServerWithResponse(boolean enableHttps, final byte[] content) {
    final Server httpServer = new Server(0);
    httpServer.setHandler(new AbstractHandler() {
        public void handle(String target, Request baseRequest,
                           HttpServletRequest request, HttpServletResponse response)
                throws IOException, ServletException {
            if (request.getRequestURI().contains("hang")) {
                System.out.println("Hanging as requested");
                try {
                    Thread.sleep(90000);
                } catch (InterruptedException ie) {
                    System.out.println("Stopped hanging due to interruption");
                }
            }

            long numberOfBytesRead = 0;
            InputStream in = new BufferedInputStream(request
                    .getInputStream());
            while (in.read() != -1) {
                numberOfBytesRead += 1;
            }
            System.out.println("Done reading # of bytes: "
                    + numberOfBytesRead);
            response.setStatus(HttpServletResponse.SC_OK);
            baseRequest.setHandled(true);

            response.addHeader("Content-Length", Integer.toString(content.length));
            response.getOutputStream().write(content);
        }
    });
    if (enableHttps) {
        // Add SSL connector
        org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory = new org.eclipse.jetty.util.ssl.SslContextFactory();

        SelfSignedSslEngineSource contextSource = new SelfSignedSslEngineSource();
        SSLContext sslContext = contextSource.getSslContext();

        sslContextFactory.setSslContext(sslContext);
        SslSocketConnector connector = new SslSocketConnector(
                sslContextFactory);
        connector.setPort(0);
        /*
         * <p>Ox: For some reason, on OS X, a non-zero timeout can causes
         * sporadic issues. <a href="http://stackoverflow.com/questions
         * /16191236/tomcat-startup-fails
         * -due-to-java-net-socketexception-invalid-argument-on-mac-o">This
         * StackOverflow thread</a> has some insights into it, but I don't
         * quite get it.</p>
         *
         * <p>This can cause problems with Jetty's SSL handshaking, so I
         * have to set the handshake timeout and the maxIdleTime to 0 so
         * that the SSLSocket has an infinite timeout.</p>
         */
        connector.setHandshakeTimeout(0);
        connector.setMaxIdleTime(0);
        httpServer.addConnector(connector);
    }

    try {
        httpServer.start();
    } catch (Exception e) {
        throw new RuntimeException("Error starting Jetty web server", e);
    }

    return httpServer;
}
 
开发者ID:wxyzZ,项目名称:little_mitm,代码行数:75,代码来源:TestUtils.java

示例14: buildDefaultListenter

import org.eclipse.jetty.server.ssl.SslSocketConnector; //导入依赖的package包/类
/**
 * Builds a new server. Used for changing ports during operation and such.
 * @return Server - A new server built from current configuration.
 * @throws UnknownHostException
 */
public static Connector buildDefaultListenter() throws UnknownHostException {
    SslSocketConnector ssl = buildSslListener(_conf.getConf("i2pcontrol.listen.address", "127.0.0.1"),
                             _conf.getConf("i2pcontrol.listen.port", 7650));
    return ssl;
}
 
开发者ID:i2p,项目名称:i2p.plugins.i2pcontrol,代码行数:11,代码来源:I2PControlController.java

示例15: startWebServer

import org.eclipse.jetty.server.ssl.SslSocketConnector; //导入依赖的package包/类
/**
 * Creates and starts embedded web server that is running on given port,
 * including an SSL connector on the other given port. Each response has a
 * body that indicates how many bytes were received with a message like
 * "Received x bytes\n".
 * 
 * @param port
 *            The port
 * @param sslPort
 *            (optional) The ssl port
 * @return Instance of Server
 * @throws Exception
 *             if failed to start
 */
public static Server startWebServer(final int port, final Integer sslPort)
        throws Exception {
    final Server httpServer = new Server(port);
    httpServer.setHandler(new AbstractHandler() {
        public void handle(String target, Request baseRequest,
                HttpServletRequest request, HttpServletResponse response)
                throws IOException, ServletException {
            if (request.getRequestURI().contains("hang")) {
                System.out.println("Hanging as requested");
                try {
                    Thread.sleep(90000);
                } catch (InterruptedException ie) {
                    System.out.println("Stopped hanging due to interruption");
                }
            }
            
            long numberOfBytesRead = 0;
            InputStream in = new BufferedInputStream(request
                    .getInputStream());
            while (in.read() != -1) {
                numberOfBytesRead += 1;
            }
            System.out.println("Done reading # of bytes: "
                    + numberOfBytesRead);
            response.setStatus(HttpServletResponse.SC_OK);
            baseRequest.setHandled(true);
            byte[] content = ("Received " + numberOfBytesRead + " bytes\n").getBytes();
            response.addHeader("Content-Length", Integer.toString(content.length));
            response.getOutputStream().write(content);
        }
    });
    if (sslPort != null) {
        // Add SSL connector
        org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory = new org.eclipse.jetty.util.ssl.SslContextFactory();

        SelfSignedSslEngineSource contextSource = new SelfSignedSslEngineSource();
        SSLContext sslContext = contextSource.getSslContext();

        sslContextFactory.setSslContext(sslContext);
        SslSocketConnector connector = new SslSocketConnector(
                sslContextFactory);
        connector.setPort(sslPort);
        /*
         * <p>Ox: For some reason, on OS X, a non-zero timeout can causes
         * sporadic issues. <a href="http://stackoverflow.com/questions
         * /16191236/tomcat-startup-fails
         * -due-to-java-net-socketexception-invalid-argument-on-mac-o">This
         * StackOverflow thread</a> has some insights into it, but I don't
         * quite get it.</p>
         * 
         * <p>This can cause problems with Jetty's SSL handshaking, so I
         * have to set the handshake timeout and the maxIdleTime to 0 so
         * that the SSLSocket has an infinite timeout.</p>
         */
        connector.setHandshakeTimeout(0);
        connector.setMaxIdleTime(0);
        httpServer.addConnector(connector);
    }
    httpServer.start();
    return httpServer;
}
 
开发者ID:Elitward,项目名称:LittleProxy,代码行数:76,代码来源:TestUtils.java


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