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


Java HttpRequestBase.setConfig方法代码示例

本文整理汇总了Java中org.apache.http.client.methods.HttpRequestBase.setConfig方法的典型用法代码示例。如果您正苦于以下问题:Java HttpRequestBase.setConfig方法的具体用法?Java HttpRequestBase.setConfig怎么用?Java HttpRequestBase.setConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.client.methods.HttpRequestBase的用法示例。


在下文中一共展示了HttpRequestBase.setConfig方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: requestHttpGet

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
public String requestHttpGet(String url_prex, String type) throws HttpException, IOException {
	String url = url_prex + type;
	HttpRequestBase method = this.httpGetMethod(url, "");
	method.setConfig(requestConfig);
	long start = System.currentTimeMillis();
	HttpResponse response = client.execute(method);
	long end = System.currentTimeMillis();
	Logger.getGlobal().log(Level.INFO, String.valueOf(end - start));
	HttpEntity entity = response.getEntity();
	if (entity == null) {
		return "";
	}
	InputStream is = null;
	String responseData = "";
	try {
		is = entity.getContent();
		responseData = IOUtils.toString(is, "UTF-8");
	} finally {
		if (is != null) {
			is.close();
		}
	}
	return responseData;
}
 
开发者ID:bitstd,项目名称:bitstd,代码行数:25,代码来源:HttpUtilManager.java

示例2: 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

示例3: addRequestConfig

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
private void addRequestConfig(final HttpRequestBase base,
                              final SdkHttpFullRequest request,
                              final ApacheHttpRequestConfig requestConfig) {
    final int connectTimeout = saturatedCast(requestConfig.connectionTimeout().toMillis());
    final RequestConfig.Builder requestConfigBuilder = RequestConfig
            .custom()
            .setConnectionRequestTimeout(connectTimeout)
            .setConnectTimeout(connectTimeout)
            .setSocketTimeout(saturatedCast(requestConfig.socketTimeout().toMillis()))
            .setLocalAddress(requestConfig.localAddress());

    /*
     * Enable 100-continue support for PUT operations, since this is
     * where we're potentially uploading large amounts of data and want
     * to find out as early as possible if an operation will fail. We
     * don't want to do this for all operations since it will cause
     * extra latency in the network interaction.
     */
    if (SdkHttpMethod.PUT == request.method() && requestConfig.expectContinueEnabled()) {
        requestConfigBuilder.setExpectContinueEnabled(true);
    }

    base.setConfig(requestConfigBuilder.build());
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:25,代码来源:ApacheHttpRequestFactory.java

示例4: addRequestConfig

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
private void addRequestConfig(final HttpRequestBase base,
                              final Request<?> request,
                              final HttpClientSettings settings) {
    final RequestConfig.Builder requestConfigBuilder = RequestConfig
            .custom()
            .setConnectionRequestTimeout(settings.getConnectionPoolRequestTimeout())
            .setConnectTimeout(settings.getConnectionTimeout())
            .setSocketTimeout(settings.getSocketTimeout())
            .setLocalAddress(settings.getLocalAddress());

    /*
     * Enable 100-continue support for PUT operations, since this is
     * where we're potentially uploading large amounts of data and want
     * to find out as early as possible if an operation will fail. We
     * don't want to do this for all operations since it will cause
     * extra latency in the network interaction.
     */
    if (HttpMethodName.PUT == request.getHttpMethod() && settings.isUseExpectContinue()) {
        requestConfigBuilder.setExpectContinueEnabled(true);
    }

    addProxyConfig(requestConfigBuilder, settings);

    base.setConfig(requestConfigBuilder.build());
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:26,代码来源:ApacheHttpRequestFactory.java

示例5: config

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
private static void config(HttpRequestBase httpRequestBase) {
    RequestConfig requestConfig = RequestConfig.custom()
            .setConnectionRequestTimeout(TIMEOUT)
            .setConnectTimeout(TIMEOUT)
            .setSocketTimeout(TIMEOUT)
            .build();
    httpRequestBase.setConfig(requestConfig);
}
 
开发者ID:Evan1120,项目名称:wechat-api-java,代码行数:9,代码来源:HttpRequestUtil.java

示例6: getRequest

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
public HttpRequestBase getRequest(){
	String url = getUrl();
	HttpRequestBase request = getRequest(url);
	if(!headers.isEmpty()){
		for(Entry<String,List<String>> header : headers.entrySet()){
			for(String headerValue : header.getValue()){
				request.addHeader(header.getKey(), headerValue);
			}
		}
	}
	if(entity != null && canHaveEntity()){
		((HttpEntityEnclosingRequest) request).setEntity(entity);
	}
	if(timeoutMs != null || proxy != null){
		Builder builder = RequestConfig.custom();
		builder.setCookieSpec(CookieSpecs.STANDARD);
		if(timeoutMs != null){
			builder.setConnectTimeout(timeoutMs).setConnectionRequestTimeout(timeoutMs).setSocketTimeout(timeoutMs);
		}
		if(proxy != null){
			builder.setProxy(proxy);
		}

		RequestConfig requestConfig = builder.build();
		request.setConfig(requestConfig);
	}
	return request;
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:29,代码来源:DatarouterHttpRequest.java

示例7: handlerRequestConfig

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
/**
 * @param connectTimeout
 * @param socketTimeout
 * @param httpRequestBase
 */
private void handlerRequestConfig(int connectTimeout, int socketTimeout, HttpRequestBase httpRequestBase) {
    RequestConfig requestConfig = RequestConfig.custom()
            .setConnectionRequestTimeout(connectTimeout)
            .setConnectTimeout(connectTimeout)
            .setSocketTimeout(socketTimeout).build();
    httpRequestBase.setConfig(requestConfig);
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:13,代码来源:AsuraCommonsHttpclient.java

示例8: setHttpParams

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
public static void setHttpParams(HttpRequestBase httpBase,
		int connectMillisTimeout, int readMillisTimeout,
		boolean handleRedirects) {
	RequestConfig requestConfig = RequestConfig.copy(defaultRequestConfig)
			.setConnectTimeout(connectMillisTimeout)
			.setSocketTimeout(readMillisTimeout)
			.setRedirectsEnabled(handleRedirects).build();

	httpBase.setConfig(requestConfig);
	httpBase.setHeader("accept-encoding", "gzip");
}
 
开发者ID:marlonwang,项目名称:raven,代码行数:12,代码来源:HttpConnectionAdaptor.java

示例9: setProxy

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
public static void setProxy(HttpRequestBase method, Proxy proxy) {
    method.setConfig(RequestConfig.custom().setProxy(new HttpHost(proxy.getHostname(), proxy.getPort())).build());
}
 
开发者ID:mercadolibre,项目名称:java-restclient,代码行数:4,代码来源:HTTPCUtil.java

示例10: setHttpConfig

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
/**
 * 设置响应超时时间
 */
public void setHttpConfig(HttpRequestBase httpMethod){
    RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).build();
    httpMethod.setConfig(requestConfig);
}
 
开发者ID:java-webbee,项目名称:webBee,代码行数:8,代码来源:HttpClientPool.java


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