當前位置: 首頁>>代碼示例>>Java>>正文


Java HandshakeCompletedListener類代碼示例

本文整理匯總了Java中javax.net.ssl.HandshakeCompletedListener的典型用法代碼示例。如果您正苦於以下問題:Java HandshakeCompletedListener類的具體用法?Java HandshakeCompletedListener怎麽用?Java HandshakeCompletedListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HandshakeCompletedListener類屬於javax.net.ssl包,在下文中一共展示了HandshakeCompletedListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: notifyHandshakeCompletedListeners

import javax.net.ssl.HandshakeCompletedListener; //導入依賴的package包/類
final void notifyHandshakeCompletedListeners() {
    if (listeners != null && !listeners.isEmpty()) {
        // notify the listeners
        HandshakeCompletedEvent event = new HandshakeCompletedEvent(this, getActiveSession());
        for (HandshakeCompletedListener listener : listeners) {
            try {
                listener.handshakeCompleted(event);
            } catch (RuntimeException e) {
                // The RI runs the handlers in a separate thread,
                // which we do not. But we try to preserve their
                // behavior of logging a problem and not killing
                // the handshaking thread just because a listener
                // has a problem.
                Thread thread = Thread.currentThread();
                thread.getUncaughtExceptionHandler().uncaughtException(thread, e);
            }
        }
    }
}
 
開發者ID:google,項目名稱:conscrypt,代碼行數:20,代碼來源:ConscryptSocketBase.java

示例2: HTTPConnection

import javax.net.ssl.HandshakeCompletedListener; //導入依賴的package包/類
/**
 * Creates a new HTTP or HTTPS connection on the specified port.
 * @param hostname the name of the host to connect to
 * @param port the port on the host to connect to
 * @param secure whether to use a secure connection
 * @param connectionTimeout the connection timeout
 * @param timeout the socket read timeout
 *
 * @throws IllegalArgumentException if either connectionTimeout or
 * timeout less than zero.
 */
public HTTPConnection(String hostname, int port, boolean secure,
                      int connectionTimeout, int timeout)
{
  if (connectionTimeout < 0 || timeout < 0)
    throw new IllegalArgumentException();

  this.hostname = hostname;
  this.port = port;
  this.secure = secure;
  this.connectionTimeout = connectionTimeout;
  this.timeout = timeout;
  majorVersion = minorVersion = 1;
  handshakeCompletedListeners
    = new ArrayList<HandshakeCompletedListener>(2);
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:27,代碼來源:HTTPConnection.java

示例3: HTTPConnection

import javax.net.ssl.HandshakeCompletedListener; //導入依賴的package包/類
/**
 * Creates a new HTTP or HTTPS connection on the specified port.
 * @param hostname the name of the host to connect to
 * @param port the port on the host to connect to
 * @param secure whether to use a secure connection
 * @param connectionTimeout the connection timeout
 * @param timeout the socket read timeout
 *
 * @throws IllegalArgumentException if either connectionTimeout or
 * timeout less than zero.
 */
public HTTPConnection(String hostname, int port, boolean secure,
                      int connectionTimeout, int timeout)
{
  if (connectionTimeout < 0 || timeout < 0)
    throw new IllegalArgumentException();
  
  this.hostname = hostname;
  this.port = port;
  this.secure = secure;
  this.connectionTimeout = connectionTimeout;
  this.timeout = timeout;
  majorVersion = minorVersion = 1;
  handshakeCompletedListeners
    = new ArrayList<HandshakeCompletedListener>(2);
}
 
開發者ID:nmldiegues,項目名稱:jvm-stm,代碼行數:27,代碼來源:HTTPConnection.java

示例4: connect

import javax.net.ssl.HandshakeCompletedListener; //導入依賴的package包/類
@Override
public void connect(SocketAddress endpoint, int timeout) throws IOException {
    Date start = new Date();
    socket.connect(endpoint, timeout);
    Date end = new Date();
    RequestInfo.get().connect(start, end);
    handshakeStart = new Date();
    startHandshake();
    this.addHandshakeCompletedListener(new HandshakeCompletedListener() {
        @Override
        public void handshakeCompleted(HandshakeCompletedEvent handshakeCompletedEvent) {
            if (handshakeStart != null) {
                RequestInfo.get().ssl(handshakeStart, new Date());
            }
        }
    });
}
 
開發者ID:epam,項目名稱:Wilma,代碼行數:18,代碼來源:SimulatedSSLSocket.java

示例5: removeHandshakeCompletedListener

import javax.net.ssl.HandshakeCompletedListener; //導入依賴的package包/類
/**
 * This method works according to the specification of implemented class.
 * @see javax.net.ssl.SSLSocket#removeHandshakeCompletedListener(HandshakeCompletedListener)
 * method documentation for more information
 */
@Override
public void removeHandshakeCompletedListener(
        HandshakeCompletedListener listener) {
    if (listener == null) {
        throw new IllegalArgumentException("Provided listener is null");
    }
    if (listeners == null) {
        throw new IllegalArgumentException(
                "Provided listener is not registered");
    }
    if (!listeners.remove(listener)) {
        throw new IllegalArgumentException(
                "Provided listener is not registered");
    }
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:21,代碼來源:SSLSocketImpl.java

示例6: notifyHandshakeCompletedListeners

import javax.net.ssl.HandshakeCompletedListener; //導入依賴的package包/類
private void notifyHandshakeCompletedListeners() {
    if (listeners != null && !listeners.isEmpty()) {
        // notify the listeners
        HandshakeCompletedEvent event =
            new HandshakeCompletedEvent(this, sslSession);
        for (HandshakeCompletedListener listener : listeners) {
            try {
                listener.handshakeCompleted(event);
            } catch (RuntimeException e) {
                // The RI runs the handlers in a separate thread,
                // which we do not. But we try to preserve their
                // behavior of logging a problem and not killing
                // the handshaking thread just because a listener
                // has a problem.
                Thread thread = Thread.currentThread();
                thread.getUncaughtExceptionHandler().uncaughtException(thread, e);
            }
        }
    }
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:21,代碼來源:OpenSSLSocketImpl.java

示例7: removeHandshakeCompletedListener

import javax.net.ssl.HandshakeCompletedListener; //導入依賴的package包/類
/**
 * The method removes a registered listener.
 * @throws IllegalArgumentException if listener is null or not registered
 */
@Override
public void removeHandshakeCompletedListener(
        HandshakeCompletedListener listener) {
    if (listener == null) {
        throw new IllegalArgumentException("Provided listener is null");
    }
    if (listeners == null) {
        throw new IllegalArgumentException(
                "Provided listener is not registered");
    }
    if (!listeners.remove(listener)) {
        throw new IllegalArgumentException(
                "Provided listener is not registered");
    }
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:20,代碼來源:OpenSSLSocketImpl.java

示例8: configure

import javax.net.ssl.HandshakeCompletedListener; //導入依賴的package包/類
/**
 * @param socket    Socket to configure
 * @param protocols Enabled SSL protocol versions
 */
protected void configure(final Socket socket, final String[] protocols) throws IOException {
    if(socket instanceof SSLSocket) {
        try {
            if(log.isDebugEnabled()) {
                log.debug(String.format("Configure SSL parameters with protocols %s", Arrays.toString(protocols)));
            }
            ((SSLSocket) socket).setEnabledProtocols(protocols);
            final List<String> ciphers = Arrays.asList(((SSLSocket) socket).getEnabledCipherSuites());
            final List<String> blacklist = preferences.getList("connection.ssl.cipher.blacklist");
            if(!blacklist.isEmpty()) {
                ciphers.removeIf(blacklist::contains);
            }
            ((SSLSocket) socket).setEnabledCipherSuites(ciphers.toArray(new String[ciphers.size()]));
            if(log.isInfoEnabled()) {
                log.info(String.format("Enabled cipher suites %s",
                        Arrays.toString(((SSLSocket) socket).getEnabledCipherSuites())));
                ((SSLSocket) socket).addHandshakeCompletedListener(new HandshakeCompletedListener() {
                    @Override
                    public void handshakeCompleted(final HandshakeCompletedEvent event) {
                        log.info(String.format("Completed handshake with %s and negotiated cipher suite %s",
                                event.getSession().getProtocol(), event.getCipherSuite()));
                        ((SSLSocket) socket).removeHandshakeCompletedListener(this);
                    }
                });
            }
        }
        catch(Exception e) {
            log.warn(String.format("Failed to configure SSL parameters %s", e.getMessage()));
        }
    }
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:36,代碼來源:CustomTrustSSLProtocolSocketFactory.java

示例9: createSSLSocket

import javax.net.ssl.HandshakeCompletedListener; //導入依賴的package包/類
/**
 * Create an SSL client socket using the IOR-encoded
 * security characteristics.
 * Setting want/need client auth on a client socket has no effect so all we can do is use the right host, port, ciphers
 *
 * @param host     The target host name.
 * @param port     The target connection port.
 *
 * @return An appropriately configured client SSLSocket.
 * @exception IOException if ssl socket can't be obtained and configured.
 */
private Socket createSSLSocket(String host, int port, int requires, int supports) throws IOException {
    SSLSocketFactory factory = getSocketFactory();
    SSLSocket socket = (SSLSocket) factory.createSocket(host, port);

    socket.setSoTimeout(SOCKET_TIMEOUT_MS);

    // get a set of cipher suites appropriate for this connections requirements.
    // We request this for each connection, since the outgoing IOR's requirements may be different from
    // our server listener requirements.
    String[] iorSuites = SSLCipherSuiteDatabase.getCipherSuites(requires, supports, factory.getSupportedCipherSuites());
    socket.setEnabledCipherSuites(iorSuites);
    if (log.isDebugEnabled()) {
        log.debug("Created SSL socket to " + host + ":" + port);
        log.debug("    cipher suites:");

        for (int i = 0; i < iorSuites.length; i++) {
            log.debug("    " + iorSuites[i]);
        }
        socket.addHandshakeCompletedListener(new HandshakeCompletedListener() {

            public void handshakeCompleted(HandshakeCompletedEvent handshakeCompletedEvent) {
                Certificate[] certs = handshakeCompletedEvent.getLocalCertificates();
                if (certs != null) {
                    log.debug("handshake returned local certs count: " + certs.length);
                    for (int i = 0; i < certs.length; i++) {
                        Certificate cert = certs[i];
                        log.debug("cert: " + cert.toString());
                    }
                } else {
                    log.debug("handshake returned no local certs");
                }
            }
        });
    }
    return socket;
}
 
開發者ID:RuiChen08,項目名稱:dacapobench,代碼行數:48,代碼來源:SocketFactory.java

示例10: removeHandshakeCompletedListener

import javax.net.ssl.HandshakeCompletedListener; //導入依賴的package包/類
@Override
public void removeHandshakeCompletedListener(HandshakeCompletedListener listener) {
    checkArgument(listener != null, "Provided listener is null");
    if (!listeners.remove(listener)) {
        throw new IllegalArgumentException("Provided listener is not registered");
    }
}
 
開發者ID:google,項目名稱:conscrypt,代碼行數:8,代碼來源:ConscryptSocketBase.java

示例11: test_SSLSocket_HandshakeCompletedListener_RuntimeException

import javax.net.ssl.HandshakeCompletedListener; //導入依賴的package包/類
@Test
public void test_SSLSocket_HandshakeCompletedListener_RuntimeException() throws Exception {
    final Thread self = Thread.currentThread();
    final UncaughtExceptionHandler original = self.getUncaughtExceptionHandler();
    final RuntimeException expectedException = new RuntimeException("expected");
    final TestUncaughtExceptionHandler test = new TestUncaughtExceptionHandler();
    self.setUncaughtExceptionHandler(test);
    final TestSSLContext c = TestSSLContext.create();
    final SSLSocket client =
            (SSLSocket) c.clientContext.getSocketFactory().createSocket(c.host, c.port);
    final SSLSocket server = (SSLSocket) c.serverSocket.accept();
    Future<Void> future = runAsync(new Callable<Void>() {
        @Override
        public Void call() throws Exception {
            server.startHandshake();
            return null;
        }
    });
    client.addHandshakeCompletedListener(new HandshakeCompletedListener() {
        @Override
        public void handshakeCompleted(HandshakeCompletedEvent event) {
            throw expectedException;
        }
    });
    client.startHandshake();
    future.get();
    client.close();
    server.close();
    c.close();
    assertSame(expectedException, test.actualException);
    self.setUncaughtExceptionHandler(original);
}
 
開發者ID:google,項目名稱:conscrypt,代碼行數:33,代碼來源:SSLSocketTest.java

示例12: addHandshakeCompletedListener

import javax.net.ssl.HandshakeCompletedListener; //導入依賴的package包/類
void addHandshakeCompletedListener(HandshakeCompletedListener l)
{
  synchronized (handshakeCompletedListeners)
    {
      handshakeCompletedListeners.add(l);
    }
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:8,代碼來源:HTTPConnection.java

示例13: removeHandshakeCompletedListener

import javax.net.ssl.HandshakeCompletedListener; //導入依賴的package包/類
void removeHandshakeCompletedListener(HandshakeCompletedListener l)
{
  synchronized (handshakeCompletedListeners)
    {
      handshakeCompletedListeners.remove(l);
    }
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:8,代碼來源:HTTPConnection.java

示例14: SSLSocketImpl

import javax.net.ssl.HandshakeCompletedListener; //導入依賴的package包/類
public SSLSocketImpl(SSLContextImpl contextImpl, String host, int port,
                     Socket underlyingSocket, boolean autoClose)
{
  engine = new SSLEngineImpl(contextImpl, host, port);
  engine.setUseClientMode(true); // default to client mode
  listeners = new HashSet<HandshakeCompletedListener>();
  this.underlyingSocket = underlyingSocket;
  this.autoClose = autoClose;
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:10,代碼來源:SSLSocketImpl.java

示例15: CustomSslSocketFactory

import javax.net.ssl.HandshakeCompletedListener; //導入依賴的package包/類
/**
 * Constructor
 *
 * @param sslSocketFactory The actual SSLSocketFactory (used by this class)
 * @param handshakeListener The class that handles "handshake completed" events
 */
public CustomSslSocketFactory(SSLSocketFactory sslSocketFactory, HandshakeCompletedListener handshakeListener,
		boolean sniEnabled) {
	this.sslSocketFactory = sslSocketFactory;
	this.handshakeListener = handshakeListener;
	this.sniEnabled = sniEnabled;
}
 
開發者ID:kaikramer,項目名稱:keystore-explorer,代碼行數:13,代碼來源:CustomSslSocketFactory.java


注:本文中的javax.net.ssl.HandshakeCompletedListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。