use of javax.net.SocketFactory in project java-apns by notnoop.
the class ApnsFeedbackConnectionTest method connectionParsedThree.
@Test
public void connectionParsedThree() {
SocketFactory sf = MockingUtils.mockSocketFactory(null, threeStream);
ApnsFeedbackConnection connection = new ApnsFeedbackConnection(sf, "localhost", 80);
checkParsedThree(connection.getInactiveDevices());
}
use of javax.net.SocketFactory in project jodd by oblac.
the class SocketHttpConnectionProvider method createSSLSocket.
/**
* Creates a SSL socket. Enables default secure enabled protocols if specified.
*/
protected SSLSocket createSSLSocket(String host, int port, int connectionTimeout, boolean trustAll, boolean verifyHttpsHost) throws IOException {
SocketFactory socketFactory = getSocketFactory(proxy, true, trustAll);
Socket socket;
if (connectionTimeout < 0) {
socket = socketFactory.createSocket(host, port);
} else {
// creates unconnected socket
// unfortunately, this does not work always
// sslSocket = (SSLSocket) socketFactory.createSocket();
// sslSocket.connect(new InetSocketAddress(host, port), connectionTimeout);
//
// Note: SSLSocketFactory has several create() methods.
// Those that take arguments all connect immediately
// and have no options for specifying a connection timeout.
//
// So, we have to create a socket and connect it (with a
// connection timeout), then have the SSLSocketFactory wrap
// the already-connected socket.
//
socket = new Socket();
//sock.setSoTimeout(readTimeout);
socket.connect(new InetSocketAddress(host, port), connectionTimeout);
// continue to wrap this plain socket with ssl socket...
}
// wrap plain socket in an SSL socket
SSLSocket sslSocket;
if (socket instanceof SSLSocket) {
sslSocket = (SSLSocket) socket;
} else {
if (socketFactory instanceof SSLSocketFactory) {
sslSocket = (SSLSocket) ((SSLSocketFactory) socketFactory).createSocket(socket, host, port, true);
} else {
sslSocket = (SSLSocket) (getDefaultSSLSocketFactory(trustAll)).createSocket(socket, host, port, true);
}
}
// sslSocket is now ready
String enabledProtocols = JoddHttp.defaultSecureEnabledProtocols;
if (enabledProtocols != null) {
String[] values = StringUtil.splitc(enabledProtocols, ',');
StringUtil.trimAll(values);
sslSocket.setEnabledProtocols(values);
}
if (verifyHttpsHost) {
SSLParameters sslParams = new SSLParameters();
sslParams.setEndpointIdentificationAlgorithm("HTTPS");
sslSocket.setSSLParameters(sslParams);
}
return sslSocket;
}
use of javax.net.SocketFactory in project jodd by oblac.
the class SocketHttpConnectionProvider method createSocket.
/**
* Creates a socket using socket factory.
*/
protected Socket createSocket(String host, int port, int connectionTimeout) throws IOException {
SocketFactory socketFactory = getSocketFactory(proxy, false, false);
if (connectionTimeout < 0) {
return socketFactory.createSocket(host, port);
} else {
// creates unconnected socket
Socket socket = socketFactory.createSocket();
socket.connect(new InetSocketAddress(host, port), connectionTimeout);
return socket;
}
}
use of javax.net.SocketFactory in project hadoop by apache.
the class HAServiceTarget method getProxyForAddress.
private HAServiceProtocol getProxyForAddress(Configuration conf, int timeoutMs, InetSocketAddress addr) throws IOException {
Configuration confCopy = new Configuration(conf);
// Lower the timeout so we quickly fail to connect
confCopy.setInt(CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 1);
SocketFactory factory = NetUtils.getDefaultSocketFactory(confCopy);
return new HAServiceProtocolClientSideTranslatorPB(addr, confCopy, factory, timeoutMs);
}
use of javax.net.SocketFactory in project hadoop by apache.
the class HAServiceTarget method getZKFCProxy.
/**
* @return a proxy to the ZKFC which is associated with this HA service.
*/
public ZKFCProtocol getZKFCProxy(Configuration conf, int timeoutMs) throws IOException {
Configuration confCopy = new Configuration(conf);
// Lower the timeout so we quickly fail to connect
confCopy.setInt(CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 1);
SocketFactory factory = NetUtils.getDefaultSocketFactory(confCopy);
return new ZKFCProtocolClientSideTranslatorPB(getZKFCAddress(), confCopy, factory, timeoutMs);
}
Aggregations