use of javax.net.SocketFactory in project camel by apache.
the class FtpBadLoginConnectionLeakTest method createRegistry.
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry jndi = super.createRegistry();
SocketFactory sf = new AuditingSocketFactory();
jndi.bind("sf", sf);
return jndi;
}
use of javax.net.SocketFactory in project camel by apache.
the class SmppConnectionFactory method createConnection.
public Connection createConnection(String host, int port) throws IOException {
try {
Socket socket;
SocketFactory socketFactory;
socketFactory = config.getUsingSSL() && config.getHttpProxyHost() == null ? SSLSocketFactory.getDefault() : SocketFactory.getDefault();
if (config.getHttpProxyHost() != null) {
// setup the proxy tunnel
socket = socketFactory.createSocket(config.getHttpProxyHost(), config.getHttpProxyPort());
connectProxy(host, port, socket);
} else {
socket = socketFactory.createSocket(host, port);
}
if (config.getUsingSSL() && config.getHttpProxyHost() != null) {
// Init the SSL socket which is based on the proxy socket
SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(socket, host, port, true);
sslSocket.startHandshake();
socket = sslSocket;
}
return new SocketConnection(socket);
} catch (Exception e) {
throw new IOException(e.getMessage());
}
}
use of javax.net.SocketFactory in project twitter-2-weibo by rjyo.
the class MySSLSocketFactory method createSocket.
public Socket createSocket(String host, int port, InetAddress localAddress, int localPort, HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
if (params == null) {
throw new IllegalArgumentException("Parameters may not be null");
}
int timeout = params.getConnectionTimeout();
SocketFactory socketfactory = getSSLContext().getSocketFactory();
if (timeout == 0) {
return socketfactory.createSocket(host, port, localAddress, localPort);
} else {
Socket socket = socketfactory.createSocket();
SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
SocketAddress remoteaddr = new InetSocketAddress(host, port);
socket.bind(localaddr);
socket.connect(remoteaddr, timeout);
return socket;
}
}
use of javax.net.SocketFactory in project AsmackService by rtreffer.
the class TcpConnection method connect.
/**
* Start the tcp connection to a given ip/port pair.
* @param addresse InetAddress The target internet address.
* @param port int The target port.
* @throws XmppException In case of a lower level exception.
*/
protected void connect(InetAddress addresse, int port) throws XmppException {
SocketFactory socketFactory = SocketFactory.getDefault();
try {
socket = socketFactory.createSocket(addresse, port);
socket.setKeepAlive(false);
socket.setSoTimeout(3 * 60 * 1000);
socket.setTcpNoDelay(true);
} catch (IOException e) {
close();
throw new XmppTransportException("Can't connect", e);
}
FeatureNegotiationEngine engine;
try {
engine = new FeatureNegotiationEngine(socket);
} catch (XmlPullParserException e) {
close();
throw new XmppMalformedException("Can't connect", e);
} catch (IOException e) {
close();
throw new XmppTransportException("Can't connect", e);
}
engine.open(account);
resourceJid = engine.bind(account.getResource());
if (resourceJid == null) {
close();
throw new XmppTransportException("Can't bind");
}
Log.d(TAG, "Bound as " + resourceJid);
xmppInput = engine.getXmppInputStream();
xmppOutput = engine.getXmppOutputStream();
}
use of javax.net.SocketFactory in project mockito by mockito.
the class DeepStubbingTest method myTest.
@Test
public void myTest() throws Exception {
SocketFactory sf = mock(SocketFactory.class, RETURNS_DEEP_STUBS);
when(sf.createSocket(anyString(), eq(80))).thenReturn(null);
sf.createSocket("what", 80);
}
Aggregations