本文整理汇总了Java中org.apache.http.client.config.RequestConfig.DEFAULT属性的典型用法代码示例。如果您正苦于以下问题:Java RequestConfig.DEFAULT属性的具体用法?Java RequestConfig.DEFAULT怎么用?Java RequestConfig.DEFAULT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.http.client.config.RequestConfig
的用法示例。
在下文中一共展示了RequestConfig.DEFAULT属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAsyncRequest
@Override
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException {
HttpAsyncClient asyncClient = getHttpAsyncClient();
startAsyncClient();
HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri);
postProcessHttpRequest(httpRequest);
HttpContext context = createHttpContext(httpMethod, uri);
if (context == null) {
context = HttpClientContext.create();
}
// Request configuration not set in the context
if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
// Use request configuration given by the user, when available
RequestConfig config = null;
if (httpRequest instanceof Configurable) {
config = ((Configurable) httpRequest).getConfig();
}
if (config == null) {
config = RequestConfig.DEFAULT;
}
context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
}
return new HttpComponentsAsyncClientHttpRequest(asyncClient, httpRequest, context);
}
示例2: createRequest
@Override
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
CloseableHttpClient client = (CloseableHttpClient) getHttpClient();
Assert.state(client != null, "Synchronous execution requires an HttpClient to be set");
HttpUriRequest httpRequest = createHttpUriRequest(httpMethod, uri);
postProcessHttpRequest(httpRequest);
HttpContext context = createHttpContext(httpMethod, uri);
if (context == null) {
context = HttpClientContext.create();
}
// Request configuration not set in the context
if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
// Use request configuration given by the user, when available
RequestConfig config = null;
if (httpRequest instanceof Configurable) {
config = ((Configurable) httpRequest).getConfig();
}
if (config == null) {
if (this.socketTimeout > 0 || this.connectTimeout > 0) {
config = RequestConfig.custom()
.setConnectTimeout(this.connectTimeout)
.setSocketTimeout(this.socketTimeout)
.build();
}
else {
config = RequestConfig.DEFAULT;
}
}
context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
}
if (this.bufferRequestBody) {
return new HttpComponentsClientHttpRequest(client, httpRequest, context);
}
else {
return new HttpComponentsStreamingClientHttpRequest(client, httpRequest, context);
}
}