List of usage examples for org.apache.http.params CoreConnectionPNames SO_LINGER
String SO_LINGER
To view the source code for org.apache.http.params CoreConnectionPNames SO_LINGER.
Click Source Link
From source file:org.carrot2.util.httpclient.HttpClientFactory.java
/** * @param timeout Timeout in milliseconds. * @return Returns a client with sockets configured to timeout after some sensible * time.//from ww w . j a va 2 s.c o m */ public static DefaultHttpClient getTimeoutingClient(int timeout) { final DefaultHttpClient httpClient = new DefaultHttpClient(); configureProxy(httpClient); // Setup defaults. httpClient.setReuseStrategy(new NoConnectionReuseStrategy()); httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout); httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_LINGER, 0); return httpClient; }
From source file:net.evendanan.android.thumbremote.network.ReusableHttpClientBlocking.java
ReusableHttpClientBlocking(int timeout, String user, String password) { Log.d(TAG, "Creating a new HTTP client"); mHttpClient = new DefaultHttpClient(); if (!TextUtils.isEmpty(password)) { CredentialsProvider credProvider = new BasicCredentialsProvider(); credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(user, password)); mHttpClient.setCredentialsProvider(credProvider); }// w w w.jav a 2s .co m mRequest = new HttpGet(); mRequest.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, new Integer(timeout)); mRequest.getParams().setParameter(CoreConnectionPNames.SO_LINGER, new Integer(timeout / 2)); mRequest.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, new Integer(timeout)); }
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:se.inera.certificate.proxy.filter.ProxyFilter.java
private void doInit() { if (!isInitiated) { connectionManager = new PoolingClientConnectionManager(SchemeRegistryFactory.createDefault()); connectionManager.setMaxTotal(maxConnections); connectionManager.setDefaultMaxPerRoute(maxDefaultPerRoute); // TODO: Hardcoded for now... (PW) HttpParams params = new BasicHttpParams(); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT_MS); params.setParameter(CoreConnectionPNames.SO_TIMEOUT, DEFAULT_SO_TIMEOUT_MS); params.setParameter(CoreConnectionPNames.SO_LINGER, DEFAULT_SO_LINGER_S); httpClient = new HttpProxyClient(connectionManager, params); isInitiated = true;// ww w.j a v a 2s .co m } }
From source file:com.jobaline.uiautomation.framework.selenium.phantomJsThreeHourTimeoutFix.HttpCommandExecutor.java
public HttpCommandExecutor(Map<String, CommandInfo> additionalCommands, URL addressOfRemoteServer) { try {// ww w . j ava2s . co m remoteServer = addressOfRemoteServer == null ? new URL(System.getProperty("webdriver.remote.server", "http://localhost:4444/wd/hub")) : addressOfRemoteServer; } catch (MalformedURLException e) { throw new WebDriverException(e); } HttpParams params = new BasicHttpParams(); // Use the JRE default for the socket linger timeout. params.setParameter(CoreConnectionPNames.SO_LINGER, -1); HttpClientParams.setRedirecting(params, false); synchronized (HttpCommandExecutor.class) { if (httpClientFactory == null) { httpClientFactory = new HttpClientFactory(); } } client = httpClientFactory.getHttpClient(); // PATCH start // HttpClientFactory has a hardcoded timeout of three hours. // This class is intended to be used only for phantomjs which runs locally so the timeouts will be set to a low value BasicHttpParams paramsPatched = (BasicHttpParams) client.getParams(); paramsPatched.setIntParameter("http.connection.timeout", 90000); // 1 minute an a half paramsPatched.setIntParameter("http.socket.timeout", 90000); // 1 minute an a half ((DefaultHttpClient) client).setParams(params); // PATCH end if (addressOfRemoteServer != null && addressOfRemoteServer.getUserInfo() != null) { // Use HTTP Basic auth UsernamePasswordCredentials credentials = new UsernamePasswordCredentials( addressOfRemoteServer.getUserInfo()); ((DefaultHttpClient) client).getCredentialsProvider().setCredentials(AuthScope.ANY, credentials); } // Some machines claim "localhost.localdomain" is the same as "localhost". // This assumption is not always true. String host = remoteServer.getHost().replace(".localdomain", ""); targetHost = new HttpHost(host, remoteServer.getPort(), remoteServer.getProtocol()); ImmutableMap.Builder<String, CommandInfo> builder = ImmutableMap.builder(); for (Map.Entry<String, CommandInfo> entry : additionalCommands.entrySet()) { builder.put(entry.getKey(), entry.getValue()); } builder.put(GET_ALL_SESSIONS, get("/sessions")).put(NEW_SESSION, post("/session")) .put(GET_CAPABILITIES, get("/session/:sessionId")).put(QUIT, delete("/session/:sessionId")) .put(GET_CURRENT_WINDOW_HANDLE, get("/session/:sessionId/window_handle")) .put(GET_WINDOW_HANDLES, get("/session/:sessionId/window_handles")) .put(GET, post("/session/:sessionId/url")) // The Alert API is still experimental and should not be used. .put(GET_ALERT, get("/session/:sessionId/alert")) .put(DISMISS_ALERT, post("/session/:sessionId/dismiss_alert")) .put(ACCEPT_ALERT, post("/session/:sessionId/accept_alert")) .put(GET_ALERT_TEXT, get("/session/:sessionId/alert_text")) .put(SET_ALERT_VALUE, post("/session/:sessionId/alert_text")) .put(GO_FORWARD, post("/session/:sessionId/forward")).put(GO_BACK, post("/session/:sessionId/back")) .put(REFRESH, post("/session/:sessionId/refresh")) .put(EXECUTE_SCRIPT, post("/session/:sessionId/execute")) .put(EXECUTE_ASYNC_SCRIPT, post("/session/:sessionId/execute_async")) .put(GET_CURRENT_URL, get("/session/:sessionId/url")) .put(GET_TITLE, get("/session/:sessionId/title")) .put(GET_PAGE_SOURCE, get("/session/:sessionId/source")) .put(SCREENSHOT, get("/session/:sessionId/screenshot")) .put(FIND_ELEMENT, post("/session/:sessionId/element")) .put(FIND_ELEMENTS, post("/session/:sessionId/elements")) .put(GET_ACTIVE_ELEMENT, post("/session/:sessionId/element/active")) .put(FIND_CHILD_ELEMENT, post("/session/:sessionId/element/:id/element")) .put(FIND_CHILD_ELEMENTS, post("/session/:sessionId/element/:id/elements")) .put(CLICK_ELEMENT, post("/session/:sessionId/element/:id/click")) .put(CLEAR_ELEMENT, post("/session/:sessionId/element/:id/clear")) .put(SUBMIT_ELEMENT, post("/session/:sessionId/element/:id/submit")) .put(GET_ELEMENT_TEXT, get("/session/:sessionId/element/:id/text")) .put(SEND_KEYS_TO_ELEMENT, post("/session/:sessionId/element/:id/value")) .put(UPLOAD_FILE, post("/session/:sessionId/file")) .put(GET_ELEMENT_VALUE, get("/session/:sessionId/element/:id/value")) .put(GET_ELEMENT_TAG_NAME, get("/session/:sessionId/element/:id/name")) .put(IS_ELEMENT_SELECTED, get("/session/:sessionId/element/:id/selected")) .put(IS_ELEMENT_ENABLED, get("/session/:sessionId/element/:id/enabled")) .put(IS_ELEMENT_DISPLAYED, get("/session/:sessionId/element/:id/displayed")) .put(HOVER_OVER_ELEMENT, post("/session/:sessionId/element/:id/hover")) .put(GET_ELEMENT_LOCATION, get("/session/:sessionId/element/:id/location")) .put(GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW, get("/session/:sessionId/element/:id/location_in_view")) .put(GET_ELEMENT_SIZE, get("/session/:sessionId/element/:id/size")) .put(GET_ELEMENT_ATTRIBUTE, get("/session/:sessionId/element/:id/attribute/:name")) .put(ELEMENT_EQUALS, get("/session/:sessionId/element/:id/equals/:other")) .put(GET_ALL_COOKIES, get("/session/:sessionId/cookie")) .put(ADD_COOKIE, post("/session/:sessionId/cookie")) .put(DELETE_ALL_COOKIES, delete("/session/:sessionId/cookie")) .put(DELETE_COOKIE, delete("/session/:sessionId/cookie/:name")) .put(SWITCH_TO_FRAME, post("/session/:sessionId/frame")) .put(SWITCH_TO_PARENT_FRAME, post("/session/:sessionId/frame/parent")) .put(SWITCH_TO_WINDOW, post("/session/:sessionId/window")) .put(GET_WINDOW_SIZE, get("/session/:sessionId/window/:windowHandle/size")) .put(GET_WINDOW_POSITION, get("/session/:sessionId/window/:windowHandle/position")) .put(SET_WINDOW_SIZE, post("/session/:sessionId/window/:windowHandle/size")) .put(SET_WINDOW_POSITION, post("/session/:sessionId/window/:windowHandle/position")) .put(MAXIMIZE_WINDOW, post("/session/:sessionId/window/:windowHandle/maximize")) .put(CLOSE, delete("/session/:sessionId/window")) .put(DRAG_ELEMENT, post("/session/:sessionId/element/:id/drag")) .put(GET_ELEMENT_VALUE_OF_CSS_PROPERTY, get("/session/:sessionId/element/:id/css/:propertyName")) .put(IMPLICITLY_WAIT, post("/session/:sessionId/timeouts/implicit_wait")) .put(SET_SCRIPT_TIMEOUT, post("/session/:sessionId/timeouts/async_script")) .put(SET_TIMEOUT, post("/session/:sessionId/timeouts")) .put(EXECUTE_SQL, post("/session/:sessionId/execute_sql")) .put(GET_LOCATION, get("/session/:sessionId/location")) .put(SET_LOCATION, post("/session/:sessionId/location")) .put(GET_APP_CACHE_STATUS, get("/session/:sessionId/application_cache/status")) .put(IS_BROWSER_ONLINE, get("/session/:sessionId/browser_connection")) .put(SET_BROWSER_ONLINE, post("/session/:sessionId/browser_connection")) .put(SWITCH_TO_CONTEXT, post("/session/:sessionId/context")) .put(GET_CURRENT_CONTEXT_HANDLE, get("/session/:sessionId/context")) .put(GET_CONTEXT_HANDLES, get("/session/:sessionId/contexts")) // TODO (user): Would it be better to combine this command with // GET_LOCAL_STORAGE_SIZE? .put(GET_LOCAL_STORAGE_ITEM, get("/session/:sessionId/local_storage/key/:key")) .put(REMOVE_LOCAL_STORAGE_ITEM, delete("/session/:sessionId/local_storage/key/:key")) .put(GET_LOCAL_STORAGE_KEYS, get("/session/:sessionId/local_storage")) .put(SET_LOCAL_STORAGE_ITEM, post("/session/:sessionId/local_storage")) .put(CLEAR_LOCAL_STORAGE, delete("/session/:sessionId/local_storage")) .put(GET_LOCAL_STORAGE_SIZE, get("/session/:sessionId/local_storage/size")) // TODO (user): Would it be better to combine this command with // GET_SESSION_STORAGE_SIZE? .put(GET_SESSION_STORAGE_ITEM, get("/session/:sessionId/session_storage/key/:key")) .put(REMOVE_SESSION_STORAGE_ITEM, delete("/session/:sessionId/session_storage/key/:key")) .put(GET_SESSION_STORAGE_KEYS, get("/session/:sessionId/session_storage")) .put(SET_SESSION_STORAGE_ITEM, post("/session/:sessionId/session_storage")) .put(CLEAR_SESSION_STORAGE, delete("/session/:sessionId/session_storage")) .put(GET_SESSION_STORAGE_SIZE, get("/session/:sessionId/session_storage/size")) .put(GET_SCREEN_ORIENTATION, get("/session/:sessionId/orientation")) .put(SET_SCREEN_ORIENTATION, post("/session/:sessionId/orientation")) // Interactions-related commands. .put(CLICK, post("/session/:sessionId/click")) .put(DOUBLE_CLICK, post("/session/:sessionId/doubleclick")) .put(MOUSE_DOWN, post("/session/:sessionId/buttondown")) .put(MOUSE_UP, post("/session/:sessionId/buttonup")) .put(MOVE_TO, post("/session/:sessionId/moveto")) .put(SEND_KEYS_TO_ACTIVE_ELEMENT, post("/session/:sessionId/keys")) // IME related commands. .put(IME_GET_AVAILABLE_ENGINES, get("/session/:sessionId/ime/available_engines")) .put(IME_GET_ACTIVE_ENGINE, get("/session/:sessionId/ime/active_engine")) .put(IME_IS_ACTIVATED, get("/session/:sessionId/ime/activated")) .put(IME_DEACTIVATE, post("/session/:sessionId/ime/deactivate")) .put(IME_ACTIVATE_ENGINE, post("/session/:sessionId/ime/activate")) // Advanced Touch API commands // TODO(berrada): Refactor single tap with mouse click. .put(TOUCH_SINGLE_TAP, post("/session/:sessionId/touch/click")) .put(TOUCH_DOWN, post("/session/:sessionId/touch/down")) .put(TOUCH_UP, post("/session/:sessionId/touch/up")) .put(TOUCH_MOVE, post("/session/:sessionId/touch/move")) .put(TOUCH_SCROLL, post("/session/:sessionId/touch/scroll")) .put(TOUCH_DOUBLE_TAP, post("/session/:sessionId/touch/doubleclick")) .put(TOUCH_LONG_PRESS, post("/session/:sessionId/touch/longclick")) .put(TOUCH_FLICK, post("/session/:sessionId/touch/flick")) .put(GET_LOG, post("/session/:sessionId/log")) .put(GET_AVAILABLE_LOG_TYPES, get("/session/:sessionId/log/types")) .put(STATUS, get("/status")); nameToUrl = builder.build(); }
From source file:org.frameworkset.spi.remote.http.HttpServer.java
public void start() { serverParams = new BasicHttpParams(); int so_timeout = this.params.getInt("http.socket.timeout", 30);//?? int SOCKET_BUFFER_SIZE = this.params.getInt("http.socket.buffer-size", 8 * 1024); boolean STALE_CONNECTION_CHECK = this.params.getBoolean("http.connection.stalecheck", false); boolean TCP_NODELAY = this.params.getBoolean("TCP_NODELAY", true); String ORIGIN_SERVER = this.params.getString("http.origin-server", "RPC-SERVER/1.1"); int CONNECTION_TIMEOUT = this.params.getInt("http.connection.timeout", 30); int httpsoLinger = this.params.getInt("http.soLinger", -1); serverParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, so_timeout * 1000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, SOCKET_BUFFER_SIZE) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, STALE_CONNECTION_CHECK) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, TCP_NODELAY) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, ORIGIN_SERVER) .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT * 1000) .setIntParameter(CoreConnectionPNames.SO_LINGER, httpsoLinger); if (!enablessl) { try {//from w w w .j av a2s .c om this.startHttp(); System.out.println("Http server is listenig at port " + port + ",ip is " + this.ip); System.out.println("Http server started."); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { try { this.startHttps(); System.out.println("Https server is listenig at port " + port + ",ip is " + this.ip); System.out.println("Https server started."); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (this.started) ApplicationContext.addShutdownHook(new ShutDownHttpServer(this)); }