类org.springframework.http.client.AsyncClientHttpRequest源码实例Demo

下面列出了怎么用org.springframework.http.client.AsyncClientHttpRequest的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: lams   文件: AsyncRestTemplate.java
/**
 * 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);
	}
}
 
源代码2 项目: spring4-understanding   文件: AsyncRestTemplate.java
/**
 * 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);
	}
}
 
源代码3 项目: wingtips   文件: SpringHttpClientTagAdapterTest.java
@DataProvider(value = {
    "true   |   spring.asyncresttemplate",
    "false  |   spring.resttemplate"
}, splitBy = "\\|")
@Test
public void getSpanHandlerTagValue_works_as_expected_when_request_is_not_an_HttpRequestWrapper(
    boolean requestIsAsyncClientHttpRequest, String expectedResult
) {
    // given
    HttpRequest request = (requestIsAsyncClientHttpRequest)
                          ? mock(AsyncClientHttpRequest.class)
                          : mock(HttpRequest.class);

    // when
    String result = implSpy.getSpanHandlerTagValue(request, responseMock);

    // then
    assertThat(result).isEqualTo(expectedResult);
}
 
源代码4 项目: wingtips   文件: SpringHttpClientTagAdapterTest.java
@DataProvider(value = {
    "true   |   spring.asyncresttemplate",
    "false  |   spring.resttemplate"
}, splitBy = "\\|")
@Test
public void getSpanHandlerTagValue_works_as_expected_when_request_is_an_HttpRequestWrapper(
    boolean wrappedRequestIsAsyncClientHttpRequest, String expectedResult
) {
    // given
    HttpRequestWrapper request = mock(HttpRequestWrapper.class);
    HttpRequest wrappedRequest = (wrappedRequestIsAsyncClientHttpRequest)
                                 ? mock(AsyncClientHttpRequest.class)
                                 : mock(HttpRequest.class);

    doReturn(wrappedRequest).when(request).getRequest();

    // when
    String result = implSpy.getSpanHandlerTagValue(request, responseMock);

    // then
    assertThat(result).isEqualTo(expectedResult);
}
 
源代码5 项目: lams   文件: AsyncRestTemplate.java
@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();
			}
		});
	}
}
 
源代码6 项目: spring4-understanding   文件: AsyncRestTemplate.java
@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();
			}
		});
	}
}
 
源代码7 项目: spring4-understanding   文件: AsyncHttpAccessor.java
/**
 * 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;
}
 
源代码8 项目: wingtips   文件: SpringHttpClientTagAdapter.java
@Override
public @Nullable String getSpanHandlerTagValue(@Nullable HttpRequest request, @Nullable ClientHttpResponse response) {
    if (request instanceof HttpRequestWrapper) {
        request = ((HttpRequestWrapper) request).getRequest();
    }

    if (request instanceof AsyncClientHttpRequest) {
        return "spring.asyncresttemplate";
    }

    return "spring.resttemplate";
}
 
源代码9 项目: riptide   文件: NonBlockingIO.java
@Override
public CompletableFuture<ClientHttpResponse> execute(final RequestArguments arguments) throws IOException {
    final URI uri = arguments.getRequestUri();
    final HttpMethod method = arguments.getMethod();

    final AsyncClientHttpRequest request = requestFactory.createAsyncRequest(uri, method);

    copyTo(arguments.getHeaders(), request.getHeaders());
    arguments.getEntity().writeTo(request);

    return toCompletable(request.executeAsync());
}
 
源代码10 项目: skywalking   文件: RestRequestInterceptor.java
@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;
}
 
源代码11 项目: oneplatform   文件: EurekaRestTemplateBuilder.java
@Override
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException {
	uri = convertToRealUri(uri);
	return super.createAsyncRequest(uri, httpMethod);
}
 
@Override
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException {
	return createRequestInternal(uri, httpMethod);
}
 
@Override
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException {
	return super.createAsyncRequest(expand(uri), httpMethod);
}
 
@Override
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod)
		throws IOException {
	return this.factory.createAsyncRequest(uri, httpMethod);
}
 
源代码15 项目: lams   文件: AsyncHttpAccessor.java
/**
 * 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;
}
 
源代码16 项目: lams   文件: AsyncRequestCallback.java
/**
 * 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;
 
/**
 * 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;
 
 类所在包
 类方法
 同包方法