Search in sources :

Example 51 with SocketFactory

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;
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) SocketFactory(javax.net.SocketFactory)

Example 52 with SocketFactory

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());
    }
}
Also used : SocketConnection(org.jsmpp.session.connection.socket.SocketConnection) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) SocketFactory(javax.net.SocketFactory) SSLSocket(javax.net.ssl.SSLSocket) IOException(java.io.IOException) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) Socket(java.net.Socket) SSLSocket(javax.net.ssl.SSLSocket) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException)

Example 53 with SocketFactory

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;
    }
}
Also used : SocketFactory(javax.net.SocketFactory) ProtocolSocketFactory(org.apache.commons.httpclient.protocol.ProtocolSocketFactory) InetSocketAddress(java.net.InetSocketAddress) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Socket(java.net.Socket)

Example 54 with SocketFactory

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();
}
Also used : XmppMalformedException(com.googlecode.asmack.XmppMalformedException) SocketFactory(javax.net.SocketFactory) XmppTransportException(com.googlecode.asmack.connection.XmppTransportException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 55 with SocketFactory

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);
}
Also used : SocketFactory(javax.net.SocketFactory) Test(org.junit.Test)

Aggregations

SocketFactory (javax.net.SocketFactory)66 Socket (java.net.Socket)25 Test (org.junit.Test)25 IOException (java.io.IOException)18 InetSocketAddress (java.net.InetSocketAddress)14 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 SSLSocket (javax.net.ssl.SSLSocket)10 OutputStream (java.io.OutputStream)9 ServerSocket (java.net.ServerSocket)9 SocketAddress (java.net.SocketAddress)6 Configuration (org.apache.hadoop.conf.Configuration)5 ServerSocketFactory (javax.net.ServerSocketFactory)4 InputStream (java.io.InputStream)3 InetAddress (java.net.InetAddress)3 UnknownHostException (java.net.UnknownHostException)3 ProtocolSocketFactory (org.apache.commons.httpclient.protocol.ProtocolSocketFactory)3 StandardSocketFactory (org.apache.hadoop.net.StandardSocketFactory)3 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)3 SocketException (java.net.SocketException)2