diff --git a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/NeutronRestApi.java b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/NeutronRestApi.java index 63d81a8e4bd..528a4ac4a32 100644 --- a/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/NeutronRestApi.java +++ b/plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/api/NeutronRestApi.java @@ -189,22 +189,28 @@ public class NeutronRestApi { @Override public Socket createSocket(final String host, final int port) throws IOException { - SSLSocket s = (SSLSocket) ssf.createSocket(host, port); - s.setEnabledProtocols(SSLUtils.getSupportedProtocols(s.getEnabledProtocols())); + Socket s = ssf.createSocket(host, port); + if (s instanceof SSLSocket) { + ((SSLSocket)s).setEnabledProtocols(SSLUtils.getSupportedProtocols(((SSLSocket)s).getEnabledProtocols())); + } return s; } @Override public Socket createSocket(final String address, final int port, final InetAddress localAddress, final int localPort) throws IOException, UnknownHostException { - SSLSocket s = (SSLSocket) ssf.createSocket(address, port, localAddress, localPort); - s.setEnabledProtocols(SSLUtils.getSupportedProtocols(s.getEnabledProtocols())); + Socket s = ssf.createSocket(address, port, localAddress, localPort); + if (s instanceof SSLSocket) { + ((SSLSocket)s).setEnabledProtocols(SSLUtils.getSupportedProtocols(((SSLSocket)s).getEnabledProtocols())); + } return s; } @Override public Socket createSocket(final Socket socket, final String host, final int port, final boolean autoClose) throws IOException, UnknownHostException { - SSLSocket s = (SSLSocket) ssf.createSocket(socket, host, port, autoClose); - s.setEnabledProtocols(SSLUtils.getSupportedProtocols(s.getEnabledProtocols())); + Socket s = ssf.createSocket(socket, host, port, autoClose); + if (s instanceof SSLSocket) { + ((SSLSocket)s).setEnabledProtocols(SSLUtils.getSupportedProtocols(((SSLSocket)s).getEnabledProtocols())); + } return s; } @@ -213,10 +219,16 @@ public class NeutronRestApi { UnknownHostException, ConnectTimeoutException { int timeout = params.getConnectionTimeout(); if (timeout == 0) { - return createSocket(host, port, localAddress, localPort); + Socket s = createSocket(host, port, localAddress, localPort); + if (s instanceof SSLSocket) { + ((SSLSocket)s).setEnabledProtocols(SSLUtils.getSupportedProtocols(((SSLSocket)s).getEnabledProtocols())); + } + return s; } else { - SSLSocket s = (SSLSocket) ssf.createSocket(); - s.setEnabledProtocols(SSLUtils.getSupportedProtocols(s.getEnabledProtocols())); + Socket s = ssf.createSocket(); + if (s instanceof SSLSocket) { + ((SSLSocket)s).setEnabledProtocols(SSLUtils.getSupportedProtocols(((SSLSocket)s).getEnabledProtocols())); + } s.bind(new InetSocketAddress(localAddress, localPort)); s.connect(new InetSocketAddress(host, port), timeout); return s; diff --git a/utils/src/com/cloud/utils/rest/RESTServiceConnector.java b/utils/src/com/cloud/utils/rest/RESTServiceConnector.java index 487610a811d..cdacd1f5ff6 100644 --- a/utils/src/com/cloud/utils/rest/RESTServiceConnector.java +++ b/utils/src/com/cloud/utils/rest/RESTServiceConnector.java @@ -356,15 +356,19 @@ public class RESTServiceConnector { @Override public Socket createSocket(final String address, final int port, final InetAddress localAddress, final int localPort) throws IOException, UnknownHostException { - SSLSocket socket = (SSLSocket) ssf.createSocket(address, port, localAddress, localPort); - socket.setEnabledProtocols(SSLUtils.getSupportedProtocols(socket.getEnabledProtocols())); + Socket socket = ssf.createSocket(address, port, localAddress, localPort); + if (socket instanceof SSLSocket) { + ((SSLSocket)socket).setEnabledProtocols(SSLUtils.getSupportedProtocols(((SSLSocket)socket).getEnabledProtocols())); + } return socket; } @Override public Socket createSocket(final Socket socket, final String host, final int port, final boolean autoClose) throws IOException, UnknownHostException { - SSLSocket s = (SSLSocket) ssf.createSocket(socket, host, port, autoClose); - s.setEnabledProtocols(SSLUtils.getSupportedProtocols(s.getEnabledProtocols())); + Socket s = ssf.createSocket(socket, host, port, autoClose); + if (s instanceof SSLSocket) { + ((SSLSocket)s).setEnabledProtocols(SSLUtils.getSupportedProtocols(((SSLSocket)s).getEnabledProtocols())); + } return s; } @@ -373,10 +377,16 @@ public class RESTServiceConnector { throws IOException, UnknownHostException, ConnectTimeoutException { final int timeout = params.getConnectionTimeout(); if (timeout == 0) { - return createSocket(host, port, localAddress, localPort); + Socket socket = createSocket(host, port, localAddress, localPort); + if (socket instanceof SSLSocket) { + ((SSLSocket)socket).setEnabledProtocols(SSLUtils.getSupportedProtocols(((SSLSocket)socket).getEnabledProtocols())); + } + return socket; } else { - final SSLSocket s = (SSLSocket) ssf.createSocket(); - s.setEnabledProtocols(SSLUtils.getSupportedProtocols(s.getEnabledProtocols())); + final Socket s = ssf.createSocket(); + if (s instanceof SSLSocket) { + ((SSLSocket)s).setEnabledProtocols(SSLUtils.getSupportedProtocols(((SSLSocket)s).getEnabledProtocols())); + } s.bind(new InetSocketAddress(localAddress, localPort)); s.connect(new InetSocketAddress(host, port), timeout); return s; diff --git a/utils/src/org/apache/commons/httpclient/contrib/ssl/EasySSLProtocolSocketFactory.java b/utils/src/org/apache/commons/httpclient/contrib/ssl/EasySSLProtocolSocketFactory.java index a60e6861148..3e7d78d189f 100644 --- a/utils/src/org/apache/commons/httpclient/contrib/ssl/EasySSLProtocolSocketFactory.java +++ b/utils/src/org/apache/commons/httpclient/contrib/ssl/EasySSLProtocolSocketFactory.java @@ -124,8 +124,10 @@ public class EasySSLProtocolSocketFactory implements SecureProtocolSocketFactory */ @Override public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort) throws IOException, UnknownHostException { - SSLSocket socket = (SSLSocket) getSSLContext().getSocketFactory().createSocket(host, port, clientHost, clientPort); - socket.setEnabledProtocols(SSLUtils.getSupportedProtocols(socket.getEnabledProtocols())); + Socket socket = getSSLContext().getSocketFactory().createSocket(host, port, clientHost, clientPort); + if (socket instanceof SSLSocket) { + ((SSLSocket)socket).setEnabledProtocols(SSLUtils.getSupportedProtocols(((SSLSocket)socket).getEnabledProtocols())); + } return socket; } @@ -159,10 +161,16 @@ public class EasySSLProtocolSocketFactory implements SecureProtocolSocketFactory int timeout = params.getConnectionTimeout(); SocketFactory socketfactory = getSSLContext().getSocketFactory(); if (timeout == 0) { - return socketfactory.createSocket(host, port, localAddress, localPort); + Socket socket = socketfactory.createSocket(host, port, localAddress, localPort); + if (socket instanceof SSLSocket) { + ((SSLSocket)socket).setEnabledProtocols(SSLUtils.getSupportedProtocols(((SSLSocket)socket).getEnabledProtocols())); + } + return socket; } else { - SSLSocket socket = (SSLSocket) socketfactory.createSocket(); - socket.setEnabledProtocols(SSLUtils.getSupportedProtocols(socket.getEnabledProtocols())); + Socket socket = socketfactory.createSocket(); + if (socket instanceof SSLSocket) { + ((SSLSocket)socket).setEnabledProtocols(SSLUtils.getSupportedProtocols(((SSLSocket)socket).getEnabledProtocols())); + } SocketAddress localaddr = new InetSocketAddress(localAddress, localPort); SocketAddress remoteaddr = new InetSocketAddress(host, port); socket.bind(localaddr); @@ -176,8 +184,10 @@ public class EasySSLProtocolSocketFactory implements SecureProtocolSocketFactory */ @Override public Socket createSocket(String host, int port) throws IOException, UnknownHostException { - SSLSocket socket = (SSLSocket) getSSLContext().getSocketFactory().createSocket(host, port); - socket.setEnabledProtocols(SSLUtils.getSupportedProtocols(socket.getEnabledProtocols())); + Socket socket = (Socket) getSSLContext().getSocketFactory().createSocket(host, port); + if (socket instanceof SSLSocket) { + ((SSLSocket)socket).setEnabledProtocols(SSLUtils.getSupportedProtocols(((SSLSocket)socket).getEnabledProtocols())); + } return socket; } @@ -186,8 +196,10 @@ public class EasySSLProtocolSocketFactory implements SecureProtocolSocketFactory */ @Override public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException { - SSLSocket s= (SSLSocket) getSSLContext().getSocketFactory().createSocket(socket, host, port, autoClose); - s.setEnabledProtocols(SSLUtils.getSupportedProtocols(s.getEnabledProtocols())); + Socket s = getSSLContext().getSocketFactory().createSocket(socket, host, port, autoClose); + if (s instanceof SSLSocket) { + ((SSLSocket)s).setEnabledProtocols(SSLUtils.getSupportedProtocols(((SSLSocket)s).getEnabledProtocols())); + } return s; }