1 /*
2  * Copyright 2014-2020 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 package com.amazonaws.internal;
16
17 import java.io.IOException;
18 import java.net.SocketAddress;
19
20 import javax.net.ssl.SSLSocket;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24
25 public class SdkSSLSocket extends DelegateSSLSocket {
26     private static final Log log = LogFactory.getLog(SdkSSLSocket.class);
27
28     public SdkSSLSocket(SSLSocket sock) {
29         super(sock);
30         if (log.isDebugEnabled())
31             log.debug("created: " + endpoint());
32     }
33
34     /**
35      * Returns the endpoint in the format of "address:port"
36      */

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