Example usage for org.apache.commons.httpclient.params HttpConnectionParams getConnectionTimeout

List of usage examples for org.apache.commons.httpclient.params HttpConnectionParams getConnectionTimeout

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.params HttpConnectionParams getConnectionTimeout.

Prototype

public int getConnectionTimeout() 

Source Link

Usage

From source file:com.zimbra.common.net.ProtocolSocketFactoryWrapper.java

@Override
public Socket createSocket(String host, int port, InetAddress localAddress, int localPort,
        HttpConnectionParams params) throws IOException {
    int timeout = params != null ? params.getConnectionTimeout() : 0;
    if (timeout > 0) {
        Socket sock = factory.createSocket();
        sock.bind(new InetSocketAddress(localAddress, localPort));
        sock.connect(new InetSocketAddress(host, port), timeout);
        return sock;
    } else {/* w  w w.j a  v a  2  s. co m*/
        return factory.createSocket(host, port, localAddress, localPort);
    }
}

From source file:com.jivesoftware.os.jive.utils.http.client.CustomSecureProtocolSocketFactoryTest.java

@Test
public void testCreateSocketLocalWithTimeout() throws Exception {
    HttpConnectionParams params = mock(HttpConnectionParams.class);
    Socket socket = mock(Socket.class);

    when(params.getConnectionTimeout()).thenReturn(788);
    when(params.getSoTimeout()).thenReturn(789);
    when(sslSocketFactory.createSocket()).thenReturn(socket);

    customSecureProtocolSocketFactory.createSocket("host", 444, InetAddress.getLocalHost(), 8765, params);

    verify(sslSocketFactory).createSocket();
    verify(socket).setSoTimeout(789);//  w w w  .j av a  2s .  c  o m
    verify(socket).connect(new InetSocketAddress("host", 444), 788);
}

From source file:com.cloud.network.bigswitch.TrustingProtocolSocketFactory.java

@Override
public Socket createSocket(String host, int port, InetAddress localAddress, int localPort,
        HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
    int timeout = params.getConnectionTimeout();
    if (timeout == 0) {
        return createSocket(host, port, localAddress, localPort);
    } else {//  www .j a  v  a2  s  .co  m
        Socket s = ssf.createSocket();
        s.bind(new InetSocketAddress(localAddress, localPort));
        s.connect(new InetSocketAddress(host, port), timeout);
        return s;
    }
}

From source file:com.thoughtworks.go.server.web.PermissiveSSLSocketFactory.java

public Socket createSocket(final String host, final int port, final InetAddress localAddress,
        final int localPort, final HttpConnectionParams params) throws IOException {
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null");
    }/*from   ww w.  j av  a  2 s.c  o m*/
    int timeout = params.getConnectionTimeout();
    return timeout == 0 ? createSocket(host, port, localAddress, localPort)
            : ControllerThreadSocketFactory.createSocket(this, host, port, localAddress, localPort, timeout);
}

From source file:com.sun.faban.driver.transport.hc3.ProtocolTimedSocketFactory.java

public Socket createSocket(String host, int port, InetAddress localAddress, int localPort,
        HttpConnectionParams params) throws IOException {
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null");
    }//from  w w  w.j a va  2 s.  c om
    int timeout = params.getConnectionTimeout();
    if (timeout == 0) {
        return createSocket(host, port, localAddress, localPort);
    } else {
        TimedSocket socket = new TimedSocket();
        socket.bind(new InetSocketAddress(localAddress, localPort));
        socket.connect(new InetSocketAddress(host, port), timeout);
        return socket;
    }
}

From source file:com.sun.faban.driver.transport.hc3.BelowTimedSSLSocketFactory.java

public Socket createSocket(String host, int port, InetAddress localAddress, int localPort,
        HttpConnectionParams params) throws IOException {
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null");
    }//from  w  w  w  .ja v  a  2s.  c om
    int timeout = params.getConnectionTimeout();
    if (timeout == 0) {
        return createSocket(host, port, localAddress, localPort);
    } else {
        TimedSocket socket = new TimedSocket();
        socket.bind(new InetSocketAddress(localAddress, localPort));
        socket.connect(new InetSocketAddress(host, port), timeout);
        return sslFactory.createSocket(socket, host, port, true);
    }
}

From source file:com.sun.faban.driver.transport.hc3.AboveTimedSSLSocketFactory.java

public Socket createSocket(String host, int port, InetAddress localAddress, int localPort,
        HttpConnectionParams params) throws IOException {
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null");
    }/*w  ww.j  a v a  2s  .c o  m*/
    int timeout = params.getConnectionTimeout();
    if (timeout <= 0) {
        return createSocket(host, port, localAddress, localPort);
    } else {
        Socket socket = new TimedSocketWrapper(sslFactory.createSocket());
        InetSocketAddress endpoint = new InetSocketAddress(host, port);
        socket.bind(new InetSocketAddress(localAddress, localPort));
        socket.connect(endpoint, timeout);
        return socket;
    }
}

From source file:com.lyndir.lhunath.opal.network.SSLFactory.java

@Override
@Deprecated//from   ww  w.jav a 2  s  . co  m
public Socket createSocket(final String host, final int port, final InetAddress localAddress,
        final int localPort, final HttpConnectionParams params) throws IOException {

    if (params == null)
        throw new IllegalArgumentException("Parameters may not be null.");

    int timeout = params.getConnectionTimeout();
    if (timeout == 0)
        return context.getSocketFactory().createSocket(host, port, localAddress, localPort);

    throw new IllegalArgumentException("Timeout is not supported.");
}

From source file:com.denimgroup.threadfix.remote.AcceptAllTrustManager.java

@Override
public Socket createSocket(final String host, final int port, final InetAddress localAddress,
        final int localPort, final HttpConnectionParams params) throws IOException {
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null");
    }/*w w  w .j ava 2  s  . c om*/

    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;
    }
}

From source file:com.vmware.aurora.vc.vcservice.TlsSocketFactory.java

@Override
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");
    }/* w  w w .  ja  v  a 2 s.  c o m*/
    int timeout = params.getConnectionTimeout();
    SocketFactory socketfactory = getSSLContext().getSocketFactory();
    if (timeout == 0) {
        return socketfactory.createSocket(host, port, localAddress, localPort);
    } else {
        Socket socket = socketfactory.createSocket();
        socket.bind(new InetSocketAddress(localAddress, localPort));
        socket.connect(new InetSocketAddress(host, port), timeout);
        return socket;
    }
}