Skip to content

Commit 4cf37a9

Browse files
committed
Bring onSslHandshakeCompleted back to life
1 parent 2826f29 commit 4cf37a9

File tree

6 files changed

+43
-17
lines changed

6 files changed

+43
-17
lines changed

api/src/main/java/org/asynchttpclient/AsyncHandlerExtensions.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
/**
1818
* This interface hosts new low level callback methods on {@link AsyncHandler}.
19-
* For now, those methods are in a dedicated interface in order not to break the existing API,
20-
* but could be merged into one of the existing ones in AHC 2.
19+
* For now, those methods are in a dedicated interface in order not to break the
20+
* existing API, but could be merged into one of the existing ones in AHC 2.
2121
*
2222
* More additional hooks might come, such as:
2323
* <ul>
24-
* <li>onConnectionClosed()</li>
25-
* <li>onBytesSent(long numberOfBytes)</li>
26-
* <li>onBytesReceived(long numberOfBytes)</li>
24+
* <li>onConnectionClosed()</li>
25+
* <li>onBytesSent(long numberOfBytes)</li>
26+
* <li>onBytesReceived(long numberOfBytes)</li>
2727
* </ul>
2828
*/
2929
public interface AsyncHandlerExtensions {
@@ -44,14 +44,15 @@ public interface AsyncHandlerExtensions {
4444
void onPoolConnection();
4545

4646
/**
47-
* Notify the callback when a new connection was successfully fetched from the pool.
47+
* Notify the callback when a new connection was successfully fetched from
48+
* the pool.
4849
*/
4950
void onConnectionPooled();
5051

5152
/**
52-
* Notify the callback when a request is being written on the wire.
53-
* If the original request causes multiple requests to be sent, for example, because of authorization or retry,
54-
* it will be notified multiple times.
53+
* Notify the callback when a request is being written on the wire. If the
54+
* original request causes multiple requests to be sent, for example,
55+
* because of authorization or retry, it will be notified multiple times.
5556
*
5657
* @param request the real request object as passed to the provider
5758
*/
@@ -66,4 +67,10 @@ public interface AsyncHandlerExtensions {
6667
* Notify the callback after DNS resolution has completed.
6768
*/
6869
void onDnsResolved(InetSocketAddress remoteAddress);
70+
71+
/**
72+
* Notify the callback when the SSL handshake performed to establish an
73+
* HTTPS connection has been completed.
74+
*/
75+
void onSslHandshakeCompleted();
6976
}

api/src/test/java/org/asynchttpclient/async/util/EventCollectingHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,9 @@ public void onRetry() {
103103
public void onDnsResolved(InetSocketAddress remoteAddress) {
104104
firedEvents.add("DnsResolved");
105105
}
106+
107+
@Override
108+
public void onSslHandshakeCompleted() {
109+
firedEvents.add("SslHandshakeCompleted");
110+
}
106111
}

providers/netty3/src/main/java/org/asynchttpclient/providers/netty3/request/NettyConnectListener.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.net.ConnectException;
1919

20+
import org.asynchttpclient.AsyncHandler;
2021
import org.asynchttpclient.AsyncHandlerExtensions;
2122
import org.asynchttpclient.providers.netty.commons.future.StackTraceInspector;
2223
import org.asynchttpclient.providers.netty3.channel.ChannelManager;
@@ -88,11 +89,16 @@ private void onFutureSuccess(final Channel channel) throws ConnectException {
8889
sslHandler.handshake().addListener(new ChannelFutureListener() {
8990

9091
@Override
91-
public void operationComplete(ChannelFuture future) throws Exception {
92-
if (future.isSuccess())
92+
public void operationComplete(ChannelFuture handshakeFuture) throws Exception {
93+
if (handshakeFuture.isSuccess()) {
94+
final AsyncHandler<T> asyncHandler = future.getAsyncHandler();
95+
if (asyncHandler instanceof AsyncHandlerExtensions)
96+
AsyncHandlerExtensions.class.cast(asyncHandler).onSslHandshakeCompleted();
97+
9398
writeRequest(channel);
94-
else
95-
onFutureFailure(channel, future.getCause());
99+
} else {
100+
onFutureFailure(channel, handshakeFuture.getCause());
101+
}
96102
}
97103
});
98104

providers/netty3/src/test/java/org/asynchttpclient/providers/netty3/NettyBasicHttpsTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public void testNormalEventsFired() throws InterruptedException, TimeoutExceptio
4141
"PoolConnection",
4242
"OpenConnection",
4343
"DnsResolved",
44+
"SslHandshakeCompleted",
4445
"ConnectionOpen",
4546
"SendRequest",
4647
"HeaderWriteCompleted",

providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/request/NettyConnectListener.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import java.net.ConnectException;
2525

26+
import org.asynchttpclient.AsyncHandler;
2627
import org.asynchttpclient.AsyncHandlerExtensions;
2728
import org.asynchttpclient.providers.netty.commons.future.StackTraceInspector;
2829
import org.asynchttpclient.providers.netty4.channel.ChannelManager;
@@ -87,12 +88,17 @@ private void onFutureSuccess(final Channel channel) throws ConnectException {
8788
if (sslHandler != null) {
8889
sslHandler.handshakeFuture().addListener(new GenericFutureListener<Future<Channel>>() {
8990
@Override
90-
public void operationComplete(Future<Channel> future) throws Exception {
91+
public void operationComplete(Future<Channel> handshakeFuture) throws Exception {
9192

92-
if (future.isSuccess())
93+
if (handshakeFuture.isSuccess()) {
94+
final AsyncHandler<T> asyncHandler = future.getAsyncHandler();
95+
if (asyncHandler instanceof AsyncHandlerExtensions)
96+
AsyncHandlerExtensions.class.cast(asyncHandler).onSslHandshakeCompleted();
97+
9398
writeRequest(channel);
94-
else
95-
onFutureFailure(channel, future.cause());
99+
} else {
100+
onFutureFailure(channel, handshakeFuture.cause());
101+
}
96102
}
97103
});
98104

providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBasicHttpsTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public void testNormalEventsFired() throws InterruptedException, TimeoutExceptio
4141
"PoolConnection",
4242
"OpenConnection",
4343
"DnsResolved",
44+
"SslHandshakeCompleted",
4445
"ConnectionOpen",
4546
"SendRequest",
4647
"HeaderWriteCompleted",

0 commit comments

Comments
 (0)