本文整理汇总了Java中org.apache.http.client.methods.HttpRequestBase.releaseConnection方法的典型用法代码示例。如果您正苦于以下问题:Java HttpRequestBase.releaseConnection方法的具体用法?Java HttpRequestBase.releaseConnection怎么用?Java HttpRequestBase.releaseConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.client.methods.HttpRequestBase
的用法示例。
在下文中一共展示了HttpRequestBase.releaseConnection方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResponseAsString
import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
public static Optional<String> getResponseAsString(HttpRequestBase httpRequest, HttpClient client) {
Optional<String> result = Optional.empty();
final int waitTime = 60000;
try {
ResponseHandler<String> responseHandler = new BasicResponseHandler();
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(waitTime).setConnectTimeout(waitTime)
.setConnectionRequestTimeout(waitTime).build();
httpRequest.setConfig(requestConfig);
result = Optional.of(client.execute(httpRequest, responseHandler));
} catch (HttpResponseException httpResponseException) {
LOG.error("getResponseAsString(): caught 'HttpResponseException' while processing request <{}> :=> <{}>", httpRequest,
httpResponseException.getMessage());
} catch (IOException ioe) {
LOG.error("getResponseAsString(): caught 'IOException' while processing request <{}> :=> <{}>", httpRequest, ioe.getMessage());
} finally {
httpRequest.releaseConnection();
}
return result;
}
示例2: doRequest
import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
private <T> HttpResponse<T> doRequest(HttpRequest request, Class<T> responseClass) {
HttpRequestBase requestObj = prepareRequest(request, false);
org.apache.http.HttpResponse response;
try {
response = syncClient.execute(requestObj);
HttpResponse<T> httpResponse = new HttpResponse<>(response, responseClass, objectMapper);
requestObj.releaseConnection();
return httpResponse;
} catch (Exception e) {
throw new RestClientException(e);
} finally {
requestObj.releaseConnection();
}
}
示例3: save
import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
@Override public HttpResponse save (final IlluminatiEsModel entity) {
final HttpRequestBase httpPutRequest = new HttpPut(entity.getEsUrl(this.esUrl));
if (entity.isSetUserAuth() == true) {
try {
httpPutRequest.setHeader("Authorization", "Basic " + entity.getEsAuthString());
} catch (Exception ex) {
this.logger.error("Sorry. something is wrong in encoding es user auth info. ("+ex.toString()+")");
}
}
((HttpPut) httpPutRequest).setEntity(this.getHttpEntity(entity));
HttpResponse httpResponse = null;
try {
httpResponse = this.httpClient.execute(httpPutRequest);
} catch (IOException e) {
this.logger.error("Sorry. something is wrong in Http Request. ("+e.toString()+")");
} finally {
httpPutRequest.releaseConnection();
}
if (httpResponse == null) {
httpResponse = getHttpResponseByData(this.errorCode, "Sorry. something is wrong in Http Request.");
}
return httpResponse;
}
示例4: res
import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
private String res(HttpRequestBase method) {
HttpClientContext context = HttpClientContext.create();
CloseableHttpResponse response = null;
String content = RESPONSE_CONTENT;
try {
response = client.execute(method, context);//执行GET/POST请求
HttpEntity entity = response.getEntity();//获取响应实体
if(entity!=null) {
Charset charset = ContentType.getOrDefault(entity).getCharset();
content = EntityUtils.toString(entity, charset);
EntityUtils.consume(entity);
}
} catch(ConnectTimeoutException cte) {
LOG.error("请求连接超时,由于 " + cte.getLocalizedMessage());
cte.printStackTrace();
} catch(SocketTimeoutException ste) {
LOG.error("请求通信超时,由于 " + ste.getLocalizedMessage());
ste.printStackTrace();
} catch(ClientProtocolException cpe) {
LOG.error("协议错误(比如构造HttpGet对象时传入协议不对(将'http'写成'htp')or响应内容不符合),由于 " + cpe.getLocalizedMessage());
cpe.printStackTrace();
} catch(IOException ie) {
LOG.error("实体转换异常或者网络异常, 由于 " + ie.getLocalizedMessage());
ie.printStackTrace();
} finally {
try {
if(response!=null) {
response.close();
}
} catch(IOException e) {
LOG.error("响应关闭异常, 由于 " + e.getLocalizedMessage());
}
if(method!=null) {
method.releaseConnection();
}
}
return content;
}
示例5: getResponseContent
import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
private String getResponseContent(String url, HttpRequestBase request) throws Exception {
HttpResponse response = null;
try {
response = this.getHttpClient(2000,2000).execute(request);
return EntityUtils.toString(response.getEntity());
} catch (Exception e) {
throw new Exception("got an error from HTTP for url : " + URLDecoder.decode(url, "UTF-8"),e);
} finally {
if(response != null){
EntityUtils.consumeQuietly(response.getEntity());
}
request.releaseConnection();
}
}