List of usage examples for org.apache.http.impl.client DefaultHttpClient getConnectionManager
public synchronized final ClientConnectionManager getConnectionManager()
From source file:org.jclouds.http.apachehc.config.ApacheHCHttpCommandExecutorServiceModule.java
@Provides @Singleton//from www . j av a2 s . c om final HttpClient newDefaultHttpClient(ProxyConfig config, BasicHttpParams params, ClientConnectionManager cm) { DefaultHttpClient client = new DefaultHttpClient(cm, params); if (config.useSystem()) { ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner( client.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault()); client.setRoutePlanner(routePlanner); } return client; }
From source file:org.qi4j.library.http.AbstractSecureJettyTest.java
@Before public void beforeSecure() throws GeneralSecurityException, IOException { // Trust HTTP Client KeyStore truststore = KeyStore.getInstance("JCEKS"); truststore.load(new FileInputStream(TRUSTSTORE_FILE), KS_PASSWORD.toCharArray()); AllowAllHostnameVerifier verifier = new AllowAllHostnameVerifier(); DefaultHttpClient trustClient = new DefaultHttpClient(); SSLSocketFactory trustSslFactory = new SSLSocketFactory(truststore); trustSslFactory.setHostnameVerifier(verifier); SchemeRegistry trustSchemeRegistry = trustClient.getConnectionManager().getSchemeRegistry(); trustSchemeRegistry.unregister(HTTPS); trustSchemeRegistry.register(new Scheme(HTTPS, HTTPS_PORT, trustSslFactory)); trustHttpClient = trustClient;//w w w . j av a 2s .c om // Mutual HTTP Client KeyStore keystore = KeyStore.getInstance("JCEKS"); keystore.load(new FileInputStream(CLIENT_KEYSTORE_FILE), KS_PASSWORD.toCharArray()); DefaultHttpClient mutualClient = new DefaultHttpClient(); SSLSocketFactory mutualSslFactory = new SSLSocketFactory(keystore, KS_PASSWORD, truststore); mutualSslFactory.setHostnameVerifier(verifier); SchemeRegistry mutualSchemeRegistry = mutualClient.getConnectionManager().getSchemeRegistry(); mutualSchemeRegistry.unregister(HTTPS); mutualSchemeRegistry.register(new Scheme(HTTPS, HTTPS_PORT, mutualSslFactory)); mutualHttpClient = mutualClient; }
From source file:org.sonatype.nexus.error.reporting.NexusPRConnector.java
private static void configureProxy(final DefaultHttpClient httpClient, final RemoteStorageContext ctx) { final RemoteProxySettings rps = ctx.getRemoteProxySettings(); if (rps.isEnabled()) { 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.warn("Invalid non proxy host regex: {}", nonProxyHostRegex, e); }/*from w w w. ja v a2s. c om*/ } httpClient.setRoutePlanner(new NonProxyHostsAwareHttpRoutePlanner( httpClient.getConnectionManager().getSchemeRegistry(), nonProxyHostPatterns)); } configureAuthentication(httpClient, rps.getHostname(), rps.getPort(), rps.getProxyAuthentication()); } }
From source file:org.opencastproject.loadtest.engage.util.TrustedHttpClient.java
/** * Perform a request, and extract the realm and nonce values * //from www . j a va 2 s . c o m * @param request The request to execute in order to obtain the realm and nonce * @return A String[] containing the {realm, nonce} */ protected String[] getRealmAndNonce(HttpRequestBase request) { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpResponse response; try { response = httpClient.execute(request); } catch (IOException e) { httpClient.getConnectionManager().shutdown(); throw new TrustedHttpClientException(e); } Header[] headers = response.getHeaders("WWW-Authenticate"); if (headers == null || headers.length == 0) { logger.warn("URI {} does not support digest authentication", request.getURI()); httpClient.getConnectionManager().shutdown(); return null; } Header authRequiredResponseHeader = headers[0]; String nonce = null; String realm = null; for (HeaderElement element : authRequiredResponseHeader.getElements()) { if ("nonce".equals(element.getName())) { nonce = element.getValue(); } else if ("Digest realm".equals(element.getName())) { realm = element.getValue(); } } httpClient.getConnectionManager().shutdown(); return new String[] { realm, nonce }; }
From source file:net.carbon14.android.ProviderManager.java
public boolean reload() { if (!connectivityManager.getActiveNetworkInfo().isAvailable()) return false; DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet request = new HttpGet(PROVIDERS_URL); ResponseHandler<String> responseHandler = new BasicResponseHandler(); try {//w ww . j a va2 s . c o m String responseBody = httpClient.execute(request, responseHandler); httpClient.getConnectionManager().shutdown(); XStream xstream = new XStream(new DomDriver()); xstream.alias("provider", Provider.class); xstream.alias("providers", Provider[].class); Provider[] providersArray = (Provider[]) xstream.fromXML(responseBody); providers = new HashMap<String, Provider>(providersArray.length); for (Provider provider : providersArray) { providers.put(provider.getName(), provider); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return (providers != null); }
From source file:com.aliyun.oss.common.comm.HttpClientFactory.java
public HttpClient createHttpClient(ClientConfiguration config) { HttpParams httpClientParams = new BasicHttpParams(); HttpProtocolParams.setUserAgent(httpClientParams, config.getUserAgent()); HttpConnectionParams.setConnectionTimeout(httpClientParams, config.getConnectionTimeout()); HttpConnectionParams.setSoTimeout(httpClientParams, config.getSocketTimeout()); HttpConnectionParams.setStaleCheckingEnabled(httpClientParams, true); HttpConnectionParams.setTcpNoDelay(httpClientParams, true); PoolingClientConnectionManager connManager = createConnectionManager(config, httpClientParams); DefaultHttpClient httpClient = new DefaultHttpClient(connManager, httpClientParams); if (System.getProperty("com.aliyun.oss.disableCertChecking") != null) { Scheme sch = new Scheme("https", 443, getSSLSocketFactory()); httpClient.getConnectionManager().getSchemeRegistry().register(sch); }// w w w .j a va 2 s. c o m String proxyHost = config.getProxyHost(); int proxyPort = config.getProxyPort(); if (proxyHost != null && proxyPort > 0) { HttpHost proxy = new HttpHost(proxyHost, proxyPort); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); String proxyUsername = config.getProxyUsername(); String proxyPassword = config.getProxyPassword(); if (proxyUsername != null && proxyPassword != null) { String proxyDomain = config.getProxyDomain(); String proxyWorkstation = config.getProxyWorkstation(); httpClient.getCredentialsProvider().setCredentials(new AuthScope(proxyHost, proxyPort), new NTCredentials(proxyUsername, proxyPassword, proxyWorkstation, proxyDomain)); } } return httpClient; }
From source file:org.openqa.selenium.remote.internal.HttpClientFactory.java
public HttpClient getGridHttpClient(int connection_timeout, int socket_timeout) { DefaultHttpClient gridClient = new DefaultHttpClient(gridClientConnectionManager); gridClient.setRedirectStrategy(new MyRedirectHandler()); gridClient.setParams(getGridHttpParams(connection_timeout, socket_timeout)); gridClient.setRoutePlanner(getRoutePlanner(gridClient.getConnectionManager().getSchemeRegistry())); gridClient.getConnectionManager().closeIdleConnections(100, TimeUnit.MILLISECONDS); return gridClient; }
From source file:org.envirocar.analyse.AggregationAlgorithm.java
protected HttpClient createClient() throws IOException, KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException { DefaultHttpClient result = new DefaultHttpClient(); SchemeRegistry sr = result.getConnectionManager().getSchemeRegistry(); SSLSocketFactory sslsf = new SSLSocketFactory(new TrustStrategy() { @Override/*from w w w . j a va 2 s.c o m*/ public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { return true; } }, new AllowAllHostnameVerifier()); Scheme httpsScheme2 = new Scheme("https", 443, sslsf); sr.register(httpsScheme2); return result; }
From source file:org.mobicents.servlet.restcomm.fax.InterfaxService.java
private URI send(final Object message) throws Exception { final FaxRequest request = (FaxRequest) message; final String to = request.to(); final File file = request.file(); // Prepare the request. final DefaultHttpClient client = new DefaultHttpClient(); final HttpContext context = new BasicHttpContext(); final SSLSocketFactory sockets = new SSLSocketFactory(strategy); final Scheme scheme = new Scheme("https", 443, sockets); client.getConnectionManager().getSchemeRegistry().register(scheme); final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user, password); final HttpPost post = new HttpPost(url + to); final String mime = URLConnection.guessContentTypeFromName(file.getName()); final FileEntity entity = new FileEntity(file, mime); post.addHeader(new BasicScheme().authenticate(credentials, post, context)); post.setEntity(entity);/*from w w w . j av a 2 s .co m*/ // Handle the response. final HttpResponse response = client.execute(post, context); final StatusLine status = response.getStatusLine(); final int code = status.getStatusCode(); if (HttpStatus.SC_CREATED == code) { EntityUtils.consume(response.getEntity()); final Header[] headers = response.getHeaders(HttpHeaders.LOCATION); final Header location = headers[0]; final String resource = location.getValue(); return URI.create(resource); } else { final StringBuilder buffer = new StringBuilder(); buffer.append(code).append(" ").append(status.getReasonPhrase()); throw new FaxServiceException(buffer.toString()); } }
From source file:eu.clarin.cmdi.virtualcollectionregistry.service.impl.HttpResponseValidator.java
protected boolean checkValidityOfUri(URI uri) throws IOException { boolean result = false; DefaultHttpClient client = new DefaultHttpClient(); HttpContext ctx = new BasicHttpContext(); try {/*from w w w . j a v a 2 s. c o m*/ HttpResponse response = client.execute(new HttpGet(uri), ctx); status = response.getStatusLine(); result = status.getStatusCode() == 200; } finally { client.getConnectionManager().shutdown(); } return result; }