use of javax.net.ssl.SSLSocket in project custom-cert-https by nelenkov.
the class MySSLSocketFactory method createSocket.
@Override
public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException {
SSLSocket sslSocket = (SSLSocket) socketFactory.createSocket(socket, host, port, autoClose);
hostnameVerifier.verify(host, sslSocket);
return sslSocket;
}
use of javax.net.ssl.SSLSocket in project custom-cert-https by nelenkov.
the class MySSLSocketFactory method connectSocket.
@Override
public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort, HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
if (host == null) {
throw new IllegalArgumentException("Target host may not be null.");
}
if (params == null) {
throw new IllegalArgumentException("Parameters may not be null.");
}
SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());
if ((localAddress != null) || (localPort > 0)) {
if (localPort < 0)
localPort = 0;
InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
sslsock.bind(isa);
}
int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
int soTimeout = HttpConnectionParams.getSoTimeout(params);
InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
sslsock.connect(remoteAddress, connTimeout);
sslsock.setSoTimeout(soTimeout);
try {
hostnameVerifier.verify(host, sslsock);
} catch (IOException iox) {
try {
sslsock.close();
} catch (Exception x) {
}
throw iox;
}
return sslsock;
}
use of javax.net.ssl.SSLSocket in project jodd by oblac.
the class SocketHttpConnectionProvider method createHttpConnection.
/**
* Creates new connection from current {@link jodd.http.HttpRequest request}.
*
* @see #createSocket(String, int, int)
*/
public HttpConnection createHttpConnection(HttpRequest httpRequest) throws IOException {
SocketHttpConnection httpConnection;
final boolean https = httpRequest.protocol().equalsIgnoreCase("https");
if (https) {
SSLSocket sslSocket = createSSLSocket(httpRequest.host(), httpRequest.port(), httpRequest.connectionTimeout(), httpRequest.trustAllCertificates(), httpRequest.verifyHttpsHost());
httpConnection = new SocketHttpSecureConnection(sslSocket);
} else {
Socket socket = createSocket(httpRequest.host(), httpRequest.port(), httpRequest.connectionTimeout());
httpConnection = new SocketHttpConnection(socket);
}
// prepare connection config
httpConnection.setTimeout(httpRequest.timeout());
try {
// additional socket initialization
httpConnection.init();
} catch (Throwable throwable) {
// @wjw_add
httpConnection.close();
throw new HttpException(throwable);
}
return httpConnection;
}
use of javax.net.ssl.SSLSocket in project openhab1-addons by openhab.
the class EasySSLSocketFactory method connectSocket.
/**
* @see org.apache.http.conn.scheme.SocketFactory#connectSocket(java.net.Socket,
* java.lang.String, int, java.net.InetAddress, int,
* org.apache.http.params.HttpParams)
*/
@Override
public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort, HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
int soTimeout = HttpConnectionParams.getSoTimeout(params);
InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());
if ((localAddress != null) || (localPort > 0)) {
// we need to bind explicitly
if (localPort < 0) {
// indicates "any"
localPort = 0;
}
InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
sslsock.bind(isa);
}
sslsock.connect(remoteAddress, connTimeout);
sslsock.setSoTimeout(soTimeout);
return sslsock;
}
use of javax.net.ssl.SSLSocket in project orientdb by orientechnologies.
the class OClientConnectionManager method shutdown.
public void shutdown() {
timerTask.cancel();
final Iterator<Entry<Integer, OClientConnection>> iterator = connections.entrySet().iterator();
while (iterator.hasNext()) {
final Entry<Integer, OClientConnection> entry = iterator.next();
final ONetworkProtocol protocol = entry.getValue().getProtocol();
if (protocol != null)
protocol.sendShutdown();
OLogManager.instance().debug(this, "Sending shutdown to thread %s", protocol);
OCommandRequestText command = entry.getValue().getData().command;
if (command != null && command.isIdempotent()) {
protocol.interrupt();
} else {
if (protocol instanceof ONetworkProtocolBinary && ((ONetworkProtocolBinary) protocol).getRequestType() == OChannelBinaryProtocol.REQUEST_SHUTDOWN) {
continue;
}
final Socket socket;
if (protocol == null || protocol.getChannel() == null)
socket = null;
else
socket = protocol.getChannel().socket;
if (socket != null && !socket.isClosed() && !socket.isInputShutdown()) {
try {
OLogManager.instance().debug(this, "Closing input socket of thread %s", protocol);
if (// An SSLSocket will throw an UnsupportedOperationException.
!(socket instanceof SSLSocket))
socket.shutdownInput();
} catch (IOException e) {
OLogManager.instance().debug(this, "Error on closing connection of %s client during shutdown", e, entry.getValue().getRemoteAddress());
}
}
if (protocol.isAlive()) {
if (protocol instanceof ONetworkProtocolBinary && ((ONetworkProtocolBinary) protocol).getRequestType() == -1) {
try {
OLogManager.instance().debug(this, "Closing socket of thread %s", protocol);
protocol.getChannel().close();
} catch (Exception e) {
OLogManager.instance().debug(this, "Error during chanel close at shutdown", e);
}
OLogManager.instance().debug(this, "Sending interrupt signal to thread %s", protocol);
protocol.interrupt();
}
// protocol.join();
}
}
}
}
Aggregations