8253635: Implement toString() for SSLEngineImpl

Reviewed-by: coffeys, wetmore
This commit is contained in:
Xue-Lei Andrew Fan 2021-01-13 01:10:29 +00:00
parent c6d798c25a
commit 65bed6470c
2 changed files with 30 additions and 24 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -1089,6 +1089,15 @@ final class SSLEngineImpl extends SSLEngine implements SSLTransport {
return true;
}
@Override
public String toString() {
return "SSLEngine[" +
"hostname=" + getPeerHost() +
", port=" + getPeerPort() +
", " + conContext.conSession + // SSLSessionImpl.toString()
"]";
}
/*
* Depending on whether the error was just a warning and the
* handshaker wasn't closed, or fatal and the handshaker is now

View file

@ -35,7 +35,6 @@ import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.concurrent.TimeUnit;
@ -135,7 +134,7 @@ public final class SSLSocketImpl
* if appropriate.
*/
SSLSocketImpl(SSLContextImpl sslContext, String peerHost,
int peerPort) throws IOException, UnknownHostException {
int peerPort) throws IOException {
super();
this.sslContext = sslContext;
HandshakeHash handshakeHash = new HandshakeHash();
@ -179,7 +178,7 @@ public final class SSLSocketImpl
*/
SSLSocketImpl(SSLContextImpl sslContext,
String peerHost, int peerPort, InetAddress localAddr,
int localPort) throws IOException, UnknownHostException {
int localPort) throws IOException {
super();
this.sslContext = sslContext;
HandshakeHash handshakeHash = new HandshakeHash();
@ -1406,11 +1405,9 @@ public final class SSLSocketImpl
conContext.isNegotiated) {
return 0;
}
} catch (SSLException ssle) {
throw ssle;
} catch (InterruptedIOException iioe) {
} catch (SSLException | InterruptedIOException ssle) {
// don't change exception in case of timeouts or interrupts
throw iioe;
throw ssle;
} catch (IOException ioe) {
throw new SSLException("readHandshakeRecord", ioe);
}
@ -1471,17 +1468,11 @@ public final class SSLSocketImpl
buffer.position() > 0) {
return buffer;
}
} catch (SSLException ssle) {
throw ssle;
} catch (InterruptedIOException iioe) {
} catch (SSLException | InterruptedIOException ssle) {
// don't change exception in case of timeouts or interrupts
throw iioe;
throw ssle;
} catch (IOException ioe) {
if (!(ioe instanceof SSLException)) {
throw new SSLException("readApplicationRecord", ioe);
} else {
throw ioe;
}
throw new SSLException("readApplicationRecord", ioe);
}
}
@ -1738,19 +1729,25 @@ public final class SSLSocketImpl
}
try {
if (conContext.isInputCloseNotified) {
// Close the connection, no wait for more peer response.
closeSocket(false);
} else {
// Close the connection, may wait for peer close_notify.
closeSocket(true);
}
// If conContext.isInputCloseNotified is false, close the
// connection, no wait for more peer response. Otherwise,
// may wait for peer close_notify.
closeSocket(!conContext.isInputCloseNotified);
} finally {
tlsIsClosed = true;
}
}
}
@Override
public String toString() {
return "SSLSocket[" +
"hostname=" + getPeerHost() +
", port=" + getPeerPort() +
", " + conContext.conSession + // SSLSessionImpl.toString()
"]";
}
private void closeSocket(boolean selfInitiated) throws IOException {
if (SSLLogger.isOn && SSLLogger.isOn("ssl")) {
SSLLogger.fine("close the SSL connection " +