• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java AsyncClientHttpRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.http.client.AsyncClientHttpRequest的典型用法代码示例。如果您正苦于以下问题:Java AsyncClientHttpRequest类的具体用法?Java AsyncClientHttpRequest怎么用?Java AsyncClientHttpRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AsyncClientHttpRequest类属于org.springframework.http.client包,在下文中一共展示了AsyncClientHttpRequest类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: doExecute

import org.springframework.http.client.AsyncClientHttpRequest; //导入依赖的package包/类
/**
 * Execute the given method on the provided URI. The
 * {@link org.springframework.http.client.ClientHttpRequest}
 * is processed using the {@link RequestCallback}; the response with
 * the {@link ResponseExtractor}.
 * @param url the fully-expanded URL to connect to
 * @param method the HTTP method to execute (GET, POST, etc.)
 * @param requestCallback object that prepares the request (can be {@code null})
 * @param responseExtractor object that extracts the return value from the response (can
 * be {@code null})
 * @return an arbitrary object, as returned by the {@link ResponseExtractor}
 */
protected <T> ListenableFuture<T> doExecute(URI url, HttpMethod method, AsyncRequestCallback requestCallback,
		ResponseExtractor<T> responseExtractor) throws RestClientException {

	Assert.notNull(url, "'url' must not be null");
	Assert.notNull(method, "'method' must not be null");
	try {
		AsyncClientHttpRequest request = createAsyncRequest(url, method);
		if (requestCallback != null) {
			requestCallback.doWithRequest(request);
		}
		ListenableFuture<ClientHttpResponse> responseFuture = request.executeAsync();
		return new ResponseExtractorFuture<T>(method, url, responseFuture,
				responseExtractor);
	}
	catch (IOException ex) {
		throw new ResourceAccessException("I/O error on " + method.name() +
				" request for \"" + url + "\":" + ex.getMessage(), ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:32,代码来源:AsyncRestTemplate.java


示例2: doExecute

import org.springframework.http.client.AsyncClientHttpRequest; //导入依赖的package包/类
/**
 * Execute the given method on the provided URI. The
 * {@link org.springframework.http.client.ClientHttpRequest}
 * is processed using the {@link RequestCallback}; the response with
 * the {@link ResponseExtractor}.
 * @param url the fully-expanded URL to connect to
 * @param method the HTTP method to execute (GET, POST, etc.)
 * @param requestCallback object that prepares the request (can be {@code null})
 * @param responseExtractor object that extracts the return value from the response (can
 * be {@code null})
 * @return an arbitrary object, as returned by the {@link ResponseExtractor}
 */
protected <T> ListenableFuture<T> doExecute(URI url, HttpMethod method, AsyncRequestCallback requestCallback,
		ResponseExtractor<T> responseExtractor) throws RestClientException {

	Assert.notNull(url, "'url' must not be null");
	Assert.notNull(method, "'method' must not be null");
	try {
		AsyncClientHttpRequest request = createAsyncRequest(url, method);
		if (requestCallback != null) {
			requestCallback.doWithRequest(request);
		}
		ListenableFuture<ClientHttpResponse> responseFuture = request.executeAsync();
		return new ResponseExtractorFuture<T>(method, url, responseFuture, responseExtractor);
	}
	catch (IOException ex) {
		throw new ResourceAccessException("I/O error on " + method.name() +
				" request for \"" + url + "\":" + ex.getMessage(), ex);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:31,代码来源:AsyncRestTemplate.java


示例3: write

import org.springframework.http.client.AsyncClientHttpRequest; //导入依赖的package包/类
@Override
public <T> void write(final AsyncClientHttpRequest request, final HttpEntity<T> entity) throws IOException {
    final HttpHeaders headers = entity.getHeaders();
    request.getHeaders().putAll(headers);

    @Nullable final T body = entity.getBody();

    if (body == null) {
        return;
    }

    final Class<?> type = body.getClass();
    @Nullable final MediaType contentType = headers.getContentType();

    converters.stream()
            .filter(converter -> converter.canWrite(type, contentType))
            .map(this::<T>cast)
            .findFirst()
            .orElseThrow(() -> fail(type, contentType))
            .write(body, contentType, request);
}
 
开发者ID:zalando,项目名称:riptide,代码行数:22,代码来源:MessageWorker.java


示例4: doWithRequest

import org.springframework.http.client.AsyncClientHttpRequest; //导入依赖的package包/类
@Override
public void doWithRequest(final AsyncClientHttpRequest request) throws IOException {
	if (this.adaptee != null) {
		this.adaptee.doWithRequest(new ClientHttpRequest() {
			@Override
			public ClientHttpResponse execute() throws IOException {
				throw new UnsupportedOperationException("execute not supported");
			}
			@Override
			public OutputStream getBody() throws IOException {
				return request.getBody();
			}
			@Override
			public HttpMethod getMethod() {
				return request.getMethod();
			}
			@Override
			public URI getURI() {
				return request.getURI();
			}
			@Override
			public HttpHeaders getHeaders() {
				return request.getHeaders();
			}
		});
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:AsyncRestTemplate.java


示例5: createAsyncRequest

import org.springframework.http.client.AsyncClientHttpRequest; //导入依赖的package包/类
/**
 * Create a new {@link AsyncClientHttpRequest} via this template's {@link
 * AsyncClientHttpRequestFactory}.
 * @param url the URL to connect to
 * @param method the HTTP method to execute (GET, POST, etc.)
 * @return the created request
 * @throws IOException in case of I/O errors
 */
protected AsyncClientHttpRequest createAsyncRequest(URI url, HttpMethod method)
		throws IOException {
	AsyncClientHttpRequest request = getAsyncRequestFactory().createAsyncRequest(url, method);
	if (logger.isDebugEnabled()) {
		logger.debug("Created asynchronous " + method.name() + " request for \"" + url + "\"");
	}
	return request;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:AsyncHttpAccessor.java


示例6: createAsyncRequest

import org.springframework.http.client.AsyncClientHttpRequest; //导入依赖的package包/类
@Override
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod)
		throws IOException {
	AsyncClientHttpRequest request = this.asyncDelegate
			.createAsyncRequest(uri, httpMethod);
	addRequestTags(request);
	publishStartEvent(request);
	return request;
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:10,代码来源:TraceAsyncClientHttpRequestFactoryWrapper.java


示例7: send

import org.springframework.http.client.AsyncClientHttpRequest; //导入依赖的package包/类
private CompletableFuture<ClientHttpResponse> send() throws IOException {
    final AsyncClientHttpRequest request = createRequest();
    worker.write(request, entity);
    final ListenableFuture<ClientHttpResponse> original = request.executeAsync();

    final CompletableFuture<ClientHttpResponse> future = preserveCancelability(original);
    original.addCallback(future::complete, future::completeExceptionally);
    return future;
}
 
开发者ID:zalando,项目名称:riptide,代码行数:10,代码来源:Requester.java


示例8: shouldReadContributorsManually

import org.springframework.http.client.AsyncClientHttpRequest; //导入依赖的package包/类
@Test
public void shouldReadContributorsManually() throws IOException, ExecutionException, InterruptedException {
    driver.addExpectation(onRequestTo("/repos/zalando/riptide/contributors").withMethod(Method.POST),
            giveResponseAsBytes(getResource("contributors.json").openStream(), "application/json"));

    final URI uri = URI.create(driver.getBaseUrl()).resolve("/repos/zalando/riptide/contributors");
    final AsyncClientHttpRequest request = factory.createAsyncRequest(uri, POST);

    request.getHeaders().setAccept(singletonList(APPLICATION_JSON));
    request.getBody().write("{}".getBytes(UTF_8));

    assertThat(request.getMethod(), is(POST));
    assertThat(request.getURI(), hasToString(endsWith("/repos/zalando/riptide/contributors")));
    assertThat(request.getHeaders().getAccept(), hasItem(APPLICATION_JSON));

    final ClientHttpResponse response = request.executeAsync().get();

    assertThat(response.getStatusCode(), is(HttpStatus.OK));
    assertThat(response.getRawStatusCode(), is(200));
    assertThat(response.getStatusText(), is("OK"));
    assertThat(response.getHeaders(), is(not(anEmptyMap())));

    final InputStream stream = response.getBody();
    final ObjectMapper mapper = createObjectMapper();
    final List<User> users = mapper.readValue(stream, new TypeReference<List<User>>() { });
    final List<String> names = users.stream()
            .map(User::getLogin)
            .collect(toList());

    assertThat(names, hasItems("jhorstmann", "lukasniemeier-zalando", "whiskeysierra"));
}
 
开发者ID:zalando,项目名称:riptide,代码行数:32,代码来源:RestAsyncClientHttpRequestFactoryTest.java


示例9: afterMethod

import org.springframework.http.client.AsyncClientHttpRequest; //导入依赖的package包/类
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    Object ret) throws Throwable {
    AsyncClientHttpRequest clientHttpRequest = (AsyncClientHttpRequest)ret;
    if (ret != null) {
        Object[] cacheValues = (Object[])objInst.getSkyWalkingDynamicField();
        ContextCarrier contextCarrier = (ContextCarrier)cacheValues[1];
        CarrierItem next = contextCarrier.items();
        while (next.hasNext()) {
            next = next.next();
            clientHttpRequest.getHeaders().set(next.getHeadKey(), next.getHeadValue());
        }
    }
    return ret;
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:16,代码来源:RestRequestInterceptor.java


示例10: createAsyncRequest

import org.springframework.http.client.AsyncClientHttpRequest; //导入依赖的package包/类
@Override
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException {
	return createRequestInternal(uri, httpMethod);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:5,代码来源:MockRestServiceServer.java


示例11: createRequest

import org.springframework.http.client.AsyncClientHttpRequest; //导入依赖的package包/类
private AsyncClientHttpRequest createRequest() throws IOException {
    final URI requestUri = arguments.getRequestUri();
    final HttpMethod method = arguments.getMethod();
    return requestFactory.createAsyncRequest(requestUri, method);
}
 
开发者ID:zalando,项目名称:riptide,代码行数:6,代码来源:Requester.java


示例12: createAsyncRequest

import org.springframework.http.client.AsyncClientHttpRequest; //导入依赖的package包/类
@Override
public AsyncClientHttpRequest createAsyncRequest(final URI uri, final HttpMethod method) throws IOException {
    return new RestAsyncClientHttpRequest(factory.createRequest(uri, method), executor);
}
 
开发者ID:zalando,项目名称:riptide,代码行数:5,代码来源:RestAsyncClientHttpRequestFactory.java


示例13: createAsyncRequest

import org.springframework.http.client.AsyncClientHttpRequest; //导入依赖的package包/类
@Override
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException {
	return super.createAsyncRequest(expand(uri), httpMethod);
}
 
开发者ID:spencergibb,项目名称:myfeed,代码行数:5,代码来源:RibbonAsyncClientHttpRequestFactory.java


示例14: createAsyncRequest

import org.springframework.http.client.AsyncClientHttpRequest; //导入依赖的package包/类
@Override
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod)
		throws IOException {
	return null;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:6,代码来源:TraceWebAsyncClientAutoConfigurationTests.java


示例15: doWithRequest

import org.springframework.http.client.AsyncClientHttpRequest; //导入依赖的package包/类
/**
 * Gets called by {@link AsyncRestTemplate#execute} with an opened {@code ClientHttpRequest}.
 * Does not need to care about closing the request or about handling errors:
 * this will all be handled by the {@code RestTemplate}.
 * @param request the active HTTP request
 * @throws java.io.IOException in case of I/O errors
 */
void doWithRequest(AsyncClientHttpRequest request) throws IOException;
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:AsyncRequestCallback.java


示例16: write

import org.springframework.http.client.AsyncClientHttpRequest; //导入依赖的package包/类
<T> void write(final AsyncClientHttpRequest request, final HttpEntity<T> entity) throws IOException; 
开发者ID:zalando,项目名称:riptide,代码行数:2,代码来源:MessageWriter.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RRule类代码示例发布时间:2022-05-23
下一篇:
Java DirectorySignature类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap