本文整理汇总了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);
}
}
}
}
示例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);
}
示例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);
}
示例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());
}
}
});
}
示例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");
}
}
示例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);
}
}
}
}
示例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");
}
}
示例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()));
}
}
}
示例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;
}
示例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");
}
}
示例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);
}
示例12: addHandshakeCompletedListener
import javax.net.ssl.HandshakeCompletedListener; //导入依赖的package包/类
void addHandshakeCompletedListener(HandshakeCompletedListener l)
{
synchronized (handshakeCompletedListeners)
{
handshakeCompletedListeners.add(l);
}
}
示例13: removeHandshakeCompletedListener
import javax.net.ssl.HandshakeCompletedListener; //导入依赖的package包/类
void removeHandshakeCompletedListener(HandshakeCompletedListener l)
{
synchronized (handshakeCompletedListeners)
{
handshakeCompletedListeners.remove(l);
}
}
示例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;
}
示例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;
}