当前位置: 首页>>代码示例>>Java>>正文


Java HttpRequestBase.releaseConnection方法代码示例

本文整理汇总了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;
}
 
开发者ID:dockstore,项目名称:write_api_service,代码行数:20,代码来源:ResourceUtilities.java

示例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();
    }

}
 
开发者ID:josueeduardo,项目名称:rest-client,代码行数:17,代码来源:ClientRequest.java

示例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;
}
 
开发者ID:LeeKyoungIl,项目名称:illuminati,代码行数:30,代码来源:ESclientImpl.java

示例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;
}
 
开发者ID:TransientBuckwheat,项目名称:nest-spider,代码行数:43,代码来源:HttpClientUtil.java

示例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();
    }
}
 
开发者ID:quietUncle,项目名称:vartrans,代码行数:15,代码来源:HttpClientPool.java


注:本文中的org.apache.http.client.methods.HttpRequestBase.releaseConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。