/** * Performs standard initializations on a newly created socket. * * @param sock the socket to prepare * @param context the context for the connection * @param params the parameters from which to prepare the socket * * @throws IOException in case of an IO problem */ protected void prepareSocket(Socket sock, HttpContext context, HttpParams params) throws IOException { // context currently not used, but derived classes may need it //@@@ is context allowed to be null? sock.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params)); sock.setSoTimeout(HttpConnectionParams.getSoTimeout(params)); int linger = HttpConnectionParams.getLinger(params); if (linger >= 0) { sock.setSoLinger(linger > 0, linger); } } // prepareSocket
public void bind(final Socket socket, final HttpParams params) throws IOException { if (socket == null) { throw new IllegalArgumentException("Socket may not be null"); } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } assertNotOpen(); socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params)); socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params)); int linger = HttpConnectionParams.getLinger(params); if (linger >= 0) { socket.setSoLinger(linger > 0, linger); } super.bind(socket, params); }
public void bind( final Socket socket, final HttpParams params) throws IOException { if (socket == null) { throw new IllegalArgumentException("Socket may not be null"); } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } assertNotOpen(); socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params)); socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params)); int linger = HttpConnectionParams.getLinger(params); if (linger >= 0) { socket.setSoLinger(linger > 0, linger); } super.bind(socket, params); }
public HttpResponse emulateRequest(HttpHost httpHost, HttpRequest httpRequest, HttpContext httpContext, RequestDirector requestDirector) throws HttpException, IOException { if (logHttpRequests) { System.out.println(" <-- " + httpRequest.getRequestLine()); } HttpResponse httpResponse = findResponse(httpRequest); if (logHttpRequests) { System.out.println(" --> " + (httpResponse == null ? null : httpResponse.getStatusLine().getStatusCode())); } if (httpResponse == null) { throw new RuntimeException("Unexpected call to execute, no pending responses are available. See Robolectric.addPendingResponse(). Request was: " + httpRequest.getRequestLine().getMethod() + " " + httpRequest.getRequestLine().getUri()); } else { HttpParams params = httpResponse.getParams(); if (HttpConnectionParams.getConnectionTimeout(params) < 0) { throw new ConnectTimeoutException("Socket is not connected"); } else if (HttpConnectionParams.getSoTimeout(params) < 0) { throw new ConnectTimeoutException("The operation timed out"); } } addRequestInfo(new HttpRequestInfo(httpRequest, httpHost, httpContext, requestDirector)); addHttpResponse(httpResponse); return httpResponse; } public boolean hasPendingResponses() {
/** * @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) { localPort = 0; // indicates "any" } InetSocketAddress isa = new InetSocketAddress(localAddress, localPort); sslsock.bind(isa); } sslsock.connect(remoteAddress, connTimeout); sslsock.setSoTimeout(soTimeout); return sslsock; }
/** * @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, org.apache.http.params.HttpParams params) throws IOException { int connTimeout = org.apache.http.params.HttpConnectionParams.getConnectionTimeout(params); int soTimeout = org.apache.http.params.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) { localPort = 0; // indicates "any" } InetSocketAddress isa = new InetSocketAddress(localAddress, localPort); sslsock.bind(isa); } sslsock.connect(remoteAddress, connTimeout); sslsock.setSoTimeout(soTimeout); return sslsock; }
int soTimeout = HttpConnectionParams.getSoTimeout(params);
managedConn.open(route, context, params); } else { managedConn.setSocketTimeout(HttpConnectionParams.getSoTimeout(params));
managedConn.setSocketTimeout(HttpConnectionParams.getSoTimeout(params));
public int getSoTimeout() { return HttpConnectionParams.getSoTimeout(params); }
public int getReadTimeout() { return HttpConnectionParams.getSoTimeout(http.getParams()); }
@Override public Socket connectSocket(final Socket sock, final InetSocketAddress remoteAddress, final InetSocketAddress localAddress, final HttpParams params) throws IOException { checkArgument(remoteAddress != null, "Remote address may not be null"); checkArgument(params != null, "HTTP parameters may not be null"); Socket socket = sock != null ? sock : new Socket(); if (localAddress != null) { socket.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params)); socket.bind(localAddress); } socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params)); socket.connect(remoteAddress, HttpConnectionParams.getConnectionTimeout(params)); if (socket instanceof SSLSocket) { return socket; } return getSSLContext().getSocketFactory() .createSocket(socket, remoteAddress.getHostName(), remoteAddress.getPort(), true); }
public void bind(final Socket socket, final HttpParams params) throws IOException { if (socket == null) { throw new IllegalArgumentException("Socket may not be null"); } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } assertNotOpen(); socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params)); socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params)); int linger = HttpConnectionParams.getLinger(params); if (linger >= 0) { socket.setSoLinger(linger > 0, linger); } super.bind(socket, params); }
public void bind( final Socket socket, final HttpParams params) throws IOException { if (socket == null) { throw new IllegalArgumentException("Socket may not be null"); } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } assertNotOpen(); socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params)); socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params)); int linger = HttpConnectionParams.getLinger(params); if (linger >= 0) { socket.setSoLinger(linger > 0, linger); } super.bind(socket, params); }
public void bind(final Socket socket, final HttpParams params) throws IOException { if (socket == null) { throw new IllegalArgumentException("Socket may not be null"); } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } assertNotOpen(); socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params)); socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params)); int linger = HttpConnectionParams.getLinger(params); if (linger >= 0) { socket.setSoLinger(linger > 0, linger); } super.bind(socket, params); }
public void bind(final Socket socket, final HttpParams params) throws IOException { if (socket == null) { throw new IllegalArgumentException("Socket may not be null"); } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } assertNotOpen(); socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params)); socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params)); int linger = HttpConnectionParams.getLinger(params); if (linger >= 0) { socket.setSoLinger(linger > 0, linger); } super.bind(socket, params); }
public void bind(final Socket socket, final HttpParams params) throws IOException { if (socket == null) { throw new IllegalArgumentException("Socket may not be null"); } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } assertNotOpen(); socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params)); socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params)); int linger = HttpConnectionParams.getLinger(params); if (linger >= 0) { socket.setSoLinger(linger > 0, linger); } super.bind(socket, params); }
public HttpResponse emulateRequest(HttpHost httpHost, HttpRequest httpRequest, HttpContext httpContext, RequestDirector requestDirector) throws HttpException, IOException { HttpResponse httpResponse = findResponse(httpRequest); if (httpResponse == null) { throw new RuntimeException("Unexpected call to execute, no pending responses are available. See Robolectric.addPendingResponse(). Request was: " + httpRequest.getRequestLine().getMethod() + " " + httpRequest.getRequestLine().getUri()); } else { HttpParams params = httpResponse.getParams(); if (HttpConnectionParams.getConnectionTimeout(params) < 0) { throw new ConnectTimeoutException("Socket is not connected"); } else if (HttpConnectionParams.getSoTimeout(params) < 0) { throw new ConnectTimeoutException("The operation timed out"); } } addRequestInfo(new HttpRequestInfo(httpRequest, httpHost, httpContext, requestDirector)); addHttpResponse(httpResponse); return httpResponse; }
@Test public void testCreateHttpClient_createWithDefaultSettings() { HttpClient client = HttpClientFactory.createHttpClient(); assertNotNull(client); assertEquals(HttpClientFactory.DEFAULT_CON_TIMEOUT, HttpConnectionParams.getConnectionTimeout(client.getParams())); assertEquals(HttpClientFactory.DEFAULT_SO_TIMEOUT, HttpConnectionParams.getSoTimeout(client.getParams())); }
@Test public void testCreateHttpClient_createWithCustomSettings() { HttpClient client = HttpClientFactory.createHttpClient(15000, 10000); assertNotNull(client); assertEquals(15000, HttpConnectionParams.getConnectionTimeout(client.getParams())); assertEquals(10000, HttpConnectionParams.getSoTimeout(client.getParams())); } }