List of usage examples for org.apache.http.client HttpClient getConnectionManager
@Deprecated ClientConnectionManager getConnectionManager();
From source file:models.Collection.java
public static RestResponse findByID(Long id, String token) throws IOException { RestResponse restResponse = new RestResponse(); //TODO insecure ssl hack HttpClient httpClient = new DefaultHttpClient(); SSLSocketFactory sf = (SSLSocketFactory) httpClient.getConnectionManager().getSchemeRegistry() .getScheme("https").getSocketFactory(); sf.setHostnameVerifier(new AllowAllHostnameVerifier()); HttpGet request = new HttpGet(Application.baseRestUrl + "/collections/" + id + "?expand=all"); request.setHeader("Accept", "application/json"); request.addHeader("Content-Type", "application/json"); request.addHeader("rest-dspace-token", token); HttpResponse httpResponse = httpClient.execute(request); JsonNode collNode = Json.parse(httpResponse.getEntity().getContent()); Collection collection = new Collection(); if (collNode.size() > 0) { collection = Collection.parseCollectionFromJSON(collNode); }//w w w. j av a2 s.co m restResponse.httpResponse = httpResponse; restResponse.endpoint = request.getURI().toString(); ObjectMapper mapper = new ObjectMapper(); String pretty = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(collection); restResponse.jsonString = pretty; restResponse.modelObject = collection; return restResponse; }
From source file:com.cloudhopper.httpclient.util.HttpClientUtil.java
/** * Quitely shuts down an HttpClient instance by shutting down its connection * manager and ignoring any errors that occur. * @param http The HttpClient to shutdown *//* w w w .j a v a 2s . c o m*/ static public void shutdownQuietly(HttpClient http) { if (http != null) { try { http.getConnectionManager().shutdown(); } catch (Exception ignore) { // do nothing } } }
From source file:com.futureplatforms.kirin.internal.attic.IOUtils.java
public static void closeHttpClient(HttpClient client) { if (client != null) { client.getConnectionManager().shutdown(); }//from w w w.j a v a2 s . c o m }
From source file:fr.liglab.adele.cilia.workbench.restmonitoring.utils.http.HttpHelper.java
public static String get(PlatformID platformID, String target) throws CiliaException { String url = getURL(platformID, target); HttpUriRequest httpRequest = new HttpGet(url); HttpClient httpClient = getClient(); ResponseHandler<String> responseHandler = new BasicResponseHandler(); try {//from w ww . j ava 2 s . c om String retval = httpClient.execute(httpRequest, responseHandler); httpClient.getConnectionManager().shutdown(); return retval; } catch (ConnectTimeoutException e) { httpClient.getConnectionManager().shutdown(); throw new CiliaException("Can't joint " + url + " before timeout (" + timeout + "ms)"); } catch (ClientProtocolException e) { httpClient.getConnectionManager().shutdown(); throw new CiliaException("Can't joint " + url, e); } catch (IOException e) { httpClient.getConnectionManager().shutdown(); throw new CiliaException("Can't joint " + url, e); } }
From source file:org.apache.camel.component.box.internal.BoxClientHelper.java
@SuppressWarnings("deprecation") public static CachedBoxClient createBoxClient(final BoxConfiguration configuration) { final String clientId = configuration.getClientId(); final String clientSecret = configuration.getClientSecret(); final IAuthSecureStorage authSecureStorage = configuration.getAuthSecureStorage(); final String userName = configuration.getUserName(); final String userPassword = configuration.getUserPassword(); if ((authSecureStorage == null && ObjectHelper.isEmpty(userPassword)) || ObjectHelper.isEmpty(userName) || ObjectHelper.isEmpty(clientId) || ObjectHelper.isEmpty(clientSecret)) { throw new IllegalArgumentException("Missing one or more required properties " + "clientId, clientSecret, userName and either authSecureStorage or userPassword"); }// w ww .ja va2s. c o m LOG.debug("Creating BoxClient for login:{}, client_id:{} ...", userName, clientId); // if set, use configured connection manager builder final BoxConnectionManagerBuilder connectionManagerBuilder = configuration.getConnectionManagerBuilder(); final BoxConnectionManagerBuilder connectionManager = connectionManagerBuilder != null ? connectionManagerBuilder : new BoxConnectionManagerBuilder(); // create REST client for BoxClient final ClientConnectionManager[] clientConnectionManager = new ClientConnectionManager[1]; final IBoxRESTClient restClient = new BoxRESTClient(connectionManager.build()) { @Override public HttpClient getRawHttpClient() { final HttpClient httpClient = super.getRawHttpClient(); clientConnectionManager[0] = httpClient.getConnectionManager(); // set custom HTTP params final Map<String, Object> configParams = configuration.getHttpParams(); if (configParams != null && !configParams.isEmpty()) { LOG.debug("Setting {} HTTP Params", configParams.size()); final HttpParams httpParams = httpClient.getParams(); for (Map.Entry<String, Object> param : configParams.entrySet()) { httpParams.setParameter(param.getKey(), param.getValue()); } } return httpClient; } }; final BoxClient boxClient = new BoxClient(clientId, clientSecret, null, null, restClient, configuration.getBoxConfig()); // enable OAuth auto-refresh boxClient.setAutoRefreshOAuth(true); // wrap the configured storage in a caching storage final CachingSecureStorage storage = new CachingSecureStorage(authSecureStorage); // set up a listener to notify secure storage and user provided listener, store it in configuration! final OAuthHelperListener listener = new OAuthHelperListener(storage, configuration.getRefreshListener()); boxClient.addOAuthRefreshListener(listener); final CachedBoxClient cachedBoxClient = new CachedBoxClient(boxClient, userName, clientId, storage, listener, clientConnectionManager); LOG.debug("BoxClient created {}", cachedBoxClient); return cachedBoxClient; }
From source file:org.sonatype.nexus.proxy.storage.remote.httpclient.HttpClientUtil.java
/** * Releases the current HTTP client (if any) and removes context objects. * * @param ctxPrefix context keys prefix// w ww . ja v a 2 s .c om * @param ctx remote repository context */ static void release(final String ctxPrefix, final RemoteStorageContext ctx) { if (ctx.hasContextObject(ctxPrefix + CTX_KEY_CLIENT)) { HttpClient httpClient = (HttpClient) ctx.getContextObject(ctxPrefix + CTX_KEY_CLIENT); httpClient.getConnectionManager().shutdown(); ctx.removeContextObject(ctxPrefix + CTX_KEY_CLIENT); } ctx.removeContextObject(ctxPrefix + CTX_KEY_S3_FLAG); ctx.putContextObject(ctxPrefix + CTX_KEY_NTLM_IS_IN_USE, Boolean.FALSE); }
From source file:com.cloudhopper.httpclient.util.HttpClientFactory.java
/** * Configures the HttpClient with an SSL TrustManager that will accept any * SSL server certificate. The server SSL certificate will not be verified. * This method creates a new Scheme for "https" that is setup for an SSL * context to uses an DoNotVerifySSLCertificateTrustManager instance. This * scheme will be registered with the HttpClient using the * getConnectionManager().getSchemeRegistry().register(https) method. * @param client The HttpClient to configure. *//*from w w w . j a va 2 s . c om*/ static public void configureWithNoSslCertificateVerification(HttpClient client) throws NoSuchAlgorithmException, KeyManagementException { // // create a new https scheme with no SSL verification // Scheme httpsScheme = SchemeFactory.createDoNotVerifyHttpsScheme(); // // register this new scheme on the https client // client.getConnectionManager().getSchemeRegistry().register(httpsScheme); }
From source file:org.ow2.proactive.scheduler.rest.utils.HttpUtility.java
public static void setInsecureAccess(HttpClient client) throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException { SSLSocketFactory socketFactory = new SSLSocketFactory(new RelaxedTrustStrategy(), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme https = new Scheme("https", 443, socketFactory); client.getConnectionManager().getSchemeRegistry().register(https); }
From source file:org.frameworkset.spi.remote.http.Client.java
private static void shutdownclient(HttpClient httpclient) { if (httpclient != null) httpclient.getConnectionManager().shutdown(); }
From source file:org.eclipse.lyo.testsuite.server.util.OSLCUtils.java
static public void setupLazySSLSupport(HttpClient httpClient) { ClientConnectionManager connManager = httpClient.getConnectionManager(); SchemeRegistry schemeRegistry = connManager.getSchemeRegistry(); schemeRegistry.unregister("https"); /** Create a trust manager that does not validate certificate chains */ TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) { /** Ignore Method Call */ }//from w w w .ja v a 2 s . c o m public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) { /** Ignore Method Call */ } public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } } }; SSLContext sc = null; try { sc = SSLContext.getInstance("SSL"); //$NON-NLS-1$ sc.init(null, trustAllCerts, new java.security.SecureRandom()); } catch (NoSuchAlgorithmException e) { /* Fail Silently */ } catch (KeyManagementException e) { /* Fail Silently */ } SSLSocketFactory sf = new SSLSocketFactory(sc); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme https = new Scheme("https", sf, 443); schemeRegistry.register(https); }