List of usage examples for org.apache.http.client.params HttpClientParams setCookiePolicy
public static void setCookiePolicy(final HttpParams params, final String cookiePolicy)
From source file:Main.java
public static DefaultHttpClient getDefaultHttpClient() { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); HttpParams params = new BasicHttpParams(); ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); DefaultHttpClient defaultHttpClient = new DefaultHttpClient(cm, params); HttpConnectionParams.setSoTimeout(defaultHttpClient.getParams(), SOCKET_TIME_OUT); HttpConnectionParams.setConnectionTimeout(defaultHttpClient.getParams(), CONNECTION_TIME_OUT); defaultHttpClient.getParams().setIntParameter(ClientPNames.MAX_REDIRECTS, 10); HttpClientParams.setCookiePolicy(defaultHttpClient.getParams(), CookiePolicy.BROWSER_COMPATIBILITY); HttpProtocolParams.setUserAgent(defaultHttpClient.getParams(), "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110628 Ubuntu/10.04 (lucid) Firefox/3.6.18"); defaultHttpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(3, true)); return defaultHttpClient; }
From source file:de.koczewski.maxapi.RequestExecutor.java
public RequestExecutor() { httpClient = WebClientDevWrapper.createClient(); // HttpProtocolParams.setUserAgent(httpClient.getParams(), // "Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"); HttpClientParams.setCookiePolicy(httpClient.getParams(), CookiePolicy.BROWSER_COMPATIBILITY); }
From source file:ilarkesto.integration.max.internet.RequestExecutor.java
public RequestExecutor(DefaultHttpClient httpClient) { this.httpClient = httpClient; // HttpProtocolParams.setUserAgent(httpClient.getParams(), // "Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"); HttpClientParams.setCookiePolicy(httpClient.getParams(), CookiePolicy.BROWSER_COMPATIBILITY); }
From source file:cn.keke.travelmix.HttpClientHelper.java
public static HttpClient getNewHttpClient() { try {//w ww . ja va 2s . co m SSLSocketFactory sf = new EasySSLSocketFactory(); // TODO test, if SyncBasicHttpParams is needed HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); HttpProtocolParams.setUseExpectContinue(params, false); HttpProtocolParams.setHttpElementCharset(params, HTTP.UTF_8); HttpConnectionParams.setConnectionTimeout(params, 10000); HttpConnectionParams.setSocketBufferSize(params, 8192); HttpConnectionParams.setLinger(params, 1); HttpConnectionParams.setStaleCheckingEnabled(params, false); HttpConnectionParams.setSoReuseaddr(params, true); HttpConnectionParams.setTcpNoDelay(params, true); HttpClientParams.setCookiePolicy(params, CookiePolicy.IGNORE_COOKIES); HttpClientParams.setAuthenticating(params, false); HttpClientParams.setRedirecting(params, false); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); registry.register(new Scheme("https", 443, sf)); ThreadSafeClientConnManager ccm = new ThreadSafeClientConnManager(registry, 20, TimeUnit.MINUTES); ccm.setMaxTotal(100); ccm.setDefaultMaxPerRoute(20); return new DefaultHttpClient(ccm, params); } catch (Exception e) { LOG.warn("Failed to create custom http client. Default http client is created", e); return new DefaultHttpClient(); } }
From source file:org.droidparts.http.worker.HttpClientWorker.java
public HttpClientWorker(String userAgent) { super(userAgent); httpClient = new DefaultHttpClient(); HttpParams params = httpClient.getParams(); HttpConnectionParams.setStaleCheckingEnabled(params, false); HttpClientParams.setRedirecting(params, false); HttpConnectionParams.setConnectionTimeout(params, SOCKET_OPERATION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, SOCKET_OPERATION_TIMEOUT); HttpConnectionParams.setSocketBufferSize(params, BUFFER_SIZE); HttpClientParams.setCookiePolicy(params, BROWSER_COMPATIBILITY); if (userAgent != null) { HttpProtocolParams.setUserAgent(params, userAgent); }//from w w w.j av a2 s . co m }
From source file:eu.masconsult.bgbanking.banks.sgexpress.SGExpressClient.java
/** * Configures the httpClient to connect to the URL provided. * //from ww w . jav a 2 s . co m * @param authToken */ private static DefaultHttpClient getHttpClient() { DefaultHttpClient httpClient = new DefaultHttpClient(); final HttpParams params = httpClient.getParams(); HttpConnectionParams.setConnectionTimeout(params, HTTP_REQUEST_TIMEOUT_MS); HttpConnectionParams.setSoTimeout(params, HTTP_REQUEST_TIMEOUT_MS); ConnManagerParams.setTimeout(params, HTTP_REQUEST_TIMEOUT_MS); HttpClientParams.setRedirecting(params, false); HttpClientParams.setCookiePolicy(params, CookiePolicy.BROWSER_COMPATIBILITY); httpClient.addRequestInterceptor(new DumpHeadersRequestInterceptor()); httpClient.addResponseInterceptor(new DumpHeadersResponseInterceptor()); httpClient.addResponseInterceptor(new CookieQuotesFixerResponseInterceptor()); return httpClient; }
From source file:org.eclipse.mylyn.commons.repositories.http.core.HttpUtil.java
public static void configureClient(AbstractHttpClient client, String userAgent) { HttpClientParams.setCookiePolicy(client.getParams(), CookiePolicy.BEST_MATCH); if (userAgent != null) { HttpProtocolParams.setUserAgent(client.getParams(), userAgent); }/*from ww w . java2 s . com*/ HttpProtocolParams.setUseExpectContinue(client.getParams(), true); client.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true); HttpConnectionParams.setConnectionTimeout(client.getParams(), CONNNECT_TIMEOUT); HttpConnectionParams.setSoTimeout(client.getParams(), SOCKET_TIMEOUT); //AuthParams.setCredentialCharset(client.getParams(), "UTF-8"); }
From source file:com.cloudbees.eclipse.core.util.Utils.java
/** * @param url/*from w w w . j a va2s . co m*/ * url to connec. Required to determine proxy settings if available. If <code>null</code> then proxy is not * configured for the client returned. * @return * @throws CloudBeesException */ public final static DefaultHttpClient getAPIClient(String url) throws CloudBeesException { DefaultHttpClient httpclient = new DefaultHttpClient(); try { HttpClientParams.setCookiePolicy(httpclient.getParams(), CookiePolicy.BROWSER_COMPATIBILITY); String version = null; if (CloudBeesCorePlugin.getDefault() != null) { version = CloudBeesCorePlugin.getDefault().getBundle().getVersion().toString(); } else { version = "n/a"; } HttpProtocolParams.setUserAgent(httpclient.getParams(), "CBEclipseToolkit/" + version); KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); CloudBeesCorePlugin plugin = CloudBeesCorePlugin.getDefault(); URL truststore; if (plugin == null) { //Outside the OSGI environment, try to open the stream from the current dir. truststore = new File("truststore").toURI().toURL(); } else { truststore = plugin.getBundle().getResource("truststore"); } InputStream instream = truststore.openStream(); try { trustStore.load(instream, "123456".toCharArray()); } finally { instream.close(); } TrustStrategy trustAllStrategy = new TrustStrategy() { @Override public boolean isTrusted(final X509Certificate[] chain, final String authType) throws CertificateException { return true; } }; SSLSocketFactory socketFactory = new SSLSocketFactory(SSLSocketFactory.TLS, null, null, trustStore, null, trustAllStrategy, SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); // Override https handling to use provided truststore @SuppressWarnings("deprecation") Scheme sch = new Scheme("https", socketFactory, 443); httpclient.getConnectionManager().getSchemeRegistry().register(sch); HttpParams params = httpclient.getParams(); //TODO Make configurable from the UI? HttpConnectionParams.setConnectionTimeout(params, 10000); HttpConnectionParams.setSoTimeout(params, 10000); if (CloudBeesCorePlugin.getDefault() != null) { // exclude proxy support when running outside eclipse IProxyService ps = CloudBeesCorePlugin.getDefault().getProxyService(); if (ps.isProxiesEnabled()) { IProxyData[] pr = ps.select(new URI(url)); //NOTE! For now we use just the first proxy settings with type HTTP or HTTPS to try out the connection. If configuration has more than 1 conf then for now this likely won't work! if (pr != null) { for (int i = 0; i < pr.length; i++) { IProxyData prd = pr[i]; if (IProxyData.HTTP_PROXY_TYPE.equals(prd.getType()) || IProxyData.HTTPS_PROXY_TYPE.equals(prd.getType())) { String proxyHost = prd.getHost(); int proxyPort = prd.getPort(); String proxyUser = prd.getUserId(); String proxyPass = prd.getPassword(); HttpHost proxy = new HttpHost(proxyHost, proxyPort); httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); if (prd.isRequiresAuthentication()) { List authpref = new ArrayList(); authpref.add(AuthPolicy.BASIC); AuthScope authScope = new AuthScope(proxyHost, proxyPort); httpclient.getCredentialsProvider().setCredentials(authScope, new UsernamePasswordCredentials(proxyUser, proxyPass)); } break; } } } } } /* httpclient.getHostConfiguration().setProxy(proxyHost,proxyPort); //if there are proxy credentials available, set those too Credentials proxyCredentials = null; String proxyUser = beesClientConfiguration.getProxyUser(); String proxyPassword = beesClientConfiguration.getProxyPassword(); if(proxyUser != null || proxyPassword != null) proxyCredentials = new UsernamePasswordCredentials(proxyUser, proxyPassword); if(proxyCredentials != null) client.getState().setProxyCredentials(AuthScope.ANY, proxyCredentials); */ return httpclient; } catch (Exception e) { throw new CloudBeesException("Error while initiating access to JSON APIs!", e); } }