List of usage examples for org.apache.http.params HttpParams setBooleanParameter
HttpParams setBooleanParameter(String str, boolean z);
From source file:org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.java
/** * Setup following elements on httpRequest: * <ul>/*from w ww . j a v a 2 s .c om*/ * <li>ConnRoutePNames.LOCAL_ADDRESS enabling IP-SPOOFING</li> * <li>Socket and connection timeout</li> * <li>Redirect handling</li> * <li>Keep Alive header or Connection Close</li> * <li>Calls setConnectionHeaders to setup headers</li> * <li>Calls setConnectionCookie to setup Cookie</li> * </ul> * * @param url * {@link URL} of the request * @param httpRequest * http request for the request * @param res * sample result to set cookies on * @throws IOException * if hostname/ip to use could not be figured out */ protected void setupRequest(URL url, HttpRequestBase httpRequest, HTTPSampleResult res) throws IOException { HttpParams requestParams = httpRequest.getParams(); // Set up the local address if one exists final InetAddress inetAddr = getIpSourceAddress(); if (inetAddr != null) {// Use special field ip source address (for pseudo 'ip spoofing') requestParams.setParameter(ConnRoutePNames.LOCAL_ADDRESS, inetAddr); } else if (localAddress != null) { requestParams.setParameter(ConnRoutePNames.LOCAL_ADDRESS, localAddress); } else { // reset in case was set previously requestParams.removeParameter(ConnRoutePNames.LOCAL_ADDRESS); } int rto = getResponseTimeout(); if (rto > 0) { requestParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, rto); } int cto = getConnectTimeout(); if (cto > 0) { requestParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, cto); } requestParams.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, getAutoRedirects()); // a well-behaved browser is supposed to send 'Connection: close' // with the last request to an HTTP server. Instead, most browsers // leave it to the server to close the connection after their // timeout period. Leave it to the JMeter user to decide. if (getUseKeepAlive()) { httpRequest.setHeader(HTTPConstants.HEADER_CONNECTION, HTTPConstants.KEEP_ALIVE); } else { httpRequest.setHeader(HTTPConstants.HEADER_CONNECTION, HTTPConstants.CONNECTION_CLOSE); } setConnectionHeaders(httpRequest, url, getHeaderManager(), getCacheManager()); String cookies = setConnectionCookie(httpRequest, url, getCookieManager()); if (res != null) { res.setCookies(cookies); } }
From source file:com.archivas.clienttools.arcutils.impl.adapter.HCAPAdapter.java
/** * Setup default http client parameters including timeouts, number of simultaneous connections, * and a retry handler//from ww w . j ava2s . c o m * * @param sslExceptionCallback */ protected synchronized final void init(SSLCertificateCallback sslExceptionCallback) throws StorageAdapterException { if (httpClient != null) { LOG.log(Level.FINE, "Reinitializing...why?"); return; } HttpParams params = new BasicHttpParams(); // Right now we just set this up for normal load. This means when we go to low load it is // possible we will // be accessing more connections on HCP than what is set there. When we upgrade to the next // apache library // we can implement that functionality see: @updateHttpClient int maxConnectionsPerRoute = HCPMoverProperties.MAX_LOAD_MAXTHREADS.getAsInt(); int maxConnections = HCPMoverProperties.MAX_LOAD_MAXTHREADS_PER_NODE.getAsInt(); try { ConnPerRouteBean connPerRoute = new ConnPerRouteBean(maxConnectionsPerRoute); ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute); } catch (NumberFormatException e) { /* Already logged by helper */ } try { ConnManagerParams.setMaxTotalConnections(params, maxConnections); } catch (NumberFormatException e) { /* Already logged by helper */ } // We need a timeout so we don't just hang there forever int connectionTimeoutMillis = HCPMoverProperties.CONNECTION_TIMEOUT_MILLIS.getAsInt(); HttpConnectionParams.setConnectionTimeout(params, connectionTimeoutMillis); // And a socket timeout from properties int socketTimeoutMillis = HCPMoverProperties.SOCKET_TIMEOUT_MILLIS.getAsInt(); HttpConnectionParams.setSoTimeout(params, socketTimeoutMillis); // This is the magic that makes windows reuse sockets. HttpConnectionParams.setLinger(params, 1); // 302's from HCP redirect -- prevent this params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false); try { SchemeRegistry schemeRegistry = getHcapProtocolSchemeRegistryForHttpClient(sslExceptionCallback); ThreadSafeClientConnManager connMgr = new ThreadSafeClientConnManager(params, schemeRegistry); // debug start // TestHttpThreadSafeClientConnManager connMgr = new // TestHttpThreadSafeClientConnManager(params, schemeRegistry); // debug end httpClient = new DefaultHttpClient(connMgr, params); LOG.log(Level.FINE, "Created new httpClient for profile: " + getProfile()); } catch (Exception e) { LOG.log(Level.INFO, "Unable to initialize HCAPHttpAdapter!", e); throw new StorageAdapterLiteralException("Unable to initialize HCAPHttpAdapter!", e); } }
From source file:com.marklogic.client.impl.JerseyServices.java
private void connect(String host, int port, String database, String user, String password, Authentication authenType, SSLContext context, X509HostnameVerifier verifier) { if (logger.isDebugEnabled()) logger.debug("Connecting to {} at {} as {}", new Object[] { host, port, user }); if (host == null) throw new IllegalArgumentException("No host provided"); if (authenType == null) { if (context != null) { authenType = Authentication.BASIC; }//www . j ava2 s .c om } if (authenType != null) { if (user == null) throw new IllegalArgumentException("No user provided"); if (password == null) throw new IllegalArgumentException("No password provided"); } if (connection != null) connection = null; if (client != null) { client.destroy(); client = null; } this.database = database; String baseUri = ((context == null) ? "http" : "https") + "://" + host + ":" + port + "/v1/"; Properties props = System.getProperties(); if (props.containsKey(MAX_DELAY_PROP)) { String maxDelayStr = props.getProperty(MAX_DELAY_PROP); if (maxDelayStr != null && maxDelayStr.length() > 0) { int max = Integer.parseInt(maxDelayStr); if (max > 0) { maxDelay = max * 1000; } } } if (props.containsKey(MIN_RETRY_PROP)) { String minRetryStr = props.getProperty(MIN_RETRY_PROP); if (minRetryStr != null && minRetryStr.length() > 0) { int min = Integer.parseInt(minRetryStr); if (min > 0) { minRetry = min; } } } // TODO: integrated control of HTTP Client and Jersey Client logging if (!props.containsKey("org.apache.commons.logging.Log")) { System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); } if (!props.containsKey("org.apache.commons.logging.simplelog.log.org.apache.http")) { System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "warn"); } if (!props.containsKey("org.apache.commons.logging.simplelog.log.org.apache.http.wire")) { System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "warn"); } Scheme scheme = null; if (context == null) { SchemeSocketFactory socketFactory = PlainSocketFactory.getSocketFactory(); scheme = new Scheme("http", port, socketFactory); } else { SSLSocketFactory socketFactory = new SSLSocketFactory(context, verifier); scheme = new Scheme("https", port, socketFactory); } SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(scheme); int maxRouteConnections = 100; int maxTotalConnections = 2 * maxRouteConnections; /* * 4.2 PoolingClientConnectionManager connMgr = new * PoolingClientConnectionManager(schemeRegistry); * connMgr.setMaxTotal(maxTotalConnections); * connMgr.setDefaultMaxPerRoute(maxRouteConnections); * connMgr.setMaxPerRoute( new HttpRoute(new HttpHost(baseUri)), * maxRouteConnections); */ // start 4.1 ThreadSafeClientConnManager connMgr = new ThreadSafeClientConnManager(schemeRegistry); connMgr.setMaxTotal(maxTotalConnections); connMgr.setDefaultMaxPerRoute(maxRouteConnections); connMgr.setMaxForRoute(new HttpRoute(new HttpHost(baseUri)), maxRouteConnections); // end 4.1 // CredentialsProvider credentialsProvider = new // BasicCredentialsProvider(); // credentialsProvider.setCredentials(new AuthScope(host, port), // new UsernamePasswordCredentials(user, password)); HttpParams httpParams = new BasicHttpParams(); if (authenType != null) { List<String> authpref = new ArrayList<String>(); if (authenType == Authentication.BASIC) authpref.add(AuthPolicy.BASIC); else if (authenType == Authentication.DIGEST) authpref.add(AuthPolicy.DIGEST); else throw new MarkLogicInternalException( "Internal error - unknown authentication type: " + authenType.name()); httpParams.setParameter(AuthPNames.PROXY_AUTH_PREF, authpref); } httpParams.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); // HttpConnectionParams.setStaleCheckingEnabled(httpParams, false); // long-term alternative to isFirstRequest alive // HttpProtocolParams.setUseExpectContinue(httpParams, false); // httpParams.setIntParameter(CoreProtocolPNames.WAIT_FOR_CONTINUE, 1000); DefaultApacheHttpClient4Config config = new DefaultApacheHttpClient4Config(); Map<String, Object> configProps = config.getProperties(); configProps.put(ApacheHttpClient4Config.PROPERTY_PREEMPTIVE_BASIC_AUTHENTICATION, false); configProps.put(ApacheHttpClient4Config.PROPERTY_DISABLE_COOKIES, true); configProps.put(ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER, connMgr); // ignored? configProps.put(ApacheHttpClient4Config.PROPERTY_FOLLOW_REDIRECTS, false); // configProps.put(ApacheHttpClient4Config.PROPERTY_CREDENTIALS_PROVIDER, // credentialsProvider); configProps.put(ApacheHttpClient4Config.PROPERTY_HTTP_PARAMS, httpParams); // switches from buffered to streamed in Jersey Client configProps.put(ApacheHttpClient4Config.PROPERTY_CHUNKED_ENCODING_SIZE, 32 * 1024); client = ApacheHttpClient4.create(config); // System.setProperty("javax.net.debug", "all"); // all or ssl if (authenType == null) { checkFirstRequest = false; } else if (authenType == Authentication.BASIC) { checkFirstRequest = false; client.addFilter(new HTTPBasicAuthFilter(user, password)); } else if (authenType == Authentication.DIGEST) { checkFirstRequest = true; // workaround for JerseyClient bug 1445 client.addFilter(new DigestChallengeFilter()); client.addFilter(new HTTPDigestAuthFilter(user, password)); } else { throw new MarkLogicInternalException( "Internal error - unknown authentication type: " + authenType.name()); } // client.addFilter(new LoggingFilter(System.err)); connection = client.resource(baseUri); }
From source file:org.craftercms.profile.impl.ProfileRestClientService.java
/** * @param httpParams/* www. jav a 2 s.co m*/ * @param connectionTimeOut * @param sockeTimeOut */ private void setParams(HttpParams httpParams, int connectionTimeOut, int sockeTimeOut) { setHttpProtocolParams(httpParams); setHttpConnectionParams(httpParams, connectionTimeOut, sockeTimeOut); httpParams.setBooleanParameter("http.protocol.expect-continue", false); }
From source file:org.mitre.dsmiley.httpproxy.ProxyServlet.java
@Override public void init() throws ServletException { String doLogStr = getConfigParam(P_LOG); if (doLogStr != null) { this.doLog = Boolean.parseBoolean(doLogStr); }/*w ww. j av a 2s .co m*/ String doForwardIPString = getConfigParam(P_FORWARDEDFOR); if (doForwardIPString != null) { this.doForwardIP = Boolean.parseBoolean(doForwardIPString); } initTarget();// sets target* HttpParams hcParams = new BasicHttpParams(); hcParams.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES); hcParams.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false); // See // #70 readConfigParam(hcParams, ClientPNames.HANDLE_REDIRECTS, Boolean.class); proxyClient = createHttpClient(hcParams); }