private void init(final HostConfiguration hostConfiguration) { // wrap all of the assignments in a synchronized block to avoid // having to negotiate the monitor for each method call synchronized (hostConfiguration) { try { if (hostConfiguration.host != null) { this.host = (HttpHost) hostConfiguration.host.clone(); } else { this.host = null; } if (hostConfiguration.proxyHost != null) { this.proxyHost = (ProxyHost) hostConfiguration.proxyHost.clone(); } else { this.proxyHost = null; } this.localAddress = hostConfiguration.getLocalAddress(); this.params = (HostParams)hostConfiguration.getParams().clone(); } catch (CloneNotSupportedException e) { throw new IllegalArgumentException("Host configuration could not be cloned"); } } }
this.connectMethod.getParams().setDefaults(this.hostConfiguration.getParams());
@SuppressWarnings( "unchecked" ) private boolean isNonProxyHost( HostConfiguration hostConfiguration ) { if( hostConfiguration == null || hostConfiguration.getHost() == null ) { return false; } Collection<Pattern> nonProxyHostPatterns = (Collection<Pattern>) hostConfiguration.getParams().getParameter( NON_PROXY_HOSTS_PATTERNS_KEY ); if( nonProxyHostPatterns != null ) { for ( Pattern hostPattern : nonProxyHostPatterns ) { if( hostPattern.matcher( hostConfiguration.getHost() ).matches() ) { return true; } } } return false; }
private void init(final HostConfiguration hostConfiguration) { // wrap all of the assignments in a synchronized block to avoid // having to negotiate the monitor for each method call synchronized (hostConfiguration) { try { if (hostConfiguration.host != null) { this.host = (HttpHost) hostConfiguration.host.clone(); } else { this.host = null; } if (hostConfiguration.proxyHost != null) { this.proxyHost = (ProxyHost) hostConfiguration.proxyHost.clone(); } else { this.proxyHost = null; } this.localAddress = hostConfiguration.getLocalAddress(); this.params = (HostParams)hostConfiguration.getParams().clone(); } catch (CloneNotSupportedException e) { throw new IllegalArgumentException("Host configuration could not be cloned"); } } }
private void init(final HostConfiguration hostConfiguration) { // wrap all of the assignments in a synchronized block to avoid // having to negotiate the monitor for each method call synchronized (hostConfiguration) { try { if (hostConfiguration.host != null) { this.host = (HttpHost) hostConfiguration.host.clone(); } else { this.host = null; } if (hostConfiguration.proxyHost != null) { this.proxyHost = (ProxyHost) hostConfiguration.proxyHost.clone(); } else { this.proxyHost = null; } this.localAddress = hostConfiguration.getLocalAddress(); this.params = (HostParams)hostConfiguration.getParams().clone(); } catch (CloneNotSupportedException e) { throw new IllegalArgumentException("Host configuration could not be cloned"); } } }
private void init(final HostConfiguration hostConfiguration) { // wrap all of the assignments in a synchronized block to avoid // having to negotiate the monitor for each method call synchronized (hostConfiguration) { try { if (hostConfiguration.host != null) { this.host = (HttpHost) hostConfiguration.host.clone(); } else { this.host = null; } if (hostConfiguration.proxyHost != null) { this.proxyHost = (ProxyHost) hostConfiguration.proxyHost.clone(); } else { this.proxyHost = null; } this.localAddress = hostConfiguration.getLocalAddress(); this.params = (HostParams)hostConfiguration.getParams().clone(); } catch (CloneNotSupportedException e) { throw new IllegalArgumentException("Host configuration could not be cloned"); } } }
private void init(final HostConfiguration hostConfiguration) { // wrap all of the assignments in a synchronized block to avoid // having to negotiate the monitor for each method call synchronized (hostConfiguration) { try { if (hostConfiguration.host != null) { this.host = (HttpHost) hostConfiguration.host.clone(); } else { this.host = null; } if (hostConfiguration.proxyHost != null) { this.proxyHost = (ProxyHost) hostConfiguration.proxyHost.clone(); } else { this.proxyHost = null; } this.localAddress = hostConfiguration.getLocalAddress(); this.params = (HostParams)hostConfiguration.getParams().clone(); } catch (CloneNotSupportedException e) { throw new IllegalArgumentException("Host configuration could not be cloned"); } } }
private void ensureClientInitialized() { if(configuration == null) throw new IllegalStateException("client must be initialized first."); if (client != null) return; client = new HttpClient(manager); HttpConnectionManager connectionManager = client.getHttpConnectionManager(); HttpConnectionManagerParams params = connectionManager.getParams(); params.setConnectionTimeout(configuration.getDefaultTimeout()); params.setSoTimeout(configuration.getDefaultTimeout()); params.setMaxTotalConnections(configuration.getMaxConnections()); HostConfiguration hostConf = client.getHostConfiguration(); List<Header> headers = new ArrayList<Header>(); headers.add(new Header("User-Agent", configuration.getUserAgent())); if (configuration.getAcceptHeader() != null) { headers.add(new Header("Accept", configuration.getAcceptHeader())); } headers.add(new Header("Accept-Language", "en-us,en-gb,en,*;q=0.3")); //TODO: this must become parametric. headers.add(new Header("Accept-Charset", "utf-8,iso-8859-1;q=0.7,*;q=0.5")); // headers.add(new Header("Accept-Encoding", "x-gzip, gzip")); hostConf.getParams().setParameter("http.default-headers", headers); }
protected void configureHttpClient() throws IOException, GeneralSecurityException { httpClient.getParams().setAuthenticationPreemptive(isAuthenticationPreemptive()); initCredentials(); initSocketFactory(); initProtocolIfNeeded(); if (httpConnectionManager != null) { httpClient.setHttpConnectionManager(httpConnectionManager); } List<Header> headers = getDefaultHeaders(); httpClient.getHostConfiguration().getParams().setParameter(HostParams.DEFAULT_HEADERS, headers); httpClient.getParams().setParameter(HttpClientParams.USER_AGENT, "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Ubuntu/11.04 Chromium/18.0.1025.151 Chrome/18.0.1025.151 Safari/535.19"); httpClient.getParams().setParameter(HttpClientParams.HTTP_CONTENT_CHARSET, "UTF-8"); httpClient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); httpClient.getParams().setConnectionManagerTimeout(connectionManagerTimeout); httpClient.getParams().setSoTimeout(soTimeout); if (connectionTimeout >= 0) { httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(connectionTimeout); } }
client.getHostConfiguration().getParams().setParameter("http.default-headers", headers); for (Header hd : headers) { log(hd.getName() + ": " + hd.getValue());
client.getHostConfiguration().getParams() .setParameter("http.default-headers", headers); for (Header hd : headers) {
this.connectMethod.getParams().setDefaults(this.hostConfiguration.getParams());
this.connectMethod.getParams().setDefaults(this.hostConfiguration.getParams());
this.connectMethod.getParams().setDefaults(this.hostConfiguration.getParams());
this.connectMethod.getParams().setDefaults(this.hostConfiguration.getParams());
this.connectMethod.getParams().setDefaults(this.hostConfiguration.getParams()); String agent = (String) getParams().getParameter(PARAM_DEFAULT_USER_AGENT_CONNECT_REQUESTS); if (agent != null) {
HostParams params = hostConfig.getParams(); if (params != null) params.setVirtualHost(hcs.getVirtualHost());
HostParams params = hostConfig.getParams(); if (params != null) params.setVirtualHost(hcs.getVirtualHost());