List of usage examples for org.apache.http.client.params ClientPNames CONNECTION_MANAGER_FACTORY_CLASS_NAME
String CONNECTION_MANAGER_FACTORY_CLASS_NAME
To view the source code for org.apache.http.client.params ClientPNames CONNECTION_MANAGER_FACTORY_CLASS_NAME.
Click Source Link
From source file:com.android.providers.downloads.ui.network.SslHttpClient.java
private static HttpParams checkForInvalidParams(HttpParams params) { String className = (String) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME); if (className != null) { throw new IllegalArgumentException( "Don't try to pass ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME parameter. We use our own connection manager factory anyway..."); }/*w w w .j a v a 2s .com*/ return params; }
From source file:com.netflix.http4.NFHttpClient.java
void init() { HttpParams params = getParams();//from w w w. j a v a 2s .c o m HttpProtocolParams.setContentCharset(params, "UTF-8"); params.setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, ThreadSafeClientConnManager.class.getName()); // set up default headers List<Header> defaultHeaders = new ArrayList<Header>(); defaultHeaders.add(new BasicHeader("Netflix.NFHttpClient.Version", "1.0")); defaultHeaders.add(new BasicHeader("X-netflix-httpclientname", name)); params.setParameter(ClientPNames.DEFAULT_HEADERS, defaultHeaders); connPoolCleaner = new ConnectionPoolCleaner(name, this.getConnectionManager()); this.retriesProperty = DynamicPropertyFactory.getInstance() .getIntProperty(this.name + ".nfhttpclient" + ".retries", 3); this.sleepTimeFactorMsProperty = DynamicPropertyFactory.getInstance() .getIntProperty(this.name + ".nfhttpclient" + ".sleepTimeFactorMs", 10); setHttpRequestRetryHandler(new NFHttpMethodRetryHandler(this.name, this.retriesProperty.get(), false, this.sleepTimeFactorMsProperty.get())); tracer = Monitors.newTimer(EXECUTE_TRACER, TimeUnit.MILLISECONDS); Monitors.registerObject(name, this); }
From source file:org.obiba.opal.rest.client.magma.OpalJavaClient.java
private void createClient() { log.info("Connecting to Opal: {}", opalURI); DefaultHttpClient httpClient = new DefaultHttpClient(); if (keyStore == null) httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials); httpClient.getParams().setParameter(ClientPNames.HANDLE_AUTHENTICATION, Boolean.TRUE); httpClient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, Collections.singletonList(OpalAuth.CREDENTIALS_HEADER)); httpClient.getParams().setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, OpalClientConnectionManagerFactory.class.getName()); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, soTimeout); httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(DEFAULT_MAX_ATTEMPT, false)); httpClient.getAuthSchemes().register(OpalAuth.CREDENTIALS_HEADER, new OpalAuthScheme.Factory()); try {//w w w .j a v a 2 s . com httpClient.getConnectionManager().getSchemeRegistry() .register(new Scheme("https", HTTPS_PORT, getSocketFactory())); } catch (NoSuchAlgorithmException | KeyManagementException e) { throw new RuntimeException(e); } client = enableCaching(httpClient); ctx = new BasicHttpContext(); ctx.setAttribute(ClientContext.COOKIE_STORE, new BasicCookieStore()); }
From source file:org.eclipse.mylyn.commons.http.HttpUtil.java
public static void configureHttpClient(AbstractHttpClient client, String userAgent) { client.getParams().setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, SingleConnectionManagerFactory.class.getName()); client.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true); HttpProtocolParams.setUserAgent(client.getParams(), getUserAgent(userAgent)); // client.getParams().setLongParameter(AllClientPNames.CONNECTION_TIMEOUT, CONNNECT_TIMEOUT_INTERVAL); // TODO consider setting this as the default //client.getParams().setCookiePolicy(CookiePolicy.RFC_2109); configureHttpClientConnectionManager(client); }
From source file:anhttpclient.impl.DefaultWebBrowser.java
/** * Allows to set {@link HttpParams}//from ww w . j a v a 2s. com * Will take effect only if httpClient is initialized inside DefaultWebBrowser * @param httpParams {@link HttpParams} to set. */ public void setHttpParams(HttpParams httpParams) { this.httpParams = httpParams; if (this.httpParams != null && this.httpParams.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME) == null) { this.httpParams.setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, clientConnectionFactoryClassName); } if (httpClient != null && httpClient instanceof DefaultHttpClient) { synchronized (this) { httpClient = null; this.initialized = false; } } }
From source file:org.vietspider.net.client.impl.AnonymousHttpClient.java
@Override protected ClientConnectionManager createClientConnectionManager() { SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager connManager = null; HttpParams params = getParams();/*from www . j a va 2 s . c o m*/ ClientConnectionManagerFactory factory = null; // Try first getting the factory directly as an object. factory = (ClientConnectionManagerFactory) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY); if (factory == null) { // then try getting its class name. String className = (String) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME); if (className != null) { try { Class<?> clazz = Class.forName(className); factory = (ClientConnectionManagerFactory) clazz.newInstance(); } catch (ClassNotFoundException ex) { throw new IllegalStateException("Invalid class name: " + className); } catch (IllegalAccessException ex) { throw new IllegalAccessError(ex.getMessage()); } catch (InstantiationException ex) { throw new InstantiationError(ex.getMessage()); } } } if (factory != null) { connManager = factory.newInstance(params, registry); } else { connManager = new SingleClientConnManager(getParams(), registry); } return connManager; }
From source file:anhttpclient.impl.DefaultWebBrowser.java
private HttpParams getBasicHttpParams() { HttpParams params = new BasicHttpParams(); params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, HTTP.UTF_8); params.setParameter(CoreProtocolPNames.USER_AGENT, WebBrowserConstants.DEFAULT_USER_AGENT); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout); params.setParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false); params.setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, clientConnectionFactoryClassName); /*Custom parameter to be used in implementation of {@link ClientConnectionManagerFactory}*/ params.setParameter(ClientConnectionManagerFactoryImpl.THREAD_SAFE_CONNECTION_MANAGER, this.threadSafe); return params; }
From source file:org.jets3t.service.utils.RestUtils.java
public static HttpClient initHttpsConnection(final JetS3tRequestAuthorizer requestAuthorizer, Jets3tProperties jets3tProperties, String userAgentDescription, CredentialsProvider credentialsProvider) { // Configure HttpClient properties based on Jets3t Properties. HttpParams params = createDefaultHttpParams(); params.setParameter(Jets3tProperties.JETS3T_PROPERTIES_ID, jets3tProperties); params.setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, jets3tProperties.getStringProperty( ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, ConnManagerFactory.class.getName())); HttpConnectionParams.setConnectionTimeout(params, jets3tProperties.getIntProperty("httpclient.connection-timeout-ms", 60000)); HttpConnectionParams.setSoTimeout(params, jets3tProperties.getIntProperty("httpclient.socket-timeout-ms", 60000)); HttpConnectionParams.setStaleCheckingEnabled(params, jets3tProperties.getBoolProperty("httpclient.stale-checking-enabled", true)); // Connection properties to take advantage of S3 window scaling. if (jets3tProperties.containsKey("httpclient.socket-receive-buffer")) { HttpConnectionParams.setSocketBufferSize(params, jets3tProperties.getIntProperty("httpclient.socket-receive-buffer", 0)); }/*ww w . j a v a 2s. c om*/ HttpConnectionParams.setTcpNoDelay(params, true); // Set user agent string. String userAgent = jets3tProperties.getStringProperty("httpclient.useragent", null); if (userAgent == null) { userAgent = ServiceUtils.getUserAgentDescription(userAgentDescription); } if (log.isDebugEnabled()) { log.debug("Setting user agent string: " + userAgent); } HttpProtocolParams.setUserAgent(params, userAgent); boolean expectContinue = jets3tProperties.getBoolProperty("http.protocol.expect-continue", true); HttpProtocolParams.setUseExpectContinue(params, expectContinue); long connectionManagerTimeout = jets3tProperties.getLongProperty("httpclient.connection-manager-timeout", 0); ConnManagerParams.setTimeout(params, connectionManagerTimeout); DefaultHttpClient httpClient = wrapClient(params); httpClient.setHttpRequestRetryHandler(new JetS3tRetryHandler( jets3tProperties.getIntProperty("httpclient.retry-max", 5), requestAuthorizer)); if (credentialsProvider != null) { if (log.isDebugEnabled()) { log.debug("Using credentials provider class: " + credentialsProvider.getClass().getName()); } httpClient.setCredentialsProvider(credentialsProvider); if (jets3tProperties.getBoolProperty("httpclient.authentication-preemptive", false)) { // Add as the very first interceptor in the protocol chain httpClient.addRequestInterceptor(new PreemptiveInterceptor(), 0); } } return httpClient; }
From source file:org.jets3t.service.utils.RestUtils.java
/** * Initialises, or re-initialises, the underlying HttpConnectionManager and * HttpClient objects a service will use to communicate with an AWS service. * If proxy settings are specified in this service's {@link Jets3tProperties} object, * these settings will also be passed on to the underlying objects. *///from www .j a v a 2 s .co m public static HttpClient initHttpConnection(final JetS3tRequestAuthorizer requestAuthorizer, Jets3tProperties jets3tProperties, String userAgentDescription, CredentialsProvider credentialsProvider) { // Configure HttpClient properties based on Jets3t Properties. HttpParams params = createDefaultHttpParams(); params.setParameter(Jets3tProperties.JETS3T_PROPERTIES_ID, jets3tProperties); params.setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, jets3tProperties.getStringProperty( ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME, ConnManagerFactory.class.getName())); HttpConnectionParams.setConnectionTimeout(params, jets3tProperties.getIntProperty("httpclient.connection-timeout-ms", 60000)); HttpConnectionParams.setSoTimeout(params, jets3tProperties.getIntProperty("httpclient.socket-timeout-ms", 60000)); HttpConnectionParams.setStaleCheckingEnabled(params, jets3tProperties.getBoolProperty("httpclient.stale-checking-enabled", true)); // Connection properties to take advantage of S3 window scaling. if (jets3tProperties.containsKey("httpclient.socket-receive-buffer")) { HttpConnectionParams.setSocketBufferSize(params, jets3tProperties.getIntProperty("httpclient.socket-receive-buffer", 0)); } HttpConnectionParams.setTcpNoDelay(params, true); // Set user agent string. String userAgent = jets3tProperties.getStringProperty("httpclient.useragent", null); if (userAgent == null) { userAgent = ServiceUtils.getUserAgentDescription(userAgentDescription); } if (log.isDebugEnabled()) { log.debug("Setting user agent string: " + userAgent); } HttpProtocolParams.setUserAgent(params, userAgent); boolean expectContinue = jets3tProperties.getBoolProperty("http.protocol.expect-continue", true); HttpProtocolParams.setUseExpectContinue(params, expectContinue); long connectionManagerTimeout = jets3tProperties.getLongProperty("httpclient.connection-manager-timeout", 0); ConnManagerParams.setTimeout(params, connectionManagerTimeout); DefaultHttpClient httpClient = new DefaultHttpClient(params); httpClient.setHttpRequestRetryHandler(new JetS3tRetryHandler( jets3tProperties.getIntProperty("httpclient.retry-max", 5), requestAuthorizer)); if (credentialsProvider != null) { if (log.isDebugEnabled()) { log.debug("Using credentials provider class: " + credentialsProvider.getClass().getName()); } httpClient.setCredentialsProvider(credentialsProvider); if (jets3tProperties.getBoolProperty("httpclient.authentication-preemptive", false)) { // Add as the very first interceptor in the protocol chain httpClient.addRequestInterceptor(new PreemptiveInterceptor(), 0); } } return httpClient; }
From source file:org.apache.http.impl.client.AbstractHttpClient.java
protected ClientConnectionManager createClientConnectionManager() { final SchemeRegistry registry = SchemeRegistryFactory.createDefault(); ClientConnectionManager connManager = null; final HttpParams params = getParams(); ClientConnectionManagerFactory factory = null; final String className = (String) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME); if (className != null) { try {//from w w w . ja v a 2 s. com final Class<?> clazz = Class.forName(className); factory = (ClientConnectionManagerFactory) clazz.newInstance(); } catch (final ClassNotFoundException ex) { throw new IllegalStateException("Invalid class name: " + className); } catch (final IllegalAccessException ex) { throw new IllegalAccessError(ex.getMessage()); } catch (final InstantiationException ex) { throw new InstantiationError(ex.getMessage()); } } if (factory != null) { connManager = factory.newInstance(params, registry); } else { connManager = new BasicClientConnectionManager(registry); } return connManager; }