int timeout = HttpConnectionParams.getConnectionTimeout(params);
int timeout = HttpConnectionParams.getConnectionTimeout(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 connTimeout = HttpConnectionParams.getConnectionTimeout(params); int soTimeout = HttpConnectionParams.getSoTimeout(params);
public int getConnectionTimeout() { return HttpConnectionParams.getConnectionTimeout(params); }
public int getConnectTimeout() { return HttpConnectionParams.getConnectionTimeout(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); }
@Override public Socket connectSocket(Socket socket, InetSocketAddress remoteAddress, InetSocketAddress localAddress, HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException { int connTimeout = HttpConnectionParams.getConnectionTimeout(params); // int soTimeout = HttpConnectionParams.getSoTimeout(params) try { // socket.setSoTimeout(soTimeout) socket.connect(new AFUNIXSocketAddress(socketFile), connTimeout); // socket.connect(new AFUNIXSocketAddress(socketFile)) } catch (SocketTimeoutException e) { throw new ConnectTimeoutException("Connect to '" + socketFile + "' timed out"); } return socket; }
@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); }
/** * Get the timeout in for establishing an HTTP connection. * @return timeout in milliseconds. */ public int getTimeout() { return HttpConnectionParams.getConnectionTimeout( super.getClient().getParams() ); }
/** * Get the timeout in for establishing an HTTP connection. * @return timeout in milliseconds. */ public int getTimeout() { return HttpConnectionParams.getConnectionTimeout( super.getClient().getParams() ); }
/** * Get the connectiion manager timeout value. * This is defined by the parameter {@code ClientPNames.CONN_MANAGER_TIMEOUT}. * Failing that it uses the parameter {@code CoreConnectionPNames.CONNECTION_TIMEOUT} * which defaults to 0 if not defined. * * @since 4.2 * @return the timeout value */ public static long getConnectionManagerTimeout(final HttpParams params) { Args.notNull(params, "HTTP parameters"); final Long timeout = (Long) params.getParameter(ClientPNames.CONN_MANAGER_TIMEOUT); if (timeout != null) { return timeout.longValue(); } return HttpConnectionParams.getConnectionTimeout(params); }
/** * Get the connectiion manager timeout value. * This is defined by the parameter {@code ClientPNames.CONN_MANAGER_TIMEOUT}. * Failing that it uses the parameter {@code CoreConnectionPNames.CONNECTION_TIMEOUT} * which defaults to 0 if not defined. * * @since 4.2 * @return the timeout value */ public static long getConnectionManagerTimeout(final HttpParams params) { Args.notNull(params, "HTTP parameters"); final Long timeout = (Long) params.getParameter(ClientPNames.CONN_MANAGER_TIMEOUT); if (timeout != null) { return timeout.longValue(); } return HttpConnectionParams.getConnectionTimeout(params); }
/** * Get the connectiion manager timeout value. * This is defined by the parameter {@code ClientPNames.CONN_MANAGER_TIMEOUT}. * Failing that it uses the parameter {@code CoreConnectionPNames.CONNECTION_TIMEOUT} * which defaults to 0 if not defined. * * @since 4.2 * @return the timeout value */ public static long getConnectionManagerTimeout(final HttpParams params) { Args.notNull(params, "HTTP parameters"); final Long timeout = (Long) params.getParameter(ClientPNames.CONN_MANAGER_TIMEOUT); if (timeout != null) { return timeout.longValue(); } return HttpConnectionParams.getConnectionTimeout(params); }
/** * Get the connectiion manager timeout value. * This is defined by the parameter {@code ClientPNames.CONN_MANAGER_TIMEOUT}. * Failing that it uses the parameter {@code CoreConnectionPNames.CONNECTION_TIMEOUT} * which defaults to 0 if not defined. * * @since 4.2 * @return the timeout value */ public static long getConnectionManagerTimeout(final HttpParams params) { Args.notNull(params, "HTTP parameters"); final Long timeout = (Long) params.getParameter(ClientPNames.CONN_MANAGER_TIMEOUT); if (timeout != null) { return timeout.longValue(); } return HttpConnectionParams.getConnectionTimeout(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())); } }