List of usage examples for org.apache.http.client HttpClient getParams
@Deprecated HttpParams getParams();
From source file:com.dropbox.client2.RESTUtility.java
/** * Updates the given client's proxy from the session. *///from ww w .jav a2 s . c om private static void updateClientProxy(HttpClient client, Session session) { ProxyInfo proxyInfo = session.getProxyInfo(); if (proxyInfo != null && proxyInfo.host != null && !proxyInfo.host.equals("")) { HttpHost proxy; if (proxyInfo.port < 0) { proxy = new HttpHost(proxyInfo.host); } else { proxy = new HttpHost(proxyInfo.host, proxyInfo.port); } client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } else { client.getParams().removeParameter(ConnRoutePNames.DEFAULT_PROXY); } }
From source file:org.soyatec.windowsazure.internal.util.HttpUtilities.java
/** * Get the HttpWebResponse with a HttpRequest. * /*from ww w . ja v a2s . co m*/ * @param request * @return HttpWebResponse * @throws Exception */ public static HttpWebResponse getResponse(HttpRequest request) throws Exception { HttpClient httpClient = createHttpClient(); HttpParams params = httpClient.getParams(); try { Long parseLong = Long.parseLong(request.getLastHeader(HeaderNames.Sotimeout).getValue()); request.removeHeader(request.getLastHeader(HeaderNames.Sotimeout)); // so timeout HttpConnectionParams.setConnectionTimeout(params, parseLong.intValue()); // connection timeout HttpConnectionParams.setSoTimeout(params, parseLong.intValue()); } catch (Exception e) { // Use default timeout setting... } try { if (request instanceof HttpUriRequest) { return new HttpWebResponse(httpClient.execute((HttpUriRequest) request)); } else { throw new IllegalArgumentException("Request is invalid"); } } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources // httpClient.getConnectionManager().shutdown(); } }
From source file:com.bright.json.JSonRequestor.java
public static String doRequest(String jsonReq, String myURL, List<Cookie> cookies) { try {//ww w . j ava2s . c om /* HttpClient httpclient = new DefaultHttpClient(); */ HttpClient httpclient = getNewHttpClient(); CookieStore cookieStore = new BasicCookieStore(); Cookie[] cookiearray = cookies.toArray(new Cookie[0]); cookieStore.addCookie(cookiearray[0]); HttpContext localContext = new BasicHttpContext(); localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); /* httpclient = WebClientDevWrapper.wrapClient(httpclient); */ httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY); HttpParams params = httpclient.getParams(); HttpConnectionParams.setConnectionTimeout(params, 1000); HttpConnectionParams.setSoTimeout(params, 1000); HttpPost httppost = new HttpPost(myURL); StringEntity stringEntity = new StringEntity(jsonReq); stringEntity.setContentType("application/json"); httppost.setEntity(stringEntity); System.out.println("executing request " + httppost.getRequestLine() + System.getProperty("line.separator") + jsonReq); HttpResponse response = httpclient.execute(httppost, localContext); System.out.println(response + "\n"); for (Cookie c : ((AbstractHttpClient) httpclient).getCookieStore().getCookies()) { System.out.println("\n Cookie: " + c.toString() + "\n"); } HttpEntity resEntity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (resEntity != null) { System.out.println("Response content length: " + resEntity.getContentLength()); System.out.println("Chunked?: " + resEntity.isChunked()); String message = new String(EntityUtils.toString(resEntity)); System.out.println(message); return message; } EntityUtils.consume(resEntity); } catch (Exception e) { e.printStackTrace(); return null; } return null; }
From source file:es.tsb.ltba.nomhad.example.ClientWithResponseHandler.java
private static DefaultHttpClient wrapClient(HttpClient base) { try {/*from w w w . java 2 s . com*/ SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = base.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", 443, ssf)); return new DefaultHttpClient(ccm, base.getParams()); } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:org.apache.stratos.cli.WebClientWrapper.java
public static HttpClient wrapClient(HttpClient base) { try {/* w w w . ja va 2 s .co m*/ SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx); ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = base.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", ssf, 443)); return new DefaultHttpClient(ccm, base.getParams()); } catch (Exception ex) { return null; } }
From source file:org.jboss.as.test.http.util.HttpClientUtils.java
/** * Returns https ready client./*from www . j av a 2 s . c o m*/ * * @param base * @return */ public static HttpClient wrapHttpsClient(HttpClient base) { try { SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = base.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", 443, ssf)); return new DefaultHttpClient(ccm, base.getParams()); } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:org.apache.camel.component.http4.ProxyHttpClientConfigurer.java
public void configureHttpClient(HttpClient client) { client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(host, port, scheme)); if (username != null && password != null) { Credentials defaultcreds;//from w ww.ja va 2s .c o m if (domain != null) { defaultcreds = new NTCredentials(username, password, ntHost, domain); } else { defaultcreds = new UsernamePasswordCredentials(username, password); } ((DefaultHttpClient) client).getCredentialsProvider().setCredentials(AuthScope.ANY, defaultcreds); } }
From source file:org.mahasen.ssl.SSLWrapper.java
/** * @param base//from ww w . java 2s . c om * @return */ public static HttpClient wrapClient(HttpClient base) { try { SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx); ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = base.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", ssf, 443)); return new DefaultHttpClient(ccm, base.getParams()); } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:es.tsb.ltba.nomhad.httpclient.NomhadHttpClient.java
/** * Authentication/* www. java 2s . co m*/ * * @param base * the client to be configured * @return the authentication-enabled client */ private static DefaultHttpClient wrapClient(HttpClient base) { try { SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = base.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", 443, ssf)); return new DefaultHttpClient(ccm, base.getParams()); } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:bad.robot.http.apache.matchers.HttpParameterMatcher.java
@Override protected boolean matchesSafely(HttpClient actual, Description mismatch) { Object parameter = actual.getParams().getParameter(this.parameter); mismatch.appendText(" actual ").appendValue(parameter != null ? parameter.toString() : "<null>"); return matcher.matches(parameter); }