List of usage examples for org.apache.http.params HttpParams setIntParameter
HttpParams setIntParameter(String str, int i);
From source file:org.openrepose.core.services.httpclient.impl.HttpConnectionPoolProvider.java
public static HttpClient genClient(PoolType poolConf) { PoolingClientConnectionManager cm = new PoolingClientConnectionManager(); cm.setDefaultMaxPerRoute(poolConf.getHttpConnManagerMaxPerRoute()); cm.setMaxTotal(poolConf.getHttpConnManagerMaxTotal()); //Set all the params up front, instead of mutating them? Maybe this matters HttpParams params = new BasicHttpParams(); params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES); params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, poolConf.getHttpSocketTimeout()); params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, poolConf.getHttpConnectionTimeout()); params.setParameter(CoreConnectionPNames.TCP_NODELAY, poolConf.isHttpTcpNodelay()); params.setParameter(CoreConnectionPNames.MAX_HEADER_COUNT, poolConf.getHttpConnectionMaxHeaderCount()); params.setParameter(CoreConnectionPNames.MAX_LINE_LENGTH, poolConf.getHttpConnectionMaxLineLength()); params.setParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, poolConf.getHttpSocketBufferSize()); params.setBooleanParameter(CHUNKED_ENCODING_PARAM, poolConf.isChunkedEncoding()); final String uuid = UUID.randomUUID().toString(); params.setParameter(CLIENT_INSTANCE_ID, uuid); //Pass in the params and the connection manager DefaultHttpClient client = new DefaultHttpClient(cm, params); SSLContext sslContext = ProxyUtilities.getTrustingSslContext(); SSLSocketFactory ssf = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); SchemeRegistry registry = cm.getSchemeRegistry(); Scheme scheme = new Scheme("https", DEFAULT_HTTPS_PORT, ssf); registry.register(scheme);//from w w w .j a va2 s . co m client.setKeepAliveStrategy(new ConnectionKeepAliveWithTimeoutStrategy(poolConf.getKeepaliveTimeout())); LOG.info("HTTP connection pool {} with instance id {} has been created", poolConf.getId(), uuid); return client; }
From source file:org.apache.abdera2.common.protocol.RequestHelper.java
public static HttpUriRequest createRequest(String method, String uri, HttpEntity entity, RequestOptions options) {/*from w ww .ja v a2 s. c o m*/ if (method == null) return null; if (options == null) options = createAtomDefaultRequestOptions().get(); Method m = Method.get(method); Method actual = null; HttpUriRequest httpMethod = null; if (options.isUsePostOverride() && !nopostoveride.contains(m)) { actual = m; m = Method.POST; } if (m == GET) httpMethod = new HttpGet(uri); else if (m == POST) { httpMethod = new HttpPost(uri); if (entity != null) ((HttpPost) httpMethod).setEntity(entity); } else if (m == PUT) { httpMethod = new HttpPut(uri); if (entity != null) ((HttpPut) httpMethod).setEntity(entity); } else if (m == DELETE) httpMethod = new HttpDelete(uri); else if (m == HEAD) httpMethod = new HttpHead(uri); else if (m == OPTIONS) httpMethod = new HttpOptions(uri); else if (m == TRACE) httpMethod = new HttpTrace(uri); // else if (m == PATCH) // httpMethod = new ExtensionRequest(m.name(),uri,entity); else httpMethod = new ExtensionRequest(m.name(), uri, entity); if (actual != null) { httpMethod.addHeader("X-HTTP-Method-Override", actual.name()); } initHeaders(options, httpMethod); HttpParams params = httpMethod.getParams(); if (!options.isUseExpectContinue()) { params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); } else { if (options.getWaitForContinue() > -1) params.setIntParameter(CoreProtocolPNames.WAIT_FOR_CONTINUE, options.getWaitForContinue()); } if (!(httpMethod instanceof HttpEntityEnclosingRequest)) params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, options.isFollowRedirects()); return httpMethod; }
From source file:com.basho.riak.client.util.ClientUtils.java
/** * Construct a new {@link HttpClient} instance given a {@link RiakConfig}. * /*from w w w. j av a 2 s. c o m*/ * @param config * {@link RiakConfig} containing HttpClient configuration * specifics. * @return A new {@link HttpClient} */ public static HttpClient newHttpClient(RiakConfig config) { HttpClient http = config.getHttpClient(); ClientConnectionManager m; if (http == null) { m = new ThreadSafeClientConnManager(); if (config.getMaxConnections() != null) { ((ThreadSafeClientConnManager) m).setMaxTotal(config.getMaxConnections()); ((ThreadSafeClientConnManager) m).setDefaultMaxPerRoute(config.getMaxConnections()); } http = new DefaultHttpClient(m); if (config.getRetryHandler() != null) { ((DefaultHttpClient) http).setHttpRequestRetryHandler(config.getRetryHandler()); } } else { m = http.getConnectionManager(); } HttpParams cp = http.getParams(); if (config.getTimeout() != null) { cp.setIntParameter(AllClientPNames.CONNECTION_TIMEOUT, config.getTimeout()); cp.setIntParameter(AllClientPNames.SO_TIMEOUT, config.getTimeout()); } return http; }
From source file:com.google.apphosting.vmruntime.VmApiProxyDelegate.java
/** * 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./*from ww w .j av a 2 s . c o m*/ * @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; }
From source file:com.basho.riak.client.http.util.ClientUtils.java
/** * Construct a new {@link HttpClient} instance given a {@link RiakConfig}. * // w w w . j av a 2 s. c om * @param config * {@link RiakConfig} containing HttpClient configuration * specifics. * @return A new {@link HttpClient} */ public static HttpClient newHttpClient(RiakConfig config) { HttpClient http = config.getHttpClient(); ClientConnectionManager m; if (http == null) { m = new PoolingClientConnectionManager(); if (config.getMaxConnections() != null) { ((PoolingClientConnectionManager) m).setMaxTotal(config.getMaxConnections()); ((PoolingClientConnectionManager) m).setDefaultMaxPerRoute(config.getMaxConnections()); } http = new DefaultHttpClient(m); if (config.getRetryHandler() != null) { ((DefaultHttpClient) http).setHttpRequestRetryHandler(config.getRetryHandler()); } } HttpParams cp = http.getParams(); if (config.getTimeout() != null) { cp.setIntParameter(AllClientPNames.CONNECTION_TIMEOUT, config.getTimeout()); cp.setIntParameter(AllClientPNames.SO_TIMEOUT, config.getTimeout()); } return http; }
From source file:eu.sisob.uma.api.crawler4j.crawler.PageFetcher.java
public synchronized static void startConnectionMonitorThread() { if (connectionMonitorThread == null) { HttpParams params = new BasicHttpParams(); HttpProtocolParamBean paramsBean = new HttpProtocolParamBean(params); paramsBean.setVersion(HttpVersion.HTTP_1_1); paramsBean.setContentCharset("UTF-8"); paramsBean.setUseExpectContinue(false); params.setParameter("http.useragent", Configurations.getStringProperty("fetcher.user_agent", "crawler4j (http://code.google.com/p/crawler4j/)")); params.setIntParameter("http.socket.timeout", Configurations.getIntProperty("fetcher.socket_timeout", 20000)); params.setIntParameter("http.connection.timeout", Configurations.getIntProperty("fetcher.connection_timeout", 30000)); params.setBooleanParameter("http.protocol.handle-redirects", false); ConnPerRouteBean connPerRouteBean = new ConnPerRouteBean(); connPerRouteBean/*from w w w .j av a 2 s . co m*/ .setDefaultMaxPerRoute(Configurations.getIntProperty("fetcher.max_connections_per_host", 100)); ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRouteBean); ConnManagerParams.setMaxTotalConnections(params, Configurations.getIntProperty("fetcher.max_total_connections", 100)); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); if (Configurations.getBooleanProperty("fetcher.crawl_https", false)) { schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); } connectionManager = new ThreadSafeClientConnManager(params, schemeRegistry); ProjectLogger.LOGGER.setLevel(Level.INFO); httpclient = new DefaultHttpClient(connectionManager, params); connectionMonitorThread = new IdleConnectionMonitorThread(connectionManager); } connectionMonitorThread.start(); }
From source file:org.hydracache.server.httpd.HttpParamsFactory.java
public HttpParams create() { HttpParams httpParams = new BasicHttpParams(); httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, socketTimeout); httpParams.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, socketBufferSize); httpParams.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false); httpParams.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true); httpParams.setParameter(CoreProtocolPNames.ORIGIN_SERVER, ORIGIN_SERVER_NAME); return httpParams; }
From source file:cz.cvut.jirutjak.fastimport.droid.utils.ExtraKeyStoreHttpClientFactory.java
public HttpClient createHttpClient() { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", createAdditionalCertsSSLSocketFactory(), 443)); HttpParams params = new BasicHttpParams(); params.setIntParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, DEFAULT_MAX_TOTAL_CONNECTIONS); params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(DEFAULT_MAX_CONNECTIONS_PER_ROUTE)); ThreadSafeClientConnManager connManager = new ThreadSafeClientConnManager(params, schemeRegistry); return new DefaultHttpClient(connManager, params); }
From source file:org.siddhiesb.transport.passthru.config.BaseConfiguration.java
protected HttpParams buildHttpParams() { HttpParams params = new BasicHttpParams(); params.setIntParameter(HttpConnectionParams.SO_TIMEOUT, conf.getIntProperty(HttpConnectionParams.SO_TIMEOUT, 60000)) .setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, conf.getIntProperty(HttpConnectionParams.CONNECTION_TIMEOUT, 0)) .setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, conf.getIntProperty(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024)) .setParameter(HttpProtocolParams.ORIGIN_SERVER, conf.getStringProperty(HttpProtocolParams.ORIGIN_SERVER, "WSO2-PassThrough-HTTP")) .setParameter(HttpProtocolParams.USER_AGENT, conf.getStringProperty(HttpProtocolParams.USER_AGENT, "Synapse-PT-HttpComponents-NIO")); return params; }
From source file:niproxy.NiProxy.java
/** * Setups a monitoring http proxy and starts a non blocking listening * service based on a {@link NiProxyConfig}. This is based on the Apache * Software Foundation's example code "Basic non-blocking HTTP server" that * can be found from http://hc.apache.org/httpcomponents-core-ga/examples.html. *//*from w w w . j av a2s . c o m*/ public NiProxy() { HttpParams params = new SyncBasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, NiProxyConfig.getHttpConnectionTimeout()) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true); HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] { new ResponseDate(), new ResponseServer(), new ResponseContent(), new ResponseConnControl() }); AsyncNHttpServiceHandler handler = new AsyncNHttpServiceHandler(httpproc, new DefaultHttpResponseFactory(), new DefaultConnectionReuseStrategy(), params); // Set up request handlers NHttpRequestHandlerRegistry registry = new NHttpRequestHandlerRegistry(); registry.register("*", NiProxyMonitor.get()); handler.setHandlerResolver(registry); // Provide an event logger handler.setEventListener(new EventLogger()); IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch(handler, params); try { logger.info("Setting up " + NiProxyConfig.getIOReactorWorkersCount() + " IOReactor workers"); ListeningIOReactor ioReactor = new DefaultListeningIOReactor(NiProxyConfig.getIOReactorWorkersCount(), params); String host = NiProxyConfig.getNiProxyHost(); int port = NiProxyConfig.getNiProxyPort(); logger.info("Listening for connections at " + host + ":" + port); ioReactor.listen(new InetSocketAddress(host, port)); logger.info("NiProxy set up done. Launching event dispatch..."); ioReactor.execute(ioEventDispatch); } catch (Exception e) { logger.error("I/O reactor was interrupted. Exception: " + e); e.printStackTrace(); } logger.info("NiProxy server shutdown."); }