List of usage examples for org.apache.http.params BasicHttpParams setParameter
public HttpParams setParameter(String str, Object obj)
From source file:com.rackspacecloud.client.service_registry.Client.java
public Client(String username, String apiKey, String region, String apiUrl) { AuthClient authClient = new AuthClient(new DefaultHttpClient() { protected HttpParams createHttpParams() { BasicHttpParams params = new BasicHttpParams(); org.apache.http.params.HttpConnectionParams.setSoTimeout(params, 10000); params.setParameter("http.socket.timeout", 10000); return params; }/*from w w w . jav a 2 s. c o m*/ @Override protected ClientConnectionManager createClientConnectionManager() { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); return new ThreadSafeClientConnManager(createHttpParams(), schemeRegistry); } }, username, apiKey, region); this.services = new ServicesClient(authClient, apiUrl); this.configuration = new ConfigurationClient(authClient, apiUrl); this.events = new EventsClient(authClient, apiUrl); this.account = new AccountClient(authClient, apiUrl); }
From source file:com.proofpoint.http.client.ApacheHttpClient.java
public ApacheHttpClient(HttpClientConfig config, Set<? extends HttpRequestFilter> requestFilters) { Preconditions.checkNotNull(config, "config is null"); Preconditions.checkNotNull(requestFilters, "requestFilters is null"); PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(); connectionManager.setMaxTotal(config.getMaxConnections()); connectionManager.setDefaultMaxPerRoute(config.getMaxConnectionsPerServer()); BasicHttpParams httpParams = new BasicHttpParams(); httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, Ints.checkedCast(config.getReadTimeout().toMillis())); httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, Ints.checkedCast(config.getConnectTimeout().toMillis())); httpParams.setParameter(CoreConnectionPNames.SO_LINGER, 0); // do we need this? DefaultHttpClient defaultHttpClient = new DefaultHttpClient(connectionManager, httpParams); defaultHttpClient.setKeepAliveStrategy(new FixedIntervalKeepAliveStrategy(config.getKeepAliveInterval())); defaultHttpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); this.httpClient = defaultHttpClient; this.requestFilters = ImmutableList.copyOf(requestFilters); }
From source file:com.janoz.usenet.processors.impl.WebbasedProcessor.java
public WebbasedProcessor() { BasicHttpParams params = new BasicHttpParams(); params.setParameter(CookieSpecPNames.DATE_PATTERNS, Arrays.asList("EEE, dd-MMM-yyyy HH:mm:ss z", "EEE, dd MMM yyyy HH:mm:ss z")); httpClient = new DefaultHttpClient(params); cookieStore = new BasicCookieStore(); context = new BasicHttpContext(); context.setAttribute(ClientContext.COOKIE_STORE, cookieStore); }
From source file:com.klarna.checkout.BasicConnector.java
/** * Create a HTTP Client./*from w w w . j a v a 2 s . c o m*/ * * @return HTTP Client to use. */ protected IHttpClient createHttpClient() { BasicHttpParams params = new BasicHttpParams(); params.setParameter("http.protocol.allow-circular-redirects", false); return new HttpClientWrapper(this.manager, params); }
From source file:org.usergrid.rest.filters.ContentTypeResourceIT.java
/** Tests that application/x-www-url-form-encoded works correctly */ @Test/*from w w w .j av a 2 s . c o m*/ @Ignore("This will only pass in tomcat, and shouldn't pass in grizzly") public void formEncodedUrlContentType() throws Exception { BasicHttpParams params = new BasicHttpParams(); params.setParameter("organization", "formUrlContentOrg"); params.setParameter("username", "formUrlContentOrg"); params.setParameter("name", "Test User"); params.setParameter("email", UUIDUtils.newTimeUUID() + "@usergrid.org"); params.setParameter("password", "foobar"); params.setParameter("grant_type", "password"); DefaultHttpClient client = new DefaultHttpClient(); HttpHost host = new HttpHost(super.getBaseURI().getHost(), super.getBaseURI().getPort()); HttpPost post = new HttpPost("/management/orgs"); post.setParams(params); post.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED); HttpResponse rsp = client.execute(host, post); printResponse(rsp); assertEquals(200, rsp.getStatusLine().getStatusCode()); Header[] headers = rsp.getHeaders(HttpHeaders.CONTENT_TYPE); assertEquals(1, headers.length); assertEquals(MediaType.APPLICATION_JSON, headers[0].getValue()); }
From source file:org.usergrid.rest.filters.ContentTypeResourceTest.java
/** * Tests that application/x-www-url-form-encoded works correctly * //ww w.j av a 2s. c o m * @throws * @throws Exception */ @Test @Ignore("This will only pass in tomcat, and shouldn't pass in grizzly") public void formEncodedUrlContentType() throws Exception { BasicHttpParams params = new BasicHttpParams(); params.setParameter("organization", "formUrlContentOrg"); params.setParameter("username", "formUrlContentOrg"); params.setParameter("name", "Test User"); params.setParameter("email", UUIDUtils.newTimeUUID() + "@usergrid.org"); params.setParameter("password", "foobar"); params.setParameter("grant_type", "password"); DefaultHttpClient client = new DefaultHttpClient(); HttpHost host = new HttpHost(super.getBaseURI().getHost(), super.getBaseURI().getPort()); HttpPost post = new HttpPost("/management/orgs"); post.setParams(params); post.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED); HttpResponse rsp = client.execute(host, post); printResponse(rsp); assertEquals(200, rsp.getStatusLine().getStatusCode()); Header[] headers = rsp.getHeaders(HttpHeaders.CONTENT_TYPE); assertEquals(1, headers.length); assertEquals(MediaType.APPLICATION_JSON, headers[0].getValue()); }
From source file:com.rackspacecloud.client.service_registry.clients.BaseClient.java
public BaseClient(AuthClient authClient, String apiUrl) { this(new DefaultHttpClient() { protected HttpParams createHttpParams() { BasicHttpParams params = new BasicHttpParams(); org.apache.http.params.HttpConnectionParams.setSoTimeout(params, 10000); params.setParameter("http.socket.timeout", 10000); return params; }//from w w w . ja v a2 s. com @Override protected ClientConnectionManager createClientConnectionManager() { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); return new ThreadSafeClientConnManager(createHttpParams(), schemeRegistry); } }, authClient, apiUrl); }
From source file:org.apache.wink.client.internal.handlers.httpclient.ApacheHttpClientConnectionHandler.java
private synchronized HttpClient openConnection(ClientRequest request) throws NoSuchAlgorithmException, KeyManagementException { if (this.httpclient != null) { return this.httpclient; }//from w ww. j a v a 2s. c o m // cast is safe because we're on the client ApacheHttpClientConfig config = (ApacheHttpClientConfig) request.getAttribute(WinkConfiguration.class); BasicHttpParams params = new BasicHttpParams(); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, Integer.valueOf(config.getConnectTimeout())); params.setParameter(CoreConnectionPNames.SO_TIMEOUT, Integer.valueOf(config.getReadTimeout())); params.setParameter(ClientPNames.HANDLE_REDIRECTS, Boolean.valueOf(config.isFollowRedirects())); if (config.isFollowRedirects()) { params.setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, Boolean.TRUE); } // setup proxy if (config.getProxyHost() != null) { params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(config.getProxyHost(), config.getProxyPort())); } if (config.getMaxPooledConnections() > 0) { SchemeRegistry schemeRegistry = SchemeRegistryFactory.createDefault(); ThreadSafeClientConnManager httpConnectionManager = new ThreadSafeClientConnManager(schemeRegistry); httpConnectionManager.setMaxTotal(config.getMaxPooledConnections()); httpConnectionManager.setDefaultMaxPerRoute(config.getMaxPooledConnections()); this.httpclient = new DefaultHttpClient(httpConnectionManager, params); } else { this.httpclient = new DefaultHttpClient(params); } if (config.getBypassHostnameVerification()) { SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, null, null); SSLSocketFactory sf = new SSLSocketFactory(sslcontext, new X509HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } public void verify(String host, String[] cns, String[] subjectAlts) throws SSLException { } public void verify(String host, X509Certificate cert) throws SSLException { } public void verify(String host, SSLSocket ssl) throws IOException { } }); httpclient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 443, sf)); } return this.httpclient; }
From source file:water.ga.GoogleAnalytics.java
protected HttpClient createHttpClient(GoogleAnalyticsConfig config) { ThreadSafeClientConnManager connManager = new ThreadSafeClientConnManager(); connManager.setDefaultMaxPerRoute(getDefaultMaxPerRoute(config)); BasicHttpParams params = new BasicHttpParams(); if (isNotEmpty(config.getUserAgent())) { params.setParameter(CoreProtocolPNames.USER_AGENT, config.getUserAgent()); }//from www. ja v a 2s .co m if (isNotEmpty(config.getProxyHost())) { params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(config.getProxyHost(), config.getProxyPort())); } DefaultHttpClient client = new DefaultHttpClient(connManager, params); if (isNotEmpty(config.getProxyUserName())) { BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(config.getProxyHost(), config.getProxyPort()), new UsernamePasswordCredentials(config.getProxyUserName(), config.getProxyPassword())); client.setCredentialsProvider(credentialsProvider); } return client; }
From source file:org.keycloak.adapters.cloned.HttpClientBuilder.java
public HttpClient build() { X509HostnameVerifier verifier = null; if (this.verifier != null) verifier = new VerifierWrapper(this.verifier); else {/*from ww w . j a va 2 s .c o m*/ switch (policy) { case ANY: verifier = new AllowAllHostnameVerifier(); break; case WILDCARD: verifier = new BrowserCompatHostnameVerifier(); break; case STRICT: verifier = new StrictHostnameVerifier(); break; } } try { SSLSocketFactory sslsf = null; SSLContext theContext = sslContext; if (disableTrustManager) { theContext = SSLContext.getInstance("SSL"); theContext.init(null, new TrustManager[] { new PassthroughTrustManager() }, new SecureRandom()); verifier = new AllowAllHostnameVerifier(); sslsf = new SniSSLSocketFactory(theContext, verifier); } else if (theContext != null) { sslsf = new SniSSLSocketFactory(theContext, verifier); } else if (clientKeyStore != null || truststore != null) { sslsf = new SniSSLSocketFactory(SSLSocketFactory.TLS, clientKeyStore, clientPrivateKeyPassword, truststore, null, verifier); } else { final SSLContext tlsContext = SSLContext.getInstance(SSLSocketFactory.TLS); tlsContext.init(null, null, null); sslsf = new SniSSLSocketFactory(tlsContext, verifier); } SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); Scheme httpsScheme = new Scheme("https", 443, sslsf); registry.register(httpsScheme); ClientConnectionManager cm = null; if (connectionPoolSize > 0) { ThreadSafeClientConnManager tcm = new ThreadSafeClientConnManager(registry, connectionTTL, connectionTTLUnit); tcm.setMaxTotal(connectionPoolSize); if (maxPooledPerRoute == 0) maxPooledPerRoute = connectionPoolSize; tcm.setDefaultMaxPerRoute(maxPooledPerRoute); cm = tcm; } else { cm = new SingleClientConnManager(registry); } BasicHttpParams params = new BasicHttpParams(); params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY); if (proxyHost != null) { params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxyHost); } if (socketTimeout > -1) { HttpConnectionParams.setSoTimeout(params, (int) socketTimeoutUnits.toMillis(socketTimeout)); } if (establishConnectionTimeout > -1) { HttpConnectionParams.setConnectionTimeout(params, (int) establishConnectionTimeoutUnits.toMillis(establishConnectionTimeout)); } DefaultHttpClient client = new DefaultHttpClient(cm, params); if (disableCookieCache) { client.setCookieStore(new CookieStore() { @Override public void addCookie(Cookie cookie) { //To change body of implemented methods use File | Settings | File Templates. } @Override public List<Cookie> getCookies() { return Collections.emptyList(); } @Override public boolean clearExpired(Date date) { return false; //To change body of implemented methods use File | Settings | File Templates. } @Override public void clear() { //To change body of implemented methods use File | Settings | File Templates. } }); } return client; } catch (Exception e) { throw new RuntimeException(e); } }