List of usage examples for org.apache.http.impl.client DefaultHttpClient getParams
public synchronized final HttpParams getParams()
From source file:com.nineash.hutsync.client.NetworkUtilities.java
/** * Configures the httpClient to connect to the URL provided. */// ww w . j a v a2 s . co m public static DefaultHttpClient getHttpClient(Context context) { initNetworkUtilities(context); DefaultHttpClient httpClient = new HutHttpClient(context); 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); return httpClient; }
From source file:lucee.commons.net.http.httpclient4.HTTPEngine4Impl.java
public static void setProxy(DefaultHttpClient client, HttpUriRequest request, ProxyData proxy) { // set Proxy/*from w w w. j a v a 2s. co m*/ if (ProxyDataImpl.isValid(proxy)) { HttpHost host = new HttpHost(proxy.getServer(), proxy.getPort() == -1 ? 80 : proxy.getPort()); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, host); if (!StringUtil.isEmpty(proxy.getUsername())) { client.getCredentialsProvider().setCredentials(new AuthScope(proxy.getServer(), proxy.getPort()), new UsernamePasswordCredentials(proxy.getUsername(), proxy.getPassword())); } } }
From source file:com.sun.jersey.client.apache4.ApacheHttpClient4.java
/** * Create a default Apache HTTP client handler. * * @param cc ClientConfig instance. Might be null. * * @return a default Apache HTTP client handler. *//*from ww w . j av a 2 s. co m*/ private static ApacheHttpClient4Handler createDefaultClientHandler(final ClientConfig cc) { Object connectionManager = null; Object httpParams = null; if (cc != null) { connectionManager = cc.getProperties().get(ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER); if (connectionManager != null) { if (!(connectionManager instanceof ClientConnectionManager)) { Logger.getLogger(ApacheHttpClient4.class.getName()).log(Level.WARNING, "Ignoring value of property " + ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER + " (" + connectionManager.getClass().getName() + ") - not instance of org.apache.http.conn.ClientConnectionManager."); connectionManager = null; } } httpParams = cc.getProperties().get(ApacheHttpClient4Config.PROPERTY_HTTP_PARAMS); if (httpParams != null) { if (!(httpParams instanceof HttpParams)) { Logger.getLogger(ApacheHttpClient4.class.getName()).log(Level.WARNING, "Ignoring value of property " + ApacheHttpClient4Config.PROPERTY_HTTP_PARAMS + " (" + httpParams.getClass().getName() + ") - not instance of org.apache.http.params.HttpParams."); httpParams = null; } } } final DefaultHttpClient client = new DefaultHttpClient((ClientConnectionManager) connectionManager, (HttpParams) httpParams); CookieStore cookieStore = null; boolean preemptiveBasicAuth = false; if (cc != null) { for (Map.Entry<String, Object> entry : cc.getProperties().entrySet()) client.getParams().setParameter(entry.getKey(), entry.getValue()); if (cc.getPropertyAsFeature(ApacheHttpClient4Config.PROPERTY_DISABLE_COOKIES)) client.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES); Object credentialsProvider = cc.getProperty(ApacheHttpClient4Config.PROPERTY_CREDENTIALS_PROVIDER); if (credentialsProvider != null && (credentialsProvider instanceof CredentialsProvider)) { client.setCredentialsProvider((CredentialsProvider) credentialsProvider); } final Object proxyUri = cc.getProperties().get(ApacheHttpClient4Config.PROPERTY_PROXY_URI); if (proxyUri != null) { final URI u = getProxyUri(proxyUri); final HttpHost proxy = new HttpHost(u.getHost(), u.getPort(), u.getScheme()); if (cc.getProperties().containsKey(ApacheHttpClient4Config.PROPERTY_PROXY_USERNAME) && cc.getProperties().containsKey(ApacheHttpClient4Config.PROPERTY_PROXY_PASSWORD)) { client.getCredentialsProvider().setCredentials(new AuthScope(u.getHost(), u.getPort()), new UsernamePasswordCredentials( cc.getProperty(ApacheHttpClient4Config.PROPERTY_PROXY_USERNAME).toString(), cc.getProperty(ApacheHttpClient4Config.PROPERTY_PROXY_PASSWORD).toString())); } client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } preemptiveBasicAuth = cc .getPropertyAsFeature(ApacheHttpClient4Config.PROPERTY_PREEMPTIVE_BASIC_AUTHENTICATION); } if (client.getParams().getParameter(ClientPNames.COOKIE_POLICY) == null || !client.getParams() .getParameter(ClientPNames.COOKIE_POLICY).equals(CookiePolicy.IGNORE_COOKIES)) { cookieStore = new BasicCookieStore(); client.setCookieStore(cookieStore); } return new ApacheHttpClient4Handler(client, cookieStore, preemptiveBasicAuth); }
From source file:org.sonatype.nexus.proxy.storage.remote.httpclient.HttpClientUtil.java
private static void configureProxy(final DefaultHttpClient httpClient, final String ctxPrefix, final RemoteStorageContext ctx, final Logger logger) { final RemoteProxySettings rps = ctx.getRemoteProxySettings(); if (rps.isEnabled()) { logger(logger).info("... proxy setup with host '{}'", rps.getHostname()); final HttpHost proxy = new HttpHost(rps.getHostname(), rps.getPort()); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); // check if we have non-proxy hosts if (rps.getNonProxyHosts() != null && !rps.getNonProxyHosts().isEmpty()) { final Set<Pattern> nonProxyHostPatterns = new HashSet<Pattern>(rps.getNonProxyHosts().size()); for (String nonProxyHostRegex : rps.getNonProxyHosts()) { try { nonProxyHostPatterns.add(Pattern.compile(nonProxyHostRegex, Pattern.CASE_INSENSITIVE)); } catch (PatternSyntaxException e) { logger(logger).warn("Invalid non proxy host regex: {}", nonProxyHostRegex, e); }//from w ww . j av a2s .co m } httpClient.setRoutePlanner(new NonProxyHostsAwareHttpRoutePlanner( httpClient.getConnectionManager().getSchemeRegistry(), nonProxyHostPatterns)); } configureAuthentication(httpClient, ctxPrefix, ctx, rps.getProxyAuthentication(), logger, "proxy "); if (rps.getProxyAuthentication() != null) { if (ctx.getRemoteAuthenticationSettings() != null && (ctx.getRemoteAuthenticationSettings() instanceof NtlmRemoteAuthenticationSettings)) { logger(logger).warn("... Apache Commons HttpClient 3.x is unable to use NTLM auth scheme\n" + " for BOTH server side and proxy side authentication!\n" + " You MUST reconfigure server side auth and use BASIC/DIGEST scheme\n" + " if you have to use NTLM proxy, otherwise it will not work!\n" + " *** SERVER SIDE AUTH OVERRIDDEN"); } } } }
From source file:ca.ualberta.cmput301w13t11.FoodBook.model.ServerClient.java
/** * Gets a thread safe client - that is, a client which can be used in a multithreaded * program and protects against certain errors that exist even in single threaded programs. * @return A Object of type DefaultHttpClient which will *//* w w w.j a v a 2 s . c o m*/ public static DefaultHttpClient getThreadSafeClient() { DefaultHttpClient client = new DefaultHttpClient(); ClientConnectionManager manager = client.getConnectionManager(); HttpParams params = client.getParams(); client = new DefaultHttpClient(new ThreadSafeClientConnManager(params, manager.getSchemeRegistry()), params); return client; }
From source file:org.wso2.carbon.dynamic.client.web.proxy.util.DCRProxyUtils.java
public static DefaultHttpClient getHttpsClient() { DefaultHttpClient httpClient = new DefaultHttpClient(); // Setup the HTTPS settings to accept any certificate. HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; SchemeRegistry registry = new SchemeRegistry(); SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier); registry.register(new Scheme(Constants.RemoteServiceProperties.DYNAMIC_CLIENT_SERVICE_PROTOCOL, socketFactory, DCRProxyUtils.getServerHTTPSPort())); SingleClientConnManager mgr = new SingleClientConnManager(httpClient.getParams(), registry); httpClient = new DefaultHttpClient(mgr, httpClient.getParams()); // Set verifier HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); return httpClient; }
From source file:com.redhat.rcm.version.util.InputUtils.java
private static void setupClient() throws VManException { if (client == null) { SSLSocketFactory sslSocketFactory; try {//from w w w . j av a 2 s. c o m sslSocketFactory = new SSLSocketFactory(SSLSocketFactory.TLS, null, null, trustKs, null, new TrustSelfSignedStrategy(), SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); // sslSocketFactory = // new SSLSocketFactory( SSLSocketFactory.TLS, null, null, trustKs, null, null, // SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER ); } catch (final KeyManagementException e) { logger.error("Failed to setup SSL socket factory: {}", e, e.getMessage()); throw new VManException("Failed to setup SSL socket factory: %s", e, e.getMessage()); } catch (final UnrecoverableKeyException e) { logger.error("Failed to setup SSL socket factory: {}", e, e.getMessage()); throw new VManException("Failed to setup SSL socket factory: %s", e, e.getMessage()); } catch (final NoSuchAlgorithmException e) { logger.error("Failed to setup SSL socket factory: {}", e, e.getMessage()); throw new VManException("Failed to setup SSL socket factory: %s", e, e.getMessage()); } catch (final KeyStoreException e) { logger.error("Failed to setup SSL socket factory: {}", e, e.getMessage()); throw new VManException("Failed to setup SSL socket factory: %s", e, e.getMessage()); } final ThreadSafeClientConnManager ccm = new ThreadSafeClientConnManager(); ccm.getSchemeRegistry().register(new Scheme("https", 443, sslSocketFactory)); final DefaultHttpClient hc = new DefaultHttpClient(ccm); hc.setRedirectStrategy(new DefaultRedirectStrategy()); final String proxyHost = System.getProperty("http.proxyHost"); final int proxyPort = Integer.parseInt(System.getProperty("http.proxyPort", "-1")); if (proxyHost != null && proxyPort > 0) { final HttpHost proxy = new HttpHost(proxyHost, proxyPort); hc.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy); } client = hc; } }
From source file:piuk.MyRemoteWallet.java
private static String postURL(String request, String urlParameters) throws Exception { if (urlParameters.length() > 0) { urlParameters += "&"; }//from w w w . j a v a 2s . c om urlParameters += "api_code=" + getApiCode(); DefaultHttpClient client = new DefaultHttpClient(); HttpConnectionParams.setConnectionTimeout(client.getParams(), 180000); HttpConnectionParams.setSoTimeout(client.getParams(), 180000); final HttpPost httpPost = new HttpPost(request); httpPost.setEntity(new StringEntity(urlParameters, "application/x-www-form-urlencoded", "UTF-8")); final HttpResponse response = client.execute(httpPost); if (response.getStatusLine().getStatusCode() != 200) { throw new Exception("Invalid HTTP Response code " + response.getStatusLine().getStatusCode() + " " + IOUtils.toString(response.getEntity().getContent())); } String responseString = IOUtils.toString(response.getEntity().getContent(), "UTF-8"); return responseString; }
From source file:org.xdi.oxauth.BaseTest.java
public static DefaultHttpClient createHttpClient(HostnameVerifierType p_verifierType) { if (p_verifierType != null && p_verifierType != HostnameVerifierType.DEFAULT) { switch (p_verifierType) { case ALLOW_ALL: HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; DefaultHttpClient client = new DefaultHttpClient(); SchemeRegistry registry = new SchemeRegistry(); SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier); registry.register(new Scheme("https", socketFactory, 443)); SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry); // Set verifier HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); return new DefaultHttpClient(mgr, client.getParams()); case DEFAULT: return new DefaultHttpClient(); }/* ww w. j av a 2 s . c o m*/ } return new DefaultHttpClient(); }
From source file:org.wso2.carbon.dynamic.client.web.app.registration.util.RemoteDCRClient.java
private static DefaultHttpClient getHTTPSClient() { DefaultHttpClient httpClient = new DefaultHttpClient(); // Setup the HTTPS settings to accept any certificate. HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; SchemeRegistry registry = new SchemeRegistry(); SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory(); socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier); registry.register(new Scheme( DynamicClientWebAppRegistrationConstants.RemoteServiceProperties.DYNAMIC_CLIENT_SERVICE_PROTOCOL, socketFactory, getServerHTTPSPort())); SingleClientConnManager mgr = new SingleClientConnManager(httpClient.getParams(), registry); httpClient = new DefaultHttpClient(mgr, httpClient.getParams()); // Set verifier HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); return httpClient; }