本文整理汇总了Java中org.apache.http.client.methods.Configurable类的典型用法代码示例。如果您正苦于以下问题:Java Configurable类的具体用法?Java Configurable怎么用?Java Configurable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Configurable类属于org.apache.http.client.methods包,在下文中一共展示了Configurable类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createAsyncRequest
import org.apache.http.client.methods.Configurable; //导入依赖的package包/类
@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 = createRequestConfig(asyncClient);
}
if (config != null) {
context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
}
}
return new HttpComponentsAsyncClientHttpRequest(asyncClient, httpRequest, context);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:HttpComponentsAsyncClientHttpRequestFactory.java
示例2: defaultSettingsOfHttpClientMergedOnExecutorCustomization
import org.apache.http.client.methods.Configurable; //导入依赖的package包/类
@Test
public void defaultSettingsOfHttpClientMergedOnExecutorCustomization() throws IOException {
RequestConfig defaultConfig = RequestConfig.custom().setConnectTimeout(1234).build();
CloseableHttpClient client = mock(CloseableHttpClient.class,
withSettings().extraInterfaces(Configurable.class));
Configurable configurable = (Configurable) client;
when(configurable.getConfig()).thenReturn(defaultConfig);
HttpComponentsHttpInvokerRequestExecutor executor =
new HttpComponentsHttpInvokerRequestExecutor(client);
HttpInvokerClientConfiguration config = mockHttpInvokerClientConfiguration("http://fake-service");
HttpPost httpPost = executor.createHttpPost(config);
assertSame("Default client configuration is expected", defaultConfig, httpPost.getConfig());
executor.setConnectionRequestTimeout(4567);
HttpPost httpPost2 = executor.createHttpPost(config);
assertNotNull(httpPost2.getConfig());
assertEquals(4567, httpPost2.getConfig().getConnectionRequestTimeout());
// Default connection timeout merged
assertEquals(1234, httpPost2.getConfig().getConnectTimeout());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:HttpComponentsHttpInvokerRequestExecutorTests.java
示例3: localSettingsOverrideClientDefaultSettings
import org.apache.http.client.methods.Configurable; //导入依赖的package包/类
@Test
public void localSettingsOverrideClientDefaultSettings() throws Exception {
RequestConfig defaultConfig = RequestConfig.custom()
.setConnectTimeout(1234).setConnectionRequestTimeout(6789).build();
CloseableHttpClient client = mock(CloseableHttpClient.class,
withSettings().extraInterfaces(Configurable.class));
Configurable configurable = (Configurable) client;
when(configurable.getConfig()).thenReturn(defaultConfig);
HttpComponentsHttpInvokerRequestExecutor executor =
new HttpComponentsHttpInvokerRequestExecutor(client);
executor.setConnectTimeout(5000);
HttpInvokerClientConfiguration config = mockHttpInvokerClientConfiguration("http://fake-service");
HttpPost httpPost = executor.createHttpPost(config);
RequestConfig requestConfig = httpPost.getConfig();
assertEquals(5000, requestConfig.getConnectTimeout());
assertEquals(6789, requestConfig.getConnectionRequestTimeout());
assertEquals(-1, requestConfig.getSocketTimeout());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:HttpComponentsHttpInvokerRequestExecutorTests.java
示例4: defaultSettingsOfHttpClientMergedOnExecutorCustomization
import org.apache.http.client.methods.Configurable; //导入依赖的package包/类
@Test
public void defaultSettingsOfHttpClientMergedOnExecutorCustomization() throws Exception {
RequestConfig defaultConfig = RequestConfig.custom().setConnectTimeout(1234).build();
CloseableHttpClient client = mock(CloseableHttpClient.class,
withSettings().extraInterfaces(Configurable.class));
Configurable configurable = (Configurable) client;
when(configurable.getConfig()).thenReturn(defaultConfig);
HttpComponentsClientHttpRequestFactory hrf = new HttpComponentsClientHttpRequestFactory(client);
assertSame("Default client configuration is expected", defaultConfig, retrieveRequestConfig(hrf));
hrf.setConnectionRequestTimeout(4567);
RequestConfig requestConfig = retrieveRequestConfig(hrf);
assertNotNull(requestConfig);
assertEquals(4567, requestConfig.getConnectionRequestTimeout());
// Default connection timeout merged
assertEquals(1234, requestConfig.getConnectTimeout());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:HttpComponentsClientHttpRequestFactoryTests.java
示例5: localSettingsOverrideClientDefaultSettings
import org.apache.http.client.methods.Configurable; //导入依赖的package包/类
@Test
public void localSettingsOverrideClientDefaultSettings() throws Exception {
RequestConfig defaultConfig = RequestConfig.custom()
.setConnectTimeout(1234).setConnectionRequestTimeout(6789).build();
CloseableHttpClient client = mock(CloseableHttpClient.class,
withSettings().extraInterfaces(Configurable.class));
Configurable configurable = (Configurable) client;
when(configurable.getConfig()).thenReturn(defaultConfig);
HttpComponentsClientHttpRequestFactory hrf = new HttpComponentsClientHttpRequestFactory(client);
hrf.setConnectTimeout(5000);
RequestConfig requestConfig = retrieveRequestConfig(hrf);
assertEquals(5000, requestConfig.getConnectTimeout());
assertEquals(6789, requestConfig.getConnectionRequestTimeout());
assertEquals(-1, requestConfig.getSocketTimeout());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:HttpComponentsClientHttpRequestFactoryTests.java
示例6: internalExecute
import org.apache.http.client.methods.Configurable; //导入依赖的package包/类
HttpResponse internalExecute(
final HttpClient client,
final HttpContext localContext) throws ClientProtocolException, IOException {
final RequestConfig.Builder builder;
if (client instanceof Configurable) {
builder = RequestConfig.copy(((Configurable) client).getConfig());
} else {
builder = RequestConfig.custom();
}
if (this.useExpectContinue != null) {
builder.setExpectContinueEnabled(this.useExpectContinue);
}
if (this.socketTmeout != null) {
builder.setSocketTimeout(this.socketTmeout);
}
if (this.connectTimeout != null) {
builder.setConnectTimeout(this.connectTimeout);
}
if (this.proxy != null) {
builder.setProxy(this.proxy);
}
final RequestConfig config = builder.build();
this.request.setConfig(config);
return client.execute(this.request, localContext);
}
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:Request.java
示例7: createAsyncRequest
import org.apache.http.client.methods.Configurable; //导入依赖的package包/类
@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);
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:HttpComponentsAsyncClientHttpRequestFactory.java
示例8: createRequest
import org.apache.http.client.methods.Configurable; //导入依赖的package包/类
@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);
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:38,代码来源:HttpComponentsClientHttpRequestFactory.java
示例9: createRequest
import org.apache.http.client.methods.Configurable; //导入依赖的package包/类
@Override
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
HttpClient client = 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) {
config = createRequestConfig(client);
}
if (config != null) {
context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
}
}
if (this.bufferRequestBody) {
return new HttpComponentsClientHttpRequest(client, httpRequest, context);
}
else {
return new HttpComponentsStreamingClientHttpRequest(client, httpRequest, context);
}
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:35,代码来源:HttpComponentsClientHttpRequestFactory.java
示例10: mergeBasedOnCurrentHttpClient
import org.apache.http.client.methods.Configurable; //导入依赖的package包/类
@Test
public void mergeBasedOnCurrentHttpClient() throws Exception {
RequestConfig defaultConfig = RequestConfig.custom()
.setSocketTimeout(1234).build();
final CloseableHttpClient client = mock(CloseableHttpClient.class,
withSettings().extraInterfaces(Configurable.class));
Configurable configurable = (Configurable) client;
when(configurable.getConfig()).thenReturn(defaultConfig);
HttpComponentsHttpInvokerRequestExecutor executor =
new HttpComponentsHttpInvokerRequestExecutor() {
@Override
public HttpClient getHttpClient() {
return client;
}
};
executor.setReadTimeout(5000);
HttpInvokerClientConfiguration config = mockHttpInvokerClientConfiguration("http://fake-service");
HttpPost httpPost = executor.createHttpPost(config);
RequestConfig requestConfig = httpPost.getConfig();
assertEquals(-1, requestConfig.getConnectTimeout());
assertEquals(-1, requestConfig.getConnectionRequestTimeout());
assertEquals(5000, requestConfig.getSocketTimeout());
// Update the Http client so that it returns an updated config
RequestConfig updatedDefaultConfig = RequestConfig.custom()
.setConnectTimeout(1234).build();
when(configurable.getConfig()).thenReturn(updatedDefaultConfig);
executor.setReadTimeout(7000);
HttpPost httpPost2 = executor.createHttpPost(config);
RequestConfig requestConfig2 = httpPost2.getConfig();
assertEquals(1234, requestConfig2.getConnectTimeout());
assertEquals(-1, requestConfig2.getConnectionRequestTimeout());
assertEquals(7000, requestConfig2.getSocketTimeout());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:36,代码来源:HttpComponentsHttpInvokerRequestExecutorTests.java
示例11: mergeBasedOnCurrentHttpClient
import org.apache.http.client.methods.Configurable; //导入依赖的package包/类
@Test
public void mergeBasedOnCurrentHttpClient() throws Exception {
RequestConfig defaultConfig = RequestConfig.custom()
.setSocketTimeout(1234).build();
final CloseableHttpClient client = mock(CloseableHttpClient.class,
withSettings().extraInterfaces(Configurable.class));
Configurable configurable = (Configurable) client;
when(configurable.getConfig()).thenReturn(defaultConfig);
HttpComponentsClientHttpRequestFactory hrf = new HttpComponentsClientHttpRequestFactory() {
@Override
public HttpClient getHttpClient() {
return client;
}
};
hrf.setReadTimeout(5000);
RequestConfig requestConfig = retrieveRequestConfig(hrf);
assertEquals(-1, requestConfig.getConnectTimeout());
assertEquals(-1, requestConfig.getConnectionRequestTimeout());
assertEquals(5000, requestConfig.getSocketTimeout());
// Update the Http client so that it returns an updated config
RequestConfig updatedDefaultConfig = RequestConfig.custom()
.setConnectTimeout(1234).build();
when(configurable.getConfig()).thenReturn(updatedDefaultConfig);
hrf.setReadTimeout(7000);
RequestConfig requestConfig2 = retrieveRequestConfig(hrf);
assertEquals(1234, requestConfig2.getConnectTimeout());
assertEquals(-1, requestConfig2.getConnectionRequestTimeout());
assertEquals(7000, requestConfig2.getSocketTimeout());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:33,代码来源:HttpComponentsClientHttpRequestFactoryTests.java
示例12: should_jest_auto_configuration_have_custom_httpbuilder
import org.apache.http.client.methods.Configurable; //导入依赖的package包/类
@Test
public void should_jest_auto_configuration_have_custom_httpbuilder() {
RequestConfig config = ((Configurable) ((JestHttpClient) jestClient).getHttpClient()).getConfig();
int connectTimeout = config.getConnectTimeout();
assertThat(connectTimeout, is(3551));
}
开发者ID:VanRoy,项目名称:spring-data-jest,代码行数:9,代码来源:ElasticsearchJestAutoConfigurationWithCustomHttpConfigurerTest.java
示例13: shouldApplyTimeouts
import org.apache.http.client.methods.Configurable; //导入依赖的package包/类
@Test
public void shouldApplyTimeouts() throws Exception {
assertThat("Configurable http client expected", exampleHttpClient, is(instanceOf(Configurable.class)));
final RequestConfig config = ((Configurable) exampleHttpClient).getConfig();
assertThat(config.getSocketTimeout(), is(34 * 60 * 60 * 1000));
assertThat(config.getConnectTimeout(), is(12 * 60 * 1000));
}
开发者ID:zalando-stups,项目名称:put-it-to-rest,代码行数:10,代码来源:ClientConfigurationTest.java
示例14: RestAsyncClientHttpRequestFactory
import org.apache.http.client.methods.Configurable; //导入依赖的package包/类
public RestAsyncClientHttpRequestFactory(final HttpClient client, final AsyncListenableTaskExecutor executor) {
final RequestConfig config = Configurable.class.cast(client).getConfig();
this.factory = new HttpComponentsClientHttpRequestFactory(client) {
@Override
protected void postProcessHttpRequest(final HttpUriRequest request) {
// restore the client's request settings that are incorrectly handled by spring
HttpRequestBase.class.cast(request).setConfig(config);
}
};
this.executor = executor;
}
开发者ID:zalando,项目名称:riptide,代码行数:13,代码来源:RestAsyncClientHttpRequestFactory.java
示例15: doExecute
import org.apache.http.client.methods.Configurable; //导入依赖的package包/类
@Override
protected CloseableHttpResponse doExecute(
final HttpHost target,
final HttpRequest request,
final HttpContext context) throws IOException, ClientProtocolException {
Args.notNull(target, "Target host");
Args.notNull(request, "HTTP request");
HttpExecutionAware execAware = null;
if (request instanceof HttpExecutionAware) {
execAware = (HttpExecutionAware) request;
}
try {
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(request);
final HttpClientContext localcontext = HttpClientContext.adapt(
context != null ? context : new BasicHttpContextHC4());
final HttpRoute route = new HttpRoute(target);
RequestConfig config = null;
if (request instanceof Configurable) {
config = ((Configurable) request).getConfig();
}
if (config != null) {
localcontext.setRequestConfig(config);
}
return this.requestExecutor.execute(route, wrapper, localcontext, execAware);
} catch (final HttpException httpException) {
throw new ClientProtocolException(httpException);
}
}
开发者ID:SxdsF,项目名称:Visit,代码行数:29,代码来源:MinimalHttpClient.java
示例16: doExecute
import org.apache.http.client.methods.Configurable; //导入依赖的package包/类
@Override
protected CloseableHttpResponse doExecute(
final HttpHost target,
final HttpRequest request,
final HttpContext context) throws IOException, ClientProtocolException {
Args.notNull(request, "HTTP request");
HttpExecutionAware execAware = null;
if (request instanceof HttpExecutionAware) {
execAware = (HttpExecutionAware) request;
}
try {
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(request);
final HttpClientContext localcontext = HttpClientContext.adapt(
context != null ? context : new BasicHttpContextHC4());
RequestConfig config = null;
if (request instanceof Configurable) {
config = ((Configurable) request).getConfig();
}
if (config == null) {
final HttpParams params = request.getParams();
if (params instanceof HttpParamsNames) {
if (!((HttpParamsNames) params).getNames().isEmpty()) {
config = HttpClientParamConfig.getRequestConfig(params);
}
} else {
config = HttpClientParamConfig.getRequestConfig(params);
}
}
if (config != null) {
localcontext.setRequestConfig(config);
}
setupContext(localcontext);
final HttpRoute route = determineRoute(target, wrapper, localcontext);
return this.execChain.execute(route, wrapper, localcontext, execAware);
} catch (final HttpException httpException) {
throw new ClientProtocolException(httpException);
}
}
开发者ID:SxdsF,项目名称:Visit,代码行数:39,代码来源:InternalHttpClient.java
示例17: createClient
import org.apache.http.client.methods.Configurable; //导入依赖的package包/类
@Test
public void createClient() throws Exception {
final RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(100)
.setConnectTimeout(200).setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
CloseableHttpClient httpClient = new DefaultApacheHttpClientFactory(HttpClientBuilder.create()).createBuilder().
setConnectionManager(mock(HttpClientConnectionManager.class)).
setDefaultRequestConfig(requestConfig).build();
Assertions.assertThat(httpClient).isInstanceOf(Configurable.class);
RequestConfig config = ((Configurable) httpClient).getConfig();
assertEquals(100, config.getSocketTimeout());
assertEquals(200, config.getConnectTimeout());
assertEquals(CookieSpecs.IGNORE_COOKIES, config.getCookieSpec());
}
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:14,代码来源:DefaultApacheHttpClientFactoryTests.java
示例18: timeoutPropertiesAreApplied
import org.apache.http.client.methods.Configurable; //导入依赖的package包/类
@Test
public void timeoutPropertiesAreApplied() {
addEnvironment(this.context, "zuul.host.socket-timeout-millis=11000",
"zuul.host.connect-timeout-millis=2100");
setupContext();
CloseableHttpClient httpClient = getFilter().newClient();
Assertions.assertThat(httpClient).isInstanceOf(Configurable.class);
RequestConfig config = ((Configurable) httpClient).getConfig();
assertEquals(11000, config.getSocketTimeout());
assertEquals(2100, config.getConnectTimeout());
}
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:12,代码来源:SimpleHostRoutingFilterTests.java
示例19: exampleHttpClient
import org.apache.http.client.methods.Configurable; //导入依赖的package包/类
@Bean
@Qualifier("example")
public HttpClient exampleHttpClient() {
return mock(HttpClient.class, withSettings().extraInterfaces(Configurable.class));
}
开发者ID:zalando-stups,项目名称:put-it-to-rest,代码行数:6,代码来源:HttpAsyncClientOverrideTest.java
示例20: createRequestConfig
import org.apache.http.client.methods.Configurable; //导入依赖的package包/类
/**
* Create a {@link RequestConfig} for the given configuration. Can return {@code null}
* to indicate that no custom request config should be set and the defaults of the
* {@link HttpClient} should be used.
* <p>The default implementation tries to merge the defaults of the client with the
* local customizations of the instance, if any.
* @param config the HTTP invoker configuration that specifies the
* target service
* @return the RequestConfig to use
*/
protected RequestConfig createRequestConfig(HttpInvokerClientConfiguration config) {
HttpClient client = getHttpClient();
if (client instanceof Configurable) {
RequestConfig clientRequestConfig = ((Configurable) client).getConfig();
return mergeRequestConfig(clientRequestConfig);
}
return this.requestConfig;
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:HttpComponentsHttpInvokerRequestExecutor.java
注:本文中的org.apache.http.client.methods.Configurable类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论