List of usage examples for org.apache.commons.httpclient.params HttpConnectionManagerParams HttpConnectionManagerParams
HttpConnectionManagerParams
From source file:com.amazonaws.a2s.AmazonA2SClient.java
/** * Configure HttpClient with set of defaults as well as configuration * from AmazonA2SConfig instance/* w ww . ja v a2 s. c o m*/ * */ private HttpClient configureHttpClient() { /* Set http client parameters */ HttpClientParams httpClientParams = new HttpClientParams(); httpClientParams.setParameter(HttpMethodParams.USER_AGENT, config.getUserAgent()); httpClientParams.setParameter(HttpClientParams.RETRY_HANDLER, new HttpMethodRetryHandler() { public boolean retryMethod(HttpMethod method, IOException exception, int executionCount) { if (executionCount > 3) { log.debug("Maximum Number of Retry attempts reached, will not retry"); return false; } log.debug("Retrying request. Attempt " + executionCount); if (exception instanceof NoHttpResponseException) { log.debug("Retrying on NoHttpResponseException"); return true; } if (!method.isRequestSent()) { log.debug("Retrying on failed sent request"); return true; } return false; } }); /* Set host configuration */ HostConfiguration hostConfiguration = new HostConfiguration(); /* Set connection manager parameters */ HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams(); connectionManagerParams.setConnectionTimeout(50000); connectionManagerParams.setSoTimeout(50000); connectionManagerParams.setStaleCheckingEnabled(true); connectionManagerParams.setTcpNoDelay(true); connectionManagerParams.setMaxTotalConnections(3); connectionManagerParams.setMaxConnectionsPerHost(hostConfiguration, 3); /* Set connection manager */ MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.setParams(connectionManagerParams); /* Set http client */ httpClient = new HttpClient(httpClientParams, connectionManager); /* Set proxy if configured */ if (config.isSetProxyHost() && config.isSetProxyPort()) { log.info("Configuring Proxy. Proxy Host: " + config.getProxyHost() + "Proxy Port: " + config.getProxyPort()); hostConfiguration.setProxy(config.getProxyHost(), config.getProxyPort()); } httpClient.setHostConfiguration(hostConfiguration); return httpClient; }
From source file:oauth.OAuthTokenValidaterStubFactory.java
/** * This created httpclient pool that can be used to connect to external entity. This connection can be configured * via broker.xml by setting up the required http connection parameters. * * @return an instance of HttpClient that is configured with MultiThreadedHttpConnectionManager *///from w w w .j a va 2 s . c o m private HttpClient createHttpClient() { HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(Integer .parseInt(tokenValidationProperties.getProperty(UIConstants.MAXIMUM_HTTP_CONNECTION_PER_HOST))); params.setMaxTotalConnections( Integer.parseInt(tokenValidationProperties.getProperty(UIConstants.MAXIMUM_TOTAL_HTTP_CONNECTION))); HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.setParams(params); return new HttpClient(connectionManager); }
From source file:open.hyperion.nimblestorage.connection.NimbleStorageAPIFactory.java
/** * Initialize HTTP client/* w w w .j ava 2s . c o m*/ */ public void init() { _log.info("NimbleStorageDriver:NimbleStorageAPIFactory init enter"); _clientMap = new ConcurrentHashMap<String, NimbleStorageAPI>(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(_maxConnPerHost); params.setMaxTotalConnections(_maxConn); params.setTcpNoDelay(true); params.setConnectionTimeout(_connTimeout); params.setSoTimeout(_socketConnTimeout); _connectionManager = new MultiThreadedHttpConnectionManager(); _connectionManager.setParams(params); _connectionManager.closeIdleConnections(0); // close idle connections immediately HttpClient client = new HttpClient(_connectionManager); client.getParams().setConnectionManagerTimeout(_connManagerTimeout); client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() { @Override public boolean retryMethod(HttpMethod httpMethod, IOException e, int i) { return false; } }); Protocol.registerProtocol("https", new Protocol("https", new NonValidatingSocketFactory(), 8080)); }
From source file:open.hyperion.purestorage.connection.PureStorageAPIFactory.java
/** * Initialize HTTP client// ww w. j a va 2 s. com */ public void init() { _log.info("PureStorageDriver:PureStorageAPIFactory init enter"); _clientMap = new ConcurrentHashMap<String, PureStorageAPI>(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(_maxConnPerHost); params.setMaxTotalConnections(_maxConn); params.setTcpNoDelay(true); params.setConnectionTimeout(_connTimeout); params.setSoTimeout(_socketConnTimeout); _connectionManager = new MultiThreadedHttpConnectionManager(); _connectionManager.setParams(params); _connectionManager.closeIdleConnections(0); // close idle connections immediately HttpClient client = new HttpClient(_connectionManager); client.getParams().setConnectionManagerTimeout(_connManagerTimeout); client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new HttpMethodRetryHandler() { @Override public boolean retryMethod(HttpMethod httpMethod, IOException e, int i) { return false; } }); Protocol.registerProtocol("https", new Protocol("https", new NonValidatingSocketFactory(), 8080)); }
From source file:org.ala.harvester.BiocacheHarvester.java
public BiocacheHarvester() { int timeout = 3000; //msec hashTable = new Hashtable<String, String>(); hashTable.put("accept", "application/json"); mapper = new ObjectMapper(); mapper.getDeserializationConfig().set(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); HttpConnectionManagerParams params;//from ww w. j ava2s. c om MultiThreadedHttpConnectionManager m_connectionmgr = new MultiThreadedHttpConnectionManager(); params = new HttpConnectionManagerParams(); params.setConnectionTimeout(timeout); params.setSoTimeout(timeout); params.setDefaultMaxConnectionsPerHost(100); params.setMaxTotalConnections(3000); m_connectionmgr.setParams(params); httpClient = new HttpClient(m_connectionmgr); // Default is to search all records. The query can be modified using the -query argument to the main method. biocacheSearchQuery = "*:*"; }
From source file:org.alfresco.rest.api.tests.client.SharedHttpClientProvider.java
public SharedHttpClientProvider(String alfrescoUrl, int maxNumberOfConnections) { setAlfrescoUrl(alfrescoUrl);/*from ww w. j a v a2 s . c o m*/ // Initialize manager MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setMaxTotalConnections(maxNumberOfConnections); params.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, maxNumberOfConnections); // Create the client client = new HttpClient(manager); client.getParams().setAuthenticationPreemptive(true); }
From source file:org.apache.camel.component.http.HttpComponent.java
@Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { String addressUri = "http://" + remaining; if (uri.startsWith("https:")) { addressUri = "https://" + remaining; }//from w w w . j a va 2 s . c o m Map<String, Object> httpClientParameters = new HashMap<String, Object>(parameters); // must extract well known parameters before we create the endpoint // TODO cmueller: remove the "httpBindingRef" look up in Camel 3.0 HttpBinding binding = resolveAndRemoveReferenceParameter(parameters, "httpBindingRef", HttpBinding.class); if (binding == null) { // try without ref binding = resolveAndRemoveReferenceParameter(parameters, "httpBinding", HttpBinding.class); } String proxyHost = getAndRemoveParameter(parameters, "proxyHost", String.class); Integer proxyPort = getAndRemoveParameter(parameters, "proxyPort", Integer.class); String authMethodPriority = getAndRemoveParameter(parameters, "authMethodPriority", String.class); HeaderFilterStrategy headerFilterStrategy = resolveAndRemoveReferenceParameter(parameters, "headerFilterStrategy", HeaderFilterStrategy.class); UrlRewrite urlRewrite = resolveAndRemoveReferenceParameter(parameters, "urlRewrite", UrlRewrite.class); // http client can be configured from URI options HttpClientParams clientParams = new HttpClientParams(); IntrospectionSupport.setProperties(clientParams, parameters, "httpClient."); // validate that we could resolve all httpClient. parameters as this component is lenient validateParameters(uri, parameters, "httpClient."); // http client can be configured from URI options HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams(); // setup the httpConnectionManagerParams IntrospectionSupport.setProperties(connectionManagerParams, parameters, "httpConnectionManager."); validateParameters(uri, parameters, "httpConnectionManager."); // make sure the component httpConnectionManager is take effect HttpConnectionManager thisHttpConnectionManager = httpConnectionManager; if (thisHttpConnectionManager == null) { // only set the params on the new created http connection manager thisHttpConnectionManager = new MultiThreadedHttpConnectionManager(); thisHttpConnectionManager.setParams(connectionManagerParams); } // create the configurer to use for this endpoint (authMethods contains the used methods created by the configurer) final Set<AuthMethod> authMethods = new LinkedHashSet<AuthMethod>(); HttpClientConfigurer configurer = createHttpClientConfigurer(parameters, authMethods); addressUri = UnsafeUriCharactersEncoder.encodeHttpURI(addressUri); URI endpointUri = URISupport.createRemainingURI(new URI(addressUri), httpClientParameters); // create the endpoint and connectionManagerParams already be set HttpEndpoint endpoint = new HttpEndpoint(endpointUri.toString(), this, clientParams, thisHttpConnectionManager, configurer); if (headerFilterStrategy != null) { endpoint.setHeaderFilterStrategy(headerFilterStrategy); } else { setEndpointHeaderFilterStrategy(endpoint); } if (urlRewrite != null) { // let CamelContext deal with the lifecycle of the url rewrite // this ensures its being shutdown when Camel shutdown etc. getCamelContext().addService(urlRewrite); endpoint.setUrlRewrite(urlRewrite); } // prefer to use endpoint configured over component configured if (binding == null) { // fallback to component configured binding = getHttpBinding(); } if (binding != null) { endpoint.setBinding(binding); } if (proxyHost != null) { endpoint.setProxyHost(proxyHost); endpoint.setProxyPort(proxyPort); } else if (httpConfiguration != null) { endpoint.setProxyHost(httpConfiguration.getProxyHost()); endpoint.setProxyPort(httpConfiguration.getProxyPort()); } if (authMethodPriority != null) { endpoint.setAuthMethodPriority(authMethodPriority); } else if (httpConfiguration != null && httpConfiguration.getAuthMethodPriority() != null) { endpoint.setAuthMethodPriority(httpConfiguration.getAuthMethodPriority()); } else { // no explicit auth method priority configured, so use convention over configuration // and set priority based on auth method if (!authMethods.isEmpty()) { authMethodPriority = CollectionHelper.collectionAsCommaDelimitedString(authMethods); endpoint.setAuthMethodPriority(authMethodPriority); } } setProperties(endpoint, parameters); // restructure uri to be based on the parameters left as we dont want to include the Camel internal options URI httpUri = URISupport.createRemainingURI(new URI(addressUri), parameters); // validate http uri that end-user did not duplicate the http part that can be a common error String part = httpUri.getSchemeSpecificPart(); if (part != null) { part = part.toLowerCase(); if (part.startsWith("//http//") || part.startsWith("//https//") || part.startsWith("//http://") || part.startsWith("//https://")) { throw new ResolveEndpointFailedException(uri, "The uri part is not configured correctly. You have duplicated the http(s) protocol."); } } endpoint.setHttpUri(httpUri); return endpoint; }
From source file:org.apache.servicemix.http.HttpComponent.java
protected void doInit() throws Exception { // Load configuration configuration.setRootDir(context.getWorkspaceRoot()); configuration.setComponentName(context.getComponentName()); configuration.load();/*from ww w. j a va2s .co m*/ // Lookup keystoreManager and authenticationService if (configuration.getKeystoreManager() == null) { try { String name = configuration.getKeystoreManagerName(); Object km = context.getNamingContext().lookup(name); configuration.setKeystoreManager(km); } catch (Throwable e) { // ignore } } if (configuration.getAuthenticationService() == null) { try { String name = configuration.getAuthenticationServiceName(); Object as = context.getNamingContext().lookup(name); configuration.setAuthenticationService(as); } catch (Throwable e) { try { Class cl = Class .forName("org.apache.servicemix.jbi.security.auth.impl.JAASAuthenticationService"); configuration.setAuthenticationService(cl.newInstance()); } catch (Throwable t) { logger.warn("Unable to retrieve or create the authentication service"); } } } // Create client if (client == null) { connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); params.setDefaultMaxConnectionsPerHost(configuration.getMaxConnectionsPerHost()); params.setMaxTotalConnections(configuration.getMaxTotalConnections()); connectionManager.setParams(params); client = new HttpClient(connectionManager); } // Create connectionPool if (connectionPool == null) { connectionPool = createNewJettyClient(); } // Create serverManager if (configuration.isManaged()) { server = new ManagedContextManager(); } else { JettyContextManager jcm = new JettyContextManager(); jcm.setMBeanServer(context.getMBeanServer()); this.server = jcm; } server.setConfiguration(configuration); server.init(); server.start(); if (listener != null) { listener.setMBeanServer(context.getMBeanServer()); listener.setDomainAndContainer(context.getMBeanNames().getJmxDomainName(), containerNameFromObjectName()); } // Default initalization super.doInit(); }
From source file:org.apache.sling.pipes.JsonPipe.java
/** * Configure http client/*from ww w . java 2 s. c om*/ */ private void configureHttpClient() { HttpConnectionManager manager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); manager.setParams(params); client = new HttpClient(manager); client.getParams().setAuthenticationPreemptive(false); }
From source file:org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2ReferenceBindingProvider.java
public void start() { configContext = Axis2EngineIntegration.getAxisConfigurationContext(extensionPoints.getServiceDiscovery()); // Apply the configuration from any other policies if (isRampartRequired) { Axis2EngineIntegration.loadRampartModule(configContext); }//from w ww. j a v a 2s.c o m for (PolicyProvider pp : this.endpointReference.getPolicyProviders()) { pp.configureBinding(this); } try { Definition definition = wsBinding.getGeneratedWSDLDocument(); QName serviceQName = wsBinding.getService().getQName(); Port port = wsBinding.getPort(); if (port == null) { // service has multiple ports, select one port to use // TODO - it feels like there is much more to this than is // here at the moment as need to match with the service side // assuming that it's available Collection<Port> ports = wsBinding.getService().getPorts().values(); for (Port p : ports) { // look for a SOAP 1.1 port first if (p.getExtensibilityElements().get(0) instanceof SOAPAddress) { port = p; break; } } if (port == null) { // no SOAP 1.1 port available, so look for a SOAP 1.2 port for (Port p : ports) { if (p.getExtensibilityElements().get(0) instanceof SOAP12Address) { port = p; break; } } } } axisClientSideService = Axis2EngineIntegration.createClientSideAxisService(definition, serviceQName, port.getName(), new Options()); HttpClient httpClient = (HttpClient) configContext.getProperty(HTTPConstants.CACHED_HTTP_CLIENT); if (httpClient == null) { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams connectionManagerParams = new HttpConnectionManagerParams(); connectionManagerParams.setDefaultMaxConnectionsPerHost(2); connectionManagerParams.setTcpNoDelay(true); connectionManagerParams.setStaleCheckingEnabled(true); connectionManagerParams.setLinger(0); connectionManager.setParams(connectionManagerParams); httpClient = new HttpClient(connectionManager); configContext.setThreadPool(new ThreadPool(1, 5)); configContext.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE); configContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); } serviceClient = new ServiceClient(configContext, axisClientSideService); } catch (AxisFault e) { throw new RuntimeException(e); // TODO: better exception } }