List of usage examples for org.apache.http.params CoreConnectionPNames CONNECTION_TIMEOUT
String CONNECTION_TIMEOUT
To view the source code for org.apache.http.params CoreConnectionPNames CONNECTION_TIMEOUT.
Click Source Link
From source file:org.apache.oozie.action.callback.CallbackActionExecutor.java
private HttpClient getHttpClient() { CallbackActionService callbackActionService = Services.get().get(CallbackActionService.class); HttpClient client = new DefaultHttpClient(callbackActionService.getConnectionManager()); client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, ConfigurationService.getInt(CallbackActionExecutor.CALLBACK_ACTION_HTTP_CONNECTION_TIMEOUT_SECS) * 1000);/*from w ww . j a v a2 s . c o m*/ client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, ConfigurationService.getInt(CallbackActionExecutor.CALLBACK_ACTION_HTTP_SOCKET_TIMEOUT_SECS) * 1000); client.getParams().setParameter(CoreConnectionPNames.SO_KEEPALIVE, ConfigurationService.getInt(CallbackActionExecutor.CALLBACK_ACTION_KEEPALIVE_SECS) * 1000); return client; }
From source file:org.apache.solr.cloud.FullSolrCloudTest.java
protected void initCloud() throws Exception { if (zkStateReader == null) { synchronized (this) { if (zkStateReader != null) { return; }/*ww w . j a va 2 s .co m*/ zkStateReader = new ZkStateReader(zkServer.getZkAddress(), 10000, AbstractZkTestCase.TIMEOUT); zkStateReader.createClusterStateWatchersAndUpdate(); } chaosMonkey = new ChaosMonkey(zkServer, zkStateReader, DEFAULT_COLLECTION, shardToJetty, shardToClient, shardToLeaderClient, shardToLeaderJetty, random()); } // wait until shards have started registering... while (!zkStateReader.getCloudState().getCollections().contains(DEFAULT_COLLECTION)) { Thread.sleep(500); } while (zkStateReader.getCloudState().getSlices(DEFAULT_COLLECTION).size() != sliceCount) { Thread.sleep(500); } // use the distributed solrj client if (cloudClient == null) { synchronized (this) { if (cloudClient != null) { return; } try { CloudSolrServer server = new CloudSolrServer(zkServer.getZkAddress()); server.setDefaultCollection(DEFAULT_COLLECTION); server.getLbServer().getHttpClient().getParams() .setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000); server.getLbServer().getHttpClient().getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 15000); cloudClient = server; } catch (MalformedURLException e) { throw new RuntimeException(e); } } } }
From source file:com.investoday.code.util.aliyun.api.gateway.util.HttpUtil.java
/** * HTTP PUT /*w w w .j a v a 2 s .c o m*/ * * @param url http://host+path+query * @param headers Http * @param body * @param appKey APP KEY * @param appSecret APP * @param timeout * @param signHeaderPrefixList ???Header? * @return * @throws Exception */ public static HttpResponse httpPut(String url, Map<String, String> headers, String body, String appKey, String appSecret, int timeout, List<String> signHeaderPrefixList) throws Exception { headers = initialBasicHeader(headers, appKey, appSecret, HttpMethod.PUT, url, null, signHeaderPrefixList); HttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, getTimeout(timeout)); HttpPut put = new HttpPut(url); for (Map.Entry<String, String> e : headers.entrySet()) { put.addHeader(e.getKey(), e.getValue()); } if (StringUtils.isNotBlank(body)) { put.setEntity(new StringEntity(body, Constants.ENCODING)); } return httpClient.execute(put); }
From source file:test.Http.java
/** * post url :??jsonString???json,?json//from w ww. j a v a2s . c o m * * @date * @param url * @param jsonString * @return * @throws Exception */ public static String httpPostWithJsons(String url, String jsonString) throws Exception { System.out.println("==url++" + url + "==jsonString" + jsonString); String responseBodyData = null; HttpClient httpClient = new DefaultHttpClient(); // httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 6000); // ? httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 6000); HttpPost httpPost = new HttpPost(url); httpPost.addHeader("Content-Type", "text/html"); // byte[] requestStrings = jsonString.toString().getBytes("UTF-8"); ByteArrayEntity byteArrayEntity = new ByteArrayEntity(requestStrings); httpPost.setEntity(byteArrayEntity); try { HttpResponse response = httpClient.execute(httpPost);// post if (response.getStatusLine().getStatusCode() == 200) { responseBodyData = EntityUtils.toString(response.getEntity()); } else { responseBodyData = null; } } catch (Exception e) { } finally { httpPost.abort(); httpClient = null; } return responseBodyData; }
From source file:cn.tc.ulife.platform.msg.http.util.HttpUtil.java
/** * HTTP PUT//from w w w .j a va2 s .com * @param host * @param path * @param connectTimeout * @param headers * @param querys * @param bodys * @param signHeaderPrefixList * @param appKey * @param appSecret * @return * @throws Exception */ public static Response httpPut(String host, String path, int connectTimeout, Map<String, String> headers, Map<String, String> querys, byte[] bodys, List<String> signHeaderPrefixList, String appKey, String appSecret) throws Exception { headers = initialBasicHeader(HttpMethod.PUT, path, headers, querys, null, signHeaderPrefixList, appKey, appSecret); HttpClient httpClient = wrapClient(host); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, getTimeout(connectTimeout)); HttpPut put = new HttpPut(initUrl(host, path, querys)); for (Map.Entry<String, String> e : headers.entrySet()) { put.addHeader(e.getKey(), MessageDigestUtil.utf8ToIso88591(e.getValue())); } if (bodys != null) { put.setEntity(new ByteArrayEntity(bodys)); } return convert(httpClient.execute(put)); }
From source file:com.example.aliyundemo.ocr.util.HttpUtil.java
/** * HTTP PUT//from w ww . j a v a 2 s. c o m * * @param url http://host+path+query * @param headers Http * @param bytes * @param appKey APP KEY * @param appSecret APP * @param timeout * @param signHeaderPrefixList ???Header? * @return * @throws Exception */ public static HttpResponse httpPut(String url, Map<String, String> headers, byte[] bytes, String appKey, String appSecret, int timeout, List<String> signHeaderPrefixList) throws Exception { headers = initialBasicHeader(headers, appKey, appSecret, HttpMethod.PUT, url, null, signHeaderPrefixList); HttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, getTimeout(timeout)); HttpPut put = new HttpPut(url); for (Map.Entry<String, String> e : headers.entrySet()) { put.addHeader(e.getKey(), MessageDigestUtil.utf8ToIso88591(e.getValue())); } if (bytes != null) { put.setEntity(new ByteArrayEntity(bytes)); } return httpClient.execute(put); }
From source file:org.graphity.core.util.jena.HttpQuery.java
private InputStream execGet() throws QueryExceptionHTTP { URL target = null;//from w w w .j a v a 2s .co m String qs = getQueryString(); ARQ.getHttpRequestLogger().trace(qs); try { if (count() == 0) target = new URL(serviceURL); else target = new URL(serviceURL + (serviceParams ? "&" : "?") + qs); } catch (MalformedURLException malEx) { throw new QueryExceptionHTTP(0, "Malformed URL: " + malEx); } log.trace("GET " + target.toExternalForm()); try { try { this.client = new SystemDefaultHttpClient(); // Always apply a 10 second timeout to obtaining a connection lease from HTTP Client // This prevents a potential lock up this.client.getParams().setLongParameter(ConnManagerPNames.TIMEOUT, TimeUnit.SECONDS.toMillis(10)); // If user has specified time outs apply them now if (this.connectTimeout > 0) this.client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, this.connectTimeout); if (this.readTimeout > 0) this.client.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, this.readTimeout); // Enable compression support appropriately HttpContext context = new BasicHttpContext(); if (allowGZip || allowDeflate) { // Apply auth early as the decompressing client we're about // to add will block this being applied later HttpOp.applyAuthentication((AbstractHttpClient) client, serviceURL, context, authenticator); client = new DecompressingHttpClient(client); } // Get the actual response stream TypedInputStream stream = HttpOp.execHttpGet(target.toString(), contentTypeResult, client, context, this.authenticator); if (stream == null) throw new QueryExceptionHTTP(404); return execCommon(stream); } catch (HttpException httpEx) { // Back-off and try POST if something complain about long URIs if (httpEx.getResponseCode() == 414) return execPost(); throw httpEx; } } catch (HttpException httpEx) { // Unwrap and re-wrap the HTTP exception responseCode = httpEx.getResponseCode(); throw new QueryExceptionHTTP(responseCode, "Error making the query, see cause for details", httpEx.getCause()); } }
From source file:org.bedework.util.http.BasicHttpClient.java
/** * @param host default host or null//from w ww .ja va 2s . c om * @param port default port if host supplied or -1 for default * @param scheme default scheme if host supplied or null for default * @param timeOut - millisecs, 0 for no timeout * @param followRedirects true for auto handling * @throws HttpException */ public BasicHttpClient(final String host, final int port, final String scheme, final int timeOut, final boolean followRedirects) throws HttpException { super(connManager, null); setKeepAliveStrategy(kas); if (sslDisabled) { warn("*******************************************************"); warn(" SSL disabled"); warn("*******************************************************"); } final HttpParams params = getParams(); if (host != null) { hostSpecified = true; final HttpHost httpHost = new HttpHost(host, port, scheme); params.setParameter(ClientPNames.DEFAULT_HOST, httpHost); } params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeOut); // XXX Should have separate value for this. params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeOut * 2); params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, followRedirects); }