Java Code Examples for org.apache.http.params.HttpParams#setBooleanParameter()
The following examples show how to use
org.apache.http.params.HttpParams#setBooleanParameter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GetClient.java From javabase with Apache License 2.0 | 6 votes |
/** * 此处解释下MaxtTotal和DefaultMaxPerRoute的区别: * 1、MaxtTotal是整个池子的大小; * 2、DefaultMaxPerRoute是根据连接到的主机对MaxTotal的一个细分;比如: * MaxtTotal=400 DefaultMaxPerRoute=200 * 而我只连接到http://sishuok.com时,到这个主机的并发最多只有200;而不是400; * 而我连接到http://sishuok.com 和 http://qq.com时,到每个主机的并发最多只有200;即加起来是400(但不能超过400);所以起作用的设置是DefaultMaxPerRoute。 */ public HttpParams getHttpParams() { HttpParams params = new BasicHttpParams(); // 设置连接超时时间 Integer CONNECTION_TIMEOUT = 2 * 1000; // 设置请求超时2秒钟 根据业务调整 Integer SO_TIMEOUT = 2 * 1000; // 设置等待数据超时时间2秒钟 根据业务调整 // 定义了当从ClientConnectionManager中检索ManagedClientConnection实例时使用的毫秒级的超时时间 // 这个参数期望得到一个java.lang.Long类型的值。如果这个参数没有被设置,默认等于CONNECTION_TIMEOUT,因此一定要设置 Long CONN_MANAGER_TIMEOUT = 500L; // 该值就是连接不够用的时候等待超时时间,一定要设置,而且不能太大 () params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, SO_TIMEOUT); params.setLongParameter(ClientPNames.CONN_MANAGER_TIMEOUT, CONN_MANAGER_TIMEOUT); // 在提交请求之前 测试连接是否可用 params.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, true); return params; }
Example 2
Source File: HTTPClientManager.java From ForgePE with GNU Affero General Public License v3.0 | 6 votes |
private HTTPClientManager() { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); ConnManagerParams.setTimeout(params, 30000); params.setBooleanParameter("http.protocol.expect-continue", false); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); SSLSocketFactory sslSocketFactory; try { registry.register(new Scheme("https", NoCertSSLSocketFactory.createDefault(), 443)); } catch (Exception e) { Log.e("MCPE_ssl", "Couldn\\'t create SSLSocketFactory"); } ClientConnectionManager manager = new ThreadSafeClientConnManager(params, registry); this.mHTTPClient = new DefaultHttpClient(manager, params); }
Example 3
Source File: AsyncHttpClient.java From MiBandDecompiled with Apache License 2.0 | 5 votes |
public void setEnableRedirects(boolean flag, boolean flag1, boolean flag2) { HttpParams httpparams = c.getParams(); boolean flag3; if (!flag1) { flag3 = true; } else { flag3 = false; } httpparams.setBooleanParameter("http.protocol.reject-relative-redirect", flag3); c.getParams().setBooleanParameter("http.protocol.allow-circular-redirects", flag2); c.setRedirectHandler(new w(flag)); }
Example 4
Source File: EasyHttpClient.java From mobilecloud-15 with Apache License 2.0 | 5 votes |
/** * Function that creates a ClientConnectionManager which can handle http and https. * In case of https self signed or invalid certificates will be accepted. */ @Override protected ClientConnectionManager createClientConnectionManager() { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); params.setBooleanParameter("http.protocol.expect-continue", false); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), HTTP_PORT)); registry.register(new Scheme("https", new EasySSLSocketFactory(), HTTPS_PORT)); ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry); return manager; }
Example 5
Source File: VmApiProxyDelegate.java From appengine-java-vm-runtime with Apache License 2.0 | 4 votes |
/** * Create an HTTP post request suitable for sending to the API server. * * @param environment The current VMApiProxyEnvironment * @param packageName The API call package * @param methodName The API call method * @param requestData The POST payload. * @param timeoutMs The timeout for this request * @return an HttpPost object to send to the API. */ // static HttpPost createRequest(VmApiProxyEnvironment environment, String packageName, String methodName, byte[] requestData, int timeoutMs) { // Wrap the payload in a RemoteApi Request. RemoteApiPb.Request remoteRequest = new RemoteApiPb.Request(); remoteRequest.setServiceName(packageName); remoteRequest.setMethod(methodName); remoteRequest.setRequestId(environment.getTicket()); remoteRequest.setRequestAsBytes(requestData); HttpPost request = new HttpPost("http://" + environment.getServer() + REQUEST_ENDPOINT); request.setHeader(RPC_STUB_ID_HEADER, REQUEST_STUB_ID); request.setHeader(RPC_METHOD_HEADER, REQUEST_STUB_METHOD); // Set TCP connection timeouts. HttpParams params = new BasicHttpParams(); params.setLongParameter(ConnManagerPNames.TIMEOUT, timeoutMs + ADDITIONAL_HTTP_TIMEOUT_BUFFER_MS); params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeoutMs + ADDITIONAL_HTTP_TIMEOUT_BUFFER_MS); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeoutMs + ADDITIONAL_HTTP_TIMEOUT_BUFFER_MS); // Performance tweaks. params.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, Boolean.TRUE); params.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, Boolean.FALSE); request.setParams(params); // The request deadline can be overwritten by the environment, read deadline if available. Double deadline = (Double) (environment.getAttributes().get(API_DEADLINE_KEY)); if (deadline == null) { request.setHeader(RPC_DEADLINE_HEADER, Double.toString(TimeUnit.SECONDS.convert(timeoutMs, TimeUnit.MILLISECONDS))); } else { request.setHeader(RPC_DEADLINE_HEADER, Double.toString(deadline)); } // If the incoming request has a dapper trace header: set it on outgoing API calls // so they are tied to the original request. Object dapperHeader = environment.getAttributes() .get(VmApiProxyEnvironment.AttributeMapping.DAPPER_ID.attributeKey); if (dapperHeader instanceof String) { request.setHeader( VmApiProxyEnvironment.AttributeMapping.DAPPER_ID.headerKey, (String) dapperHeader); } // If the incoming request has a Cloud trace header: set it on outgoing API calls // so they are tied to the original request. // TODO(user): For now, this uses the incoming span id - use the one from the active span. Object traceHeader = environment.getAttributes() .get(VmApiProxyEnvironment.AttributeMapping.CLOUD_TRACE_CONTEXT.attributeKey); if (traceHeader instanceof String) { request.setHeader( VmApiProxyEnvironment.AttributeMapping.CLOUD_TRACE_CONTEXT.headerKey, (String) traceHeader); } ByteArrayEntity postPayload = new ByteArrayEntity(remoteRequest.toByteArray(), ContentType.APPLICATION_OCTET_STREAM); postPayload.setChunked(false); request.setEntity(postPayload); return request; }
Example 6
Source File: ApacheHttpTransport.java From google-http-java-client with Apache License 2.0 | 3 votes |
/** * Constructor that allows an alternative Apache HTTP client to be used. * * <p>Note that a few settings are overridden: * * <ul> * <li>HTTP version is set to 1.1 using {@link HttpProtocolParams#setVersion} with {@link * HttpVersion#HTTP_1_1}. * <li>Redirects are disabled using {@link ClientPNames#HANDLE_REDIRECTS}. * <li>{@link ConnManagerParams#setTimeout} and {@link * HttpConnectionParams#setConnectionTimeout} are set on each request based on {@link * HttpRequest#getConnectTimeout()}. * <li>{@link HttpConnectionParams#setSoTimeout} is set on each request based on {@link * HttpRequest#getReadTimeout()}. * </ul> * * <p>Use {@link Builder} for a more user-friendly way to modify the HTTP client options. * * @param httpClient Apache HTTP client to use * @since 1.6 */ public ApacheHttpTransport(HttpClient httpClient) { this.httpClient = httpClient; HttpParams params = httpClient.getParams(); if (params == null) { params = newDefaultHttpClient().getParams(); } HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false); }