|
17 | 17 | import java.io.IOException;
|
18 | 18 | import java.io.InputStream;
|
19 | 19 | import java.io.OutputStream;
|
| 20 | +import java.net.SocketAddress; |
20 | 21 | import java.net.URI;
|
21 | 22 | import java.nio.ByteBuffer;
|
22 | 23 | import java.nio.file.Path;
|
|
34 | 35 | import org.eclipse.jetty.client.BufferingResponseListener;
|
35 | 36 | import org.eclipse.jetty.client.BytesRequestContent;
|
36 | 37 | import org.eclipse.jetty.client.CompletableResponseListener;
|
| 38 | +import org.eclipse.jetty.client.Connection; |
37 | 39 | import org.eclipse.jetty.client.ConnectionPool;
|
38 | 40 | import org.eclipse.jetty.client.ContentResponse;
|
39 | 41 | import org.eclipse.jetty.client.Destination;
|
|
72 | 74 | import org.eclipse.jetty.io.ClientConnectionFactory;
|
73 | 75 | import org.eclipse.jetty.io.ClientConnector;
|
74 | 76 | import org.eclipse.jetty.io.Content;
|
| 77 | +import org.eclipse.jetty.io.EndPoint; |
75 | 78 | import org.eclipse.jetty.io.Transport;
|
76 | 79 | import org.eclipse.jetty.io.ssl.SslHandshakeListener;
|
77 | 80 | import org.eclipse.jetty.quic.client.ClientQuicConfiguration;
|
@@ -1180,4 +1183,29 @@ public void mixedTransports() throws Exception
|
1180 | 1183 | .send();
|
1181 | 1184 | // end::mixedTransports[]
|
1182 | 1185 | }
|
| 1186 | + |
| 1187 | + public void connectionInformation() throws Exception |
| 1188 | + { |
| 1189 | + // tag::connectionInformation[] |
| 1190 | + HttpClient httpClient = new HttpClient(); |
| 1191 | + httpClient.start(); |
| 1192 | + |
| 1193 | + ContentResponse response = httpClient.newRequest("http://domain.com/path") |
| 1194 | + // The connection information is only available starting from the request begin event. |
| 1195 | + .onRequestBegin(request -> |
| 1196 | + { |
| 1197 | + Connection connection = request.getConnection(); |
| 1198 | + |
| 1199 | + // Obtain the address of the server. |
| 1200 | + SocketAddress remoteAddress = connection.getRemoteSocketAddress(); |
| 1201 | + System.getLogger("connection").log(INFO, "Server address: %s", remoteAddress); |
| 1202 | + |
| 1203 | + // Obtain the SslSessionData. |
| 1204 | + EndPoint.SslSessionData sslSessionData = connection.getSslSessionData(); |
| 1205 | + if (sslSessionData != null) |
| 1206 | + System.getLogger("connection").log(INFO, "SslSessionData: %s", sslSessionData); |
| 1207 | + }) |
| 1208 | + .send(); |
| 1209 | + // end::connectionInformation[] |
| 1210 | + } |
1183 | 1211 | }
|
0 commit comments