1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  *  http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */

15
16 package software.amazon.awssdk.http.apache.internal.net;
17
18 import java.io.IOException;
19 import java.net.SocketAddress;
20 import javax.net.ssl.SSLSocket;
21 import software.amazon.awssdk.annotations.SdkInternalApi;
22 import software.amazon.awssdk.utils.Logger;
23
24 @SdkInternalApi
25 public class SdkSslSocket extends DelegateSslSocket {
26     private static final Logger log = Logger.loggerFor(SdkSslSocket.class);
27
28     public SdkSslSocket(SSLSocket sock) {
29         super(sock);
30         log.debug(() -> "created: " + endpoint());
31     }
32
33     /**
34      * Returns the endpoint in the format of "address:port"
35      */

36     private String endpoint() {
37         return sock.getInetAddress() + ":" + sock.getPort();
38     }
39
40     @Override
41     public void connect(SocketAddress endpoint) throws IOException {
42         log.trace(() -> "connecting to: " + endpoint);
43         sock.connect(endpoint);
44         log.debug(() -> "connected to: " + endpoint);
45     }
46
47     @Override
48     public void connect(SocketAddress endpoint, int timeout) throws IOException {
49         log.trace(() -> "connecting to: " + endpoint);
50         sock.connect(endpoint, timeout);
51         log.debug(() -> "connected to: " + endpoint);
52     }
53
54     @Override
55     public void close() throws IOException {
56         log.debug(() -> "closing " + endpoint());
57         sock.close();
58     }
59
60     @Override
61     public void shutdownInput() throws IOException {
62         log.debug(() -> "shutting down input of " + endpoint());
63         sock.shutdownInput();
64     }
65
66     @Override
67     public void shutdownOutput() throws IOException {
68         log.debug(() -> "shutting down output of " + endpoint());
69         sock.shutdownOutput();
70     }
71 }
72