List of usage examples for org.apache.http.params HttpParams setBooleanParameter
HttpParams setBooleanParameter(String str, boolean z);
From source file:org.openrepose.core.services.httpclient.impl.HttpConnectionPoolProvider.java
public static HttpClient genClient(PoolType poolConf) { PoolingClientConnectionManager cm = new PoolingClientConnectionManager(); cm.setDefaultMaxPerRoute(poolConf.getHttpConnManagerMaxPerRoute()); cm.setMaxTotal(poolConf.getHttpConnManagerMaxTotal()); //Set all the params up front, instead of mutating them? Maybe this matters HttpParams params = new BasicHttpParams(); params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES); params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, poolConf.getHttpSocketTimeout()); params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, poolConf.getHttpConnectionTimeout()); params.setParameter(CoreConnectionPNames.TCP_NODELAY, poolConf.isHttpTcpNodelay()); params.setParameter(CoreConnectionPNames.MAX_HEADER_COUNT, poolConf.getHttpConnectionMaxHeaderCount()); params.setParameter(CoreConnectionPNames.MAX_LINE_LENGTH, poolConf.getHttpConnectionMaxLineLength()); params.setParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, poolConf.getHttpSocketBufferSize()); params.setBooleanParameter(CHUNKED_ENCODING_PARAM, poolConf.isChunkedEncoding()); final String uuid = UUID.randomUUID().toString(); params.setParameter(CLIENT_INSTANCE_ID, uuid); //Pass in the params and the connection manager DefaultHttpClient client = new DefaultHttpClient(cm, params); SSLContext sslContext = ProxyUtilities.getTrustingSslContext(); SSLSocketFactory ssf = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); SchemeRegistry registry = cm.getSchemeRegistry(); Scheme scheme = new Scheme("https", DEFAULT_HTTPS_PORT, ssf); registry.register(scheme);/* w w w .j ava2 s. c om*/ client.setKeepAliveStrategy(new ConnectionKeepAliveWithTimeoutStrategy(poolConf.getKeepaliveTimeout())); LOG.info("HTTP connection pool {} with instance id {} has been created", poolConf.getId(), uuid); return client; }
From source file:org.switchyard.quickstarts.rules.multi.RulesMultiThreadBindingUtils.java
/** * Gets the client./*from w w w . jav a 2s. c o m*/ * * @return the client */ public static DefaultHttpClient getClient() { DefaultHttpClient ret = null; // sets up parameters HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); params.setBooleanParameter("http.protocol.expect-continue", false); // registers schemes for both http and https SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); sslSocketFactory.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); registry.register(new Scheme("https", sslSocketFactory, 443)); ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry); ret = new DefaultHttpClient(manager, params); return ret; }
From source file:org.nuxeo.scim.server.tests.ScimServerTest.java
protected static ClientConfig createHttpBasicClientConfig(final String userName, final String password) { final HttpParams params = new BasicHttpParams(); DefaultHttpClient.setDefaultHttpParams(params); params.setBooleanParameter(CoreConnectionPNames.SO_REUSEADDR, true); params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true); params.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, true); final SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); final PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(schemeRegistry); mgr.setMaxTotal(200);/* w w w. j a v a 2 s .c o m*/ mgr.setDefaultMaxPerRoute(20); final DefaultHttpClient httpClient = new DefaultHttpClient(mgr, params); final Credentials credentials = new UsernamePasswordCredentials(userName, password); httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials); httpClient.addRequestInterceptor(new PreemptiveAuthInterceptor(), 0); ClientConfig clientConfig = new ApacheHttpClientConfig(httpClient); clientConfig.setBypassHostnameVerification(true); return clientConfig; }
From source file:pt.hive.cameo.net.ClientFactory.java
public static DefaultHttpClient getHttpClient(boolean strict) { // creates a new instance of the basic http parameters and then // updates the parameter with a series of pre-defined options that // are defined as the default ones for this factory HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); params.setBooleanParameter("http.protocol.strict-transfer-encoding", false); params.setBooleanParameter("http.protocol.expect-continue", true); // constructs both the plain and the secure factory objects that are // going to be used in the registration of the plain and secure http // schemes, operation to be performed latter on SocketFactory plainFactory = PlainSocketFactory.getSocketFactory(); SocketFactory secureFactory = strict ? org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory() : SSLSocketFactory.getSocketFactory(); // creates the registry object and registers both the secure and the // insecure http mechanisms for the respective socket factories SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", plainFactory, 80)); registry.register(new Scheme("https", secureFactory, 443)); // creates the manager entity using the creates parameters structure // and the registry for socket factories ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry); // creates the default http client using the created thread safe manager // with the provided parameters and registry (as expected) and then // returns the new client to the caller method so that it may be used DefaultHttpClient client = new DefaultHttpClient(manager, params); return client; }
From source file:org.apache.abdera2.common.protocol.RequestHelper.java
public static HttpUriRequest createRequest(String method, String uri, HttpEntity entity, RequestOptions options) {/*from w w w . j av a 2s .c o m*/ if (method == null) return null; if (options == null) options = createAtomDefaultRequestOptions().get(); Method m = Method.get(method); Method actual = null; HttpUriRequest httpMethod = null; if (options.isUsePostOverride() && !nopostoveride.contains(m)) { actual = m; m = Method.POST; } if (m == GET) httpMethod = new HttpGet(uri); else if (m == POST) { httpMethod = new HttpPost(uri); if (entity != null) ((HttpPost) httpMethod).setEntity(entity); } else if (m == PUT) { httpMethod = new HttpPut(uri); if (entity != null) ((HttpPut) httpMethod).setEntity(entity); } else if (m == DELETE) httpMethod = new HttpDelete(uri); else if (m == HEAD) httpMethod = new HttpHead(uri); else if (m == OPTIONS) httpMethod = new HttpOptions(uri); else if (m == TRACE) httpMethod = new HttpTrace(uri); // else if (m == PATCH) // httpMethod = new ExtensionRequest(m.name(),uri,entity); else httpMethod = new ExtensionRequest(m.name(), uri, entity); if (actual != null) { httpMethod.addHeader("X-HTTP-Method-Override", actual.name()); } initHeaders(options, httpMethod); HttpParams params = httpMethod.getParams(); if (!options.isUseExpectContinue()) { params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); } else { if (options.getWaitForContinue() > -1) params.setIntParameter(CoreProtocolPNames.WAIT_FOR_CONTINUE, options.getWaitForContinue()); } if (!(httpMethod instanceof HttpEntityEnclosingRequest)) params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, options.isFollowRedirects()); return httpMethod; }
From source file:com.ninja.examples.utility.net.APIRequest.java
public static DefaultHttpClient getClient() { if (httpclient == null) { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setUseExpectContinue(params, false); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); params.setBooleanParameter("http.protocol.expect-continue", false); HttpConnectionParams.setConnectionTimeout(params, WS_TIMEOUT); HttpConnectionParams.setSoTimeout(params, WS_TIMEOUT); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry); httpclient = new DefaultHttpClient(manager, params); httpclient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() { public long getKeepAliveDuration(HttpResponse response, HttpContext context) { return 50; }/*from ww w . j ava 2 s .c o m*/ }); } return httpclient; }
From source file:com.unboundid.scim.sdk.examples.ClientExample.java
/** * Create an SSL-enabled Wink client config from the provided information. * The returned client config may be used to create a SCIM service object. * IMPORTANT: This should not be used in production because no validation * is performed on the server certificate returned by the SCIM service. * * @param userName The HTTP Basic Auth user name. * @param password The HTTP Basic Auth password. * * @return An Apache Wink client config. *//* ww w . j a va 2s.co m*/ public static ClientConfig createHttpBasicClientConfig(final String userName, final String password) { SSLSocketFactory sslSocketFactory; try { final SSLContext sslContext = SSLContext.getInstance("TLS"); // Do not use these settings in production. sslContext.init(null, new TrustManager[] { new BlindTrustManager() }, new SecureRandom()); sslSocketFactory = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } catch (KeyManagementException e) { throw new RuntimeException(e.getLocalizedMessage()); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e.getLocalizedMessage()); } final HttpParams params = new BasicHttpParams(); DefaultHttpClient.setDefaultHttpParams(params); params.setBooleanParameter(CoreConnectionPNames.SO_REUSEADDR, true); params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true); params.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, true); final SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, sslSocketFactory)); final PoolingClientConnectionManager mgr = new PoolingClientConnectionManager(schemeRegistry); mgr.setMaxTotal(200); mgr.setDefaultMaxPerRoute(20); final DefaultHttpClient httpClient = new DefaultHttpClient(mgr, params); final Credentials credentials = new UsernamePasswordCredentials(userName, password); httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials); httpClient.addRequestInterceptor(new PreemptiveAuthInterceptor(), 0); ClientConfig clientConfig = new ApacheHttpClientConfig(httpClient); clientConfig.setBypassHostnameVerification(true); return clientConfig; }
From source file:nl.hardijzer.bitonsync.client.NetworkUtilities.java
/** * Configures the httpClient to connect to the URL provided. *//*from w w w . j a v a2 s. c o m*/ public static void maybeCreateHttpClient() { if (mHttpClient == null) { mHttpClient = new DefaultHttpClient(); final HttpParams params = mHttpClient.getParams(); HttpConnectionParams.setConnectionTimeout(params, REGISTRATION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, REGISTRATION_TIMEOUT); ConnManagerParams.setTimeout(params, REGISTRATION_TIMEOUT); params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true); } }
From source file:org.wso2.bam.integration.tests.reciever.RESTAPITestCase.java
@BeforeClass(groups = { "wso2.bam" }) private static void init() { DATA_RECEIVER = "/datareceiver/1.0.0"; // host = FrameworkSettings.HOST_NAME; // httpsPort = Integer.parseInt(FrameworkSettings.HTTPS_PORT); restAppParentURL = "https://" + host + ":" + httpsPort + DATA_RECEIVER; streamsURL = restAppParentURL + "/streams"; streamURL = restAppParentURL + "/stream"; stockQuoteVersion1URL = streamURL + "/stockquote.stream/1.0.2/"; stockQuoteVersion2URL = streamURL + "/stockquote.stream.2/2.0.0"; stockQuoteVersion3URL = streamURL + "/labit.stream/0.0.3"; stockQuoteVersion4URL = streamURL + "/eu.ima.event.stream/1.2.0"; stockQuoteVersion5URL = streamURL + "/eu.ima.event.stream.2/1.3.0"; try {/*from w w w. jav a 2s . c o m*/ events1 = IOUtils .toString(RESTAPITestCase.class.getClassLoader().getResourceAsStream("rest/events1.json")); events2 = IOUtils .toString(RESTAPITestCase.class.getClassLoader().getResourceAsStream("rest/events2.json")); events3 = IOUtils .toString(RESTAPITestCase.class.getClassLoader().getResourceAsStream("rest/events3.json")); events4 = IOUtils .toString(RESTAPITestCase.class.getClassLoader().getResourceAsStream("rest/events4.json")); events5 = IOUtils .toString(RESTAPITestCase.class.getClassLoader().getResourceAsStream("rest/events5.json")); streamdefn1 = IOUtils .toString(RESTAPITestCase.class.getClassLoader().getResourceAsStream("rest/streamdefn1.json")); streamdefn2 = IOUtils .toString(RESTAPITestCase.class.getClassLoader().getResourceAsStream("rest/streamdefn2.json")); streamdefn3 = IOUtils .toString(RESTAPITestCase.class.getClassLoader().getResourceAsStream("rest/streamdefn3.json")); streamdefn4 = IOUtils .toString(RESTAPITestCase.class.getClassLoader().getResourceAsStream("rest/streamdefn4.json")); streamdefn5 = IOUtils .toString(RESTAPITestCase.class.getClassLoader().getResourceAsStream("rest/streamdefn5.json")); TrustManager easyTrustManager = new X509TrustManager() { public void checkClientTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws java.security.cert.CertificateException { } public void checkServerTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws java.security.cert.CertificateException { } public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } }; SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, new TrustManager[] { easyTrustManager }, null); SSLSocketFactory sf = new SSLSocketFactory(sslContext); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme httpsScheme = new Scheme("https", sf, httpsPort); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); params.setBooleanParameter("http.protocol.expect-continue", false); client = new DefaultHttpClient(params); client.getConnectionManager().getSchemeRegistry().register(httpsScheme); } catch (Exception e) { e.printStackTrace(); fail(); } }
From source file:com.alibaba.akita.io.HttpInvoker.java
/** * init//from ww w .j a va 2s .co m */ private static void init() { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", _FakeSSLSocketFactory.getSocketFactory(), 443)); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); HttpConnectionParams.setConnectionTimeout(params, 8000); HttpConnectionParams.setSoTimeout(params, 15000); params.setBooleanParameter("http.protocol.expect-continue", false); connectionManager = new ThreadSafeClientConnManager(params, schemeRegistry); client = new DefaultHttpClient(connectionManager, params); // enable gzip support in Request and Response. client.addRequestInterceptor(new HttpRequestInterceptor() { public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { if (!request.containsHeader("Accept-Encoding")) { request.addHeader("Accept-Encoding", "gzip"); } } }); client.addResponseInterceptor(new HttpResponseInterceptor() { public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { HttpEntity entity = response.getEntity(); //Log.i("ContentLength", entity.getContentLength()+""); Header ceheader = entity.getContentEncoding(); if (ceheader != null) { HeaderElement[] codecs = ceheader.getElements(); for (int i = 0; i < codecs.length; i++) { if (codecs[i].getName().equalsIgnoreCase("gzip")) { response.setEntity(new GzipDecompressingEntity(response.getEntity())); return; } } } } }); }