From 81430caa43849a6f1c319a4b0a379cfc8e6b69c8 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Fri, 17 Mar 2017 11:25:30 +0100 Subject: [PATCH] Deprecated AsyncRestTemplate and related types This commit deprecates `AsyncRestTemplate` and related types (`AsyncClientHttpRequestFactory` etc.) in favor of the Spring 5.0 `WebClient`. Issue: SPR-15294 --- .../client/MockAsyncClientHttpRequest.java | 9 +- .../web/client/MockRestServiceServer.java | 24 ++-- .../AbstractAsyncClientHttpRequest.java | 4 +- ...stractBufferingAsyncClientHttpRequest.java | 4 +- .../http/client/AsyncClientHttpRequest.java | 4 +- .../AsyncClientHttpRequestExecution.java | 22 ++-- .../client/AsyncClientHttpRequestFactory.java | 4 +- .../AsyncClientHttpRequestInterceptor.java | 7 +- .../HttpComponentsAsyncClientHttpRequest.java | 4 +- ...mponentsAsyncClientHttpRequestFactory.java | 4 +- ...HttpComponentsAsyncClientHttpResponse.java | 4 +- .../InterceptingAsyncClientHttpRequest.java | 118 +++++++++--------- ...rceptingAsyncClientHttpRequestFactory.java | 4 +- .../http/client/Netty4ClientHttpRequest.java | 2 + .../Netty4ClientHttpRequestFactory.java | 4 +- .../http/client/Netty4ClientHttpResponse.java | 4 +- .../client/OkHttp3AsyncClientHttpRequest.java | 4 +- .../OkHttp3ClientHttpRequestFactory.java | 3 +- ...SimpleBufferingAsyncClientHttpRequest.java | 4 +- .../SimpleClientHttpRequestFactory.java | 1 + ...SimpleStreamingAsyncClientHttpRequest.java | 4 +- .../client/support/AsyncHttpAccessor.java | 22 ++-- .../InterceptingAsyncHttpAccessor.java | 55 ++++---- .../web/client/AsyncRequestCallback.java | 10 +- .../web/client/AsyncRestOperations.java | 4 +- .../web/client/AsyncRestTemplate.java | 25 ++-- 26 files changed, 194 insertions(+), 160 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/mock/http/client/MockAsyncClientHttpRequest.java b/spring-test/src/main/java/org/springframework/mock/http/client/MockAsyncClientHttpRequest.java index 975f5a228a..6207d868bd 100644 --- a/spring-test/src/main/java/org/springframework/mock/http/client/MockAsyncClientHttpRequest.java +++ b/spring-test/src/main/java/org/springframework/mock/http/client/MockAsyncClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,21 +20,22 @@ import java.io.IOException; import java.net.URI; import org.springframework.http.HttpMethod; -import org.springframework.http.client.AsyncClientHttpRequest; import org.springframework.http.client.ClientHttpResponse; import org.springframework.util.concurrent.ListenableFuture; import org.springframework.util.concurrent.SettableListenableFuture; /** * An extension of {@link MockClientHttpRequest} that also implements - * {@link AsyncClientHttpRequest} by wrapping the response in a + * {@link org.springframework.http.client.AsyncClientHttpRequest} by wrapping the response in a * {@link SettableListenableFuture}. * * @author Rossen Stoyanchev * @author Sam Brannen * @since 4.1 + * @deprecated as of Spring 5.0, with no direct replacement */ -public class MockAsyncClientHttpRequest extends MockClientHttpRequest implements AsyncClientHttpRequest { +@Deprecated +public class MockAsyncClientHttpRequest extends MockClientHttpRequest implements org.springframework.http.client.AsyncClientHttpRequest { public MockAsyncClientHttpRequest() { } diff --git a/spring-test/src/main/java/org/springframework/test/web/client/MockRestServiceServer.java b/spring-test/src/main/java/org/springframework/test/web/client/MockRestServiceServer.java index 09207f8cbe..4ef493cf8b 100644 --- a/spring-test/src/main/java/org/springframework/test/web/client/MockRestServiceServer.java +++ b/spring-test/src/main/java/org/springframework/test/web/client/MockRestServiceServer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,14 +20,10 @@ import java.io.IOException; import java.net.URI; import org.springframework.http.HttpMethod; -import org.springframework.http.client.AsyncClientHttpRequest; -import org.springframework.http.client.AsyncClientHttpRequestFactory; import org.springframework.http.client.ClientHttpRequest; import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.ClientHttpResponse; -import org.springframework.mock.http.client.MockAsyncClientHttpRequest; import org.springframework.util.Assert; -import org.springframework.web.client.AsyncRestTemplate; import org.springframework.web.client.RestTemplate; import org.springframework.web.client.support.RestGatewaySupport; @@ -65,6 +61,7 @@ import org.springframework.web.client.support.RestGatewaySupport; * @author Rossen Stoyanchev * @since 3.2 */ +@SuppressWarnings("deprecation") public class MockRestServiceServer { private final RequestExpectationManager expectationManager; @@ -139,7 +136,7 @@ public class MockRestServiceServer { * to reply to the given {@code AsyncRestTemplate}. * @since 4.3 */ - public static MockRestServiceServerBuilder bindTo(AsyncRestTemplate asyncRestTemplate) { + public static MockRestServiceServerBuilder bindTo(org.springframework.web.client.AsyncRestTemplate asyncRestTemplate) { return new DefaultBuilder(asyncRestTemplate); } @@ -168,7 +165,7 @@ public class MockRestServiceServer { * @param asyncRestTemplate the AsyncRestTemplate to set up for mock testing * @return the created mock server */ - public static MockRestServiceServer createServer(AsyncRestTemplate asyncRestTemplate) { + public static MockRestServiceServer createServer(org.springframework.web.client.AsyncRestTemplate asyncRestTemplate) { return bindTo(asyncRestTemplate).build(); } @@ -215,7 +212,7 @@ public class MockRestServiceServer { private final RestTemplate restTemplate; - private final AsyncRestTemplate asyncRestTemplate; + private final org.springframework.web.client.AsyncRestTemplate asyncRestTemplate; private boolean ignoreExpectOrder; @@ -225,7 +222,7 @@ public class MockRestServiceServer { this.asyncRestTemplate = null; } - public DefaultBuilder(AsyncRestTemplate asyncRestTemplate) { + public DefaultBuilder(org.springframework.web.client.AsyncRestTemplate asyncRestTemplate) { Assert.notNull(asyncRestTemplate, "AsyncRestTemplate must not be null"); this.restTemplate = null; this.asyncRestTemplate = asyncRestTemplate; @@ -266,7 +263,8 @@ public class MockRestServiceServer { * Mock ClientHttpRequestFactory that creates requests by iterating * over the list of expected {@link DefaultRequestExpectation}'s. */ - private class MockClientHttpRequestFactory implements ClientHttpRequestFactory, AsyncClientHttpRequestFactory { + @SuppressWarnings("deprecation") + private class MockClientHttpRequestFactory implements ClientHttpRequestFactory, org.springframework.http.client.AsyncClientHttpRequestFactory { @Override public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) { @@ -274,15 +272,15 @@ public class MockRestServiceServer { } @Override - public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) { + public org.springframework.http.client.AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) { return createRequestInternal(uri, httpMethod); } - private MockAsyncClientHttpRequest createRequestInternal(URI uri, HttpMethod method) { + private org.springframework.mock.http.client.MockAsyncClientHttpRequest createRequestInternal(URI uri, HttpMethod method) { Assert.notNull(uri, "'uri' must not be null"); Assert.notNull(method, "'httpMethod' must not be null"); - return new MockAsyncClientHttpRequest(method, uri) { + return new org.springframework.mock.http.client.MockAsyncClientHttpRequest(method, uri) { @Override protected ClientHttpResponse executeInternal() throws IOException { diff --git a/spring-web/src/main/java/org/springframework/http/client/AbstractAsyncClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/AbstractAsyncClientHttpRequest.java index e33a15381c..78b0eb291e 100644 --- a/spring-web/src/main/java/org/springframework/http/client/AbstractAsyncClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/AbstractAsyncClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,9 @@ import org.springframework.util.concurrent.ListenableFuture; * * @author Arjen Poutsma * @since 4.0 + * @deprecated as of Spring 5.0, in favor of {@link org.springframework.http.client.reactive.AbstractClientHttpRequest} */ +@Deprecated abstract class AbstractAsyncClientHttpRequest implements AsyncClientHttpRequest { private final HttpHeaders headers = new HttpHeaders(); diff --git a/spring-web/src/main/java/org/springframework/http/client/AbstractBufferingAsyncClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/AbstractBufferingAsyncClientHttpRequest.java index 2bcbcdb298..c5ec370435 100644 --- a/spring-web/src/main/java/org/springframework/http/client/AbstractBufferingAsyncClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/AbstractBufferingAsyncClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,9 @@ import org.springframework.util.concurrent.ListenableFuture; * * @author Arjen Poutsma * @since 4.0 + * @deprecated as of Spring 5.0, with no direct replacement */ +@Deprecated abstract class AbstractBufferingAsyncClientHttpRequest extends AbstractAsyncClientHttpRequest { private ByteArrayOutputStream bufferedOutput = new ByteArrayOutputStream(1024); diff --git a/spring-web/src/main/java/org/springframework/http/client/AsyncClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/AsyncClientHttpRequest.java index 9e2e32eea1..c418fc9dbe 100644 --- a/spring-web/src/main/java/org/springframework/http/client/AsyncClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/AsyncClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,9 @@ import org.springframework.util.concurrent.ListenableFuture; * @author Arjen Poutsma * @since 4.0 * @see AsyncClientHttpRequestFactory#createAsyncRequest + * @deprecated as of Spring 5.0, in favor of {@link org.springframework.web.reactive.function.client.ClientRequest} */ +@Deprecated public interface AsyncClientHttpRequest extends HttpRequest, HttpOutputMessage { /** diff --git a/spring-web/src/main/java/org/springframework/http/client/AsyncClientHttpRequestExecution.java b/spring-web/src/main/java/org/springframework/http/client/AsyncClientHttpRequestExecution.java index 2f09014a76..232df59ec8 100644 --- a/spring-web/src/main/java/org/springframework/http/client/AsyncClientHttpRequestExecution.java +++ b/spring-web/src/main/java/org/springframework/http/client/AsyncClientHttpRequestExecution.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,17 +31,19 @@ import org.springframework.util.concurrent.ListenableFuture; * @author Rossen Stoyanchev * @since 4.3 * @see AsyncClientHttpRequestInterceptor + * @deprecated as of Spring 5.0, in favor of {@link org.springframework.web.reactive.function.client.ExchangeFilterFunction} */ +@Deprecated public interface AsyncClientHttpRequestExecution { - /** - * Resume the request execution by invoking the next interceptor in the chain - * or executing the request to the remote service. - * @param request the HTTP request, containing the HTTP method and headers - * @param body the body of the request - * @return a corresponding future handle - * @throws IOException in case of I/O errors - */ - ListenableFuture executeAsync(HttpRequest request, byte[] body) throws IOException; + /** + * Resume the request execution by invoking the next interceptor in the chain + * or executing the request to the remote service. + * @param request the HTTP request, containing the HTTP method and headers + * @param body the body of the request + * @return a corresponding future handle + * @throws IOException in case of I/O errors + */ + ListenableFuture executeAsync(HttpRequest request, byte[] body) throws IOException; } diff --git a/spring-web/src/main/java/org/springframework/http/client/AsyncClientHttpRequestFactory.java b/spring-web/src/main/java/org/springframework/http/client/AsyncClientHttpRequestFactory.java index b482e3d6a3..7addd66ebb 100644 --- a/spring-web/src/main/java/org/springframework/http/client/AsyncClientHttpRequestFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/AsyncClientHttpRequestFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,9 @@ import org.springframework.http.HttpMethod; * * @author Arjen Poutsma * @since 4.0 + * @deprecated as of Spring 5.0, in favor of {@link org.springframework.http.client.reactive.ClientHttpConnector} */ +@Deprecated public interface AsyncClientHttpRequestFactory { /** diff --git a/spring-web/src/main/java/org/springframework/http/client/AsyncClientHttpRequestInterceptor.java b/spring-web/src/main/java/org/springframework/http/client/AsyncClientHttpRequestInterceptor.java index 3fabe12075..6b7a0cd892 100644 --- a/spring-web/src/main/java/org/springframework/http/client/AsyncClientHttpRequestInterceptor.java +++ b/spring-web/src/main/java/org/springframework/http/client/AsyncClientHttpRequestInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ package org.springframework.http.client; import java.io.IOException; import org.springframework.http.HttpRequest; -import org.springframework.http.client.support.InterceptingAsyncHttpAccessor; import org.springframework.util.concurrent.ListenableFuture; /** @@ -36,8 +35,10 @@ import org.springframework.util.concurrent.ListenableFuture; * @author Rossen Stoyanchev * @since 4.3 * @see org.springframework.web.client.AsyncRestTemplate - * @see InterceptingAsyncHttpAccessor + * @see org.springframework.http.client.support.InterceptingAsyncHttpAccessor + * @deprecated as of Spring 5.0, in favor of {@link org.springframework.web.reactive.function.client.ExchangeFilterFunction} */ +@Deprecated public interface AsyncClientHttpRequestInterceptor { /** diff --git a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpRequest.java index aaa8e578d9..1a41f63b15 100644 --- a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,7 +49,9 @@ import org.springframework.util.concurrent.SuccessCallback; * @author Arjen Poutsma * @since 4.0 * @see HttpComponentsClientHttpRequestFactory#createRequest + * @deprecated as of Spring 5.0, with no direct replacement */ +@Deprecated final class HttpComponentsAsyncClientHttpRequest extends AbstractBufferingAsyncClientHttpRequest { private final HttpAsyncClient httpClient; diff --git a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpRequestFactory.java b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpRequestFactory.java index fa57fbd3ca..c7d9564bb6 100644 --- a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpRequestFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpRequestFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,7 +43,9 @@ import org.springframework.util.Assert; * @author Stephane Nicoll * @since 4.0 * @see HttpAsyncClient + * @deprecated as of Spring 5.0, with no direct replacement */ +@Deprecated public class HttpComponentsAsyncClientHttpRequestFactory extends HttpComponentsClientHttpRequestFactory implements AsyncClientHttpRequestFactory, InitializingBean { diff --git a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpResponse.java index b8f5a6bbb7..78e4646a0c 100644 --- a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsAsyncClientHttpResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,9 @@ import org.springframework.util.StreamUtils; * @author Arjen Poutsma * @since 4.0 * @see HttpComponentsAsyncClientHttpRequest#executeAsync() + * @deprecated as of Spring 5.0, with no direct replacement */ +@Deprecated final class HttpComponentsAsyncClientHttpResponse extends AbstractClientHttpResponse { private final HttpResponse httpResponse; diff --git a/spring-web/src/main/java/org/springframework/http/client/InterceptingAsyncClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/InterceptingAsyncClientHttpRequest.java index 0b13181a29..e58b3ef06c 100644 --- a/spring-web/src/main/java/org/springframework/http/client/InterceptingAsyncClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/InterceptingAsyncClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,84 +34,86 @@ import org.springframework.util.concurrent.ListenableFuture; * @author Jakub Narloch * @author Rossen Stoyanchev * @see InterceptingAsyncClientHttpRequestFactory + * @deprecated as of Spring 5.0, with no direct replacement */ +@Deprecated class InterceptingAsyncClientHttpRequest extends AbstractBufferingAsyncClientHttpRequest { - private AsyncClientHttpRequestFactory requestFactory; + private AsyncClientHttpRequestFactory requestFactory; - private List interceptors; + private List interceptors; - private URI uri; + private URI uri; - private HttpMethod httpMethod; + private HttpMethod httpMethod; - /** - * Creates new instance of {@link InterceptingAsyncClientHttpRequest}. - * - * @param requestFactory the async request factory - * @param interceptors the list of interceptors - * @param uri the request URI - * @param httpMethod the HTTP method - */ - public InterceptingAsyncClientHttpRequest(AsyncClientHttpRequestFactory requestFactory, - List interceptors, URI uri, HttpMethod httpMethod) { + /** + * Creates new instance of {@link InterceptingAsyncClientHttpRequest}. + * + * @param requestFactory the async request factory + * @param interceptors the list of interceptors + * @param uri the request URI + * @param httpMethod the HTTP method + */ + public InterceptingAsyncClientHttpRequest(AsyncClientHttpRequestFactory requestFactory, + List interceptors, URI uri, HttpMethod httpMethod) { - this.requestFactory = requestFactory; - this.interceptors = interceptors; - this.uri = uri; - this.httpMethod = httpMethod; - } + this.requestFactory = requestFactory; + this.interceptors = interceptors; + this.uri = uri; + this.httpMethod = httpMethod; + } - @Override - protected ListenableFuture executeInternal(HttpHeaders headers, byte[] body) - throws IOException { + @Override + protected ListenableFuture executeInternal(HttpHeaders headers, byte[] body) + throws IOException { - return new AsyncRequestExecution().executeAsync(this, body); - } + return new AsyncRequestExecution().executeAsync(this, body); + } - @Override - public HttpMethod getMethod() { - return httpMethod; - } + @Override + public HttpMethod getMethod() { + return httpMethod; + } - @Override - public URI getURI() { - return uri; - } + @Override + public URI getURI() { + return uri; + } - private class AsyncRequestExecution implements AsyncClientHttpRequestExecution { + private class AsyncRequestExecution implements AsyncClientHttpRequestExecution { - private Iterator iterator; + private Iterator iterator; - public AsyncRequestExecution() { - this.iterator = interceptors.iterator(); - } + public AsyncRequestExecution() { + this.iterator = interceptors.iterator(); + } - @Override - public ListenableFuture executeAsync(HttpRequest request, byte[] body) - throws IOException { + @Override + public ListenableFuture executeAsync(HttpRequest request, byte[] body) + throws IOException { - if (this.iterator.hasNext()) { - AsyncClientHttpRequestInterceptor interceptor = this.iterator.next(); - return interceptor.intercept(request, body, this); - } - else { - URI theUri = request.getURI(); - HttpMethod theMethod = request.getMethod(); - HttpHeaders theHeaders = request.getHeaders(); + if (this.iterator.hasNext()) { + AsyncClientHttpRequestInterceptor interceptor = this.iterator.next(); + return interceptor.intercept(request, body, this); + } + else { + URI theUri = request.getURI(); + HttpMethod theMethod = request.getMethod(); + HttpHeaders theHeaders = request.getHeaders(); - AsyncClientHttpRequest delegate = requestFactory.createAsyncRequest(theUri, theMethod); - delegate.getHeaders().putAll(theHeaders); - if (body.length > 0) { - StreamUtils.copy(body, delegate.getBody()); - } + AsyncClientHttpRequest delegate = requestFactory.createAsyncRequest(theUri, theMethod); + delegate.getHeaders().putAll(theHeaders); + if (body.length > 0) { + StreamUtils.copy(body, delegate.getBody()); + } - return delegate.executeAsync(); - } - } - } + return delegate.executeAsync(); + } + } + } } diff --git a/spring-web/src/main/java/org/springframework/http/client/InterceptingAsyncClientHttpRequestFactory.java b/spring-web/src/main/java/org/springframework/http/client/InterceptingAsyncClientHttpRequestFactory.java index b12e706207..4347767a45 100644 --- a/spring-web/src/main/java/org/springframework/http/client/InterceptingAsyncClientHttpRequestFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/InterceptingAsyncClientHttpRequestFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,9 @@ import org.springframework.http.HttpMethod; * @author Jakub Narloch * @since 4.3 * @see InterceptingAsyncClientHttpRequest + * @deprecated as of Spring 5.0, with no direct replacement */ +@Deprecated public class InterceptingAsyncClientHttpRequestFactory implements AsyncClientHttpRequestFactory { private AsyncClientHttpRequestFactory delegate; diff --git a/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequest.java index b85e3acecd..d48f5ddd47 100644 --- a/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequest.java @@ -50,7 +50,9 @@ import org.springframework.util.concurrent.SettableListenableFuture; * @author Rossen Stoyanchev * @author Brian Clozel * @since 4.1.2 + * @deprecated as of Spring 5.0, in favor of {@link org.springframework.http.client.reactive.ReactorClientHttpConnector} */ +@Deprecated class Netty4ClientHttpRequest extends AbstractAsyncClientHttpRequest implements ClientHttpRequest { private final Bootstrap bootstrap; diff --git a/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequestFactory.java b/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequestFactory.java index f5a059c245..1850912547 100644 --- a/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequestFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequestFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,7 +56,9 @@ import org.springframework.util.Assert; * @author Brian Clozel * @author Mark Paluch * @since 4.1.2 + * @deprecated as of Spring 5.0, in favor of {@link org.springframework.http.client.reactive.ReactorClientHttpConnector} */ +@Deprecated public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory, AsyncClientHttpRequestFactory, InitializingBean, DisposableBean { diff --git a/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpResponse.java index e42259edd8..8a795ccb7b 100644 --- a/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,9 @@ import org.springframework.util.Assert; * * @author Arjen Poutsma * @since 4.1.2 + * @deprecated as of Spring 5.0, in favor of {@link org.springframework.http.client.reactive.ReactorClientHttpConnector} */ +@Deprecated class Netty4ClientHttpResponse extends AbstractClientHttpResponse { private final ChannelHandlerContext context; diff --git a/spring-web/src/main/java/org/springframework/http/client/OkHttp3AsyncClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/OkHttp3AsyncClientHttpRequest.java index 06e1d064ff..7333d8bc36 100644 --- a/spring-web/src/main/java/org/springframework/http/client/OkHttp3AsyncClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/OkHttp3AsyncClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,9 @@ import org.springframework.util.concurrent.SettableListenableFuture; * @author Arjen Poutsma * @author Roy Clarkson * @since 4.3 + * @deprecated as of Spring 5.0, with no direct replacement */ +@Deprecated class OkHttp3AsyncClientHttpRequest extends AbstractBufferingAsyncClientHttpRequest { private final OkHttpClient client; diff --git a/spring-web/src/main/java/org/springframework/http/client/OkHttp3ClientHttpRequestFactory.java b/spring-web/src/main/java/org/springframework/http/client/OkHttp3ClientHttpRequestFactory.java index b45d36e329..389b98eb25 100644 --- a/spring-web/src/main/java/org/springframework/http/client/OkHttp3ClientHttpRequestFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/OkHttp3ClientHttpRequestFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,6 +42,7 @@ import org.springframework.util.StringUtils; * @author Roy Clarkson * @since 4.3 */ +@SuppressWarnings("deprecation") public class OkHttp3ClientHttpRequestFactory implements ClientHttpRequestFactory, AsyncClientHttpRequestFactory, DisposableBean { diff --git a/spring-web/src/main/java/org/springframework/http/client/SimpleBufferingAsyncClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/SimpleBufferingAsyncClientHttpRequest.java index bd43996365..e98a7a2d75 100644 --- a/spring-web/src/main/java/org/springframework/http/client/SimpleBufferingAsyncClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/SimpleBufferingAsyncClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,9 @@ import org.springframework.util.concurrent.ListenableFuture; * @author Arjen Poutsma * @since 3.0 * @see org.springframework.http.client.SimpleClientHttpRequestFactory#createRequest + * @deprecated as of Spring 5.0, with no direct replacement */ +@Deprecated final class SimpleBufferingAsyncClientHttpRequest extends AbstractBufferingAsyncClientHttpRequest { private final HttpURLConnection connection; diff --git a/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequestFactory.java b/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequestFactory.java index aa369188fb..17bcd6c1d4 100644 --- a/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequestFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequestFactory.java @@ -36,6 +36,7 @@ import org.springframework.util.Assert; * @see java.net.HttpURLConnection * @see HttpComponentsClientHttpRequestFactory */ +@SuppressWarnings("deprecation") public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory, AsyncClientHttpRequestFactory { private static final int DEFAULT_CHUNK_SIZE = 4096; diff --git a/spring-web/src/main/java/org/springframework/http/client/SimpleStreamingAsyncClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/SimpleStreamingAsyncClientHttpRequest.java index e3327d238b..f79f2cbbd5 100644 --- a/spring-web/src/main/java/org/springframework/http/client/SimpleStreamingAsyncClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/SimpleStreamingAsyncClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,7 +37,9 @@ import org.springframework.util.concurrent.ListenableFuture; * @author Arjen Poutsma * @since 3.0 * @see org.springframework.http.client.SimpleClientHttpRequestFactory#createRequest + * @deprecated as of Spring 5.0, with no direct replacement */ +@Deprecated final class SimpleStreamingAsyncClientHttpRequest extends AbstractAsyncClientHttpRequest { private final HttpURLConnection connection; diff --git a/spring-web/src/main/java/org/springframework/http/client/support/AsyncHttpAccessor.java b/spring-web/src/main/java/org/springframework/http/client/support/AsyncHttpAccessor.java index 00762139ea..99a0b0ed69 100644 --- a/spring-web/src/main/java/org/springframework/http/client/support/AsyncHttpAccessor.java +++ b/spring-web/src/main/java/org/springframework/http/client/support/AsyncHttpAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,14 +23,12 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.http.HttpMethod; -import org.springframework.http.client.AsyncClientHttpRequest; -import org.springframework.http.client.AsyncClientHttpRequestFactory; import org.springframework.util.Assert; /** * Base class for {@link org.springframework.web.client.AsyncRestTemplate} * and other HTTP accessing gateway helpers, defining common properties - * such as the {@link AsyncClientHttpRequestFactory} to operate on. + * such as the {@link org.springframework.http.client.AsyncClientHttpRequestFactory} to operate on. * *

Not intended to be used directly. See * {@link org.springframework.web.client.AsyncRestTemplate}. @@ -38,19 +36,21 @@ import org.springframework.util.Assert; * @author Arjen Poutsma * @since 4.0 * @see org.springframework.web.client.AsyncRestTemplate + * @deprecated as of Spring 5.0, with no direct replacement */ +@Deprecated public class AsyncHttpAccessor { /** Logger available to subclasses. */ protected final Log logger = LogFactory.getLog(getClass()); - private AsyncClientHttpRequestFactory asyncRequestFactory; + private org.springframework.http.client.AsyncClientHttpRequestFactory asyncRequestFactory; /** * Set the request factory that this accessor uses for obtaining {@link * org.springframework.http.client.ClientHttpRequest HttpRequests}. */ - public void setAsyncRequestFactory(AsyncClientHttpRequestFactory asyncRequestFactory) { + public void setAsyncRequestFactory(org.springframework.http.client.AsyncClientHttpRequestFactory asyncRequestFactory) { Assert.notNull(asyncRequestFactory, "'asyncRequestFactory' must not be null"); this.asyncRequestFactory = asyncRequestFactory; } @@ -59,21 +59,21 @@ public class AsyncHttpAccessor { * Return the request factory that this accessor uses for obtaining {@link * org.springframework.http.client.ClientHttpRequest HttpRequests}. */ - public AsyncClientHttpRequestFactory getAsyncRequestFactory() { + public org.springframework.http.client.AsyncClientHttpRequestFactory getAsyncRequestFactory() { return this.asyncRequestFactory; } /** - * Create a new {@link AsyncClientHttpRequest} via this template's {@link - * AsyncClientHttpRequestFactory}. + * Create a new {@link org.springframework.http.client.AsyncClientHttpRequest} via this template's + * {@link org.springframework.http.client.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) + protected org.springframework.http.client.AsyncClientHttpRequest createAsyncRequest(URI url, HttpMethod method) throws IOException { - AsyncClientHttpRequest request = getAsyncRequestFactory().createAsyncRequest(url, method); + org.springframework.http.client.AsyncClientHttpRequest request = getAsyncRequestFactory().createAsyncRequest(url, method); if (logger.isDebugEnabled()) { logger.debug("Created asynchronous " + method.name() + " request for \"" + url + "\""); } diff --git a/spring-web/src/main/java/org/springframework/http/client/support/InterceptingAsyncHttpAccessor.java b/spring-web/src/main/java/org/springframework/http/client/support/InterceptingAsyncHttpAccessor.java index c3c2236bcf..6c570ef98c 100644 --- a/spring-web/src/main/java/org/springframework/http/client/support/InterceptingAsyncHttpAccessor.java +++ b/spring-web/src/main/java/org/springframework/http/client/support/InterceptingAsyncHttpAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,6 @@ package org.springframework.http.client.support; import java.util.ArrayList; import java.util.List; -import org.springframework.http.client.AsyncClientHttpRequestFactory; -import org.springframework.http.client.AsyncClientHttpRequestInterceptor; -import org.springframework.http.client.InterceptingAsyncClientHttpRequestFactory; import org.springframework.util.CollectionUtils; /** @@ -31,38 +28,40 @@ import org.springframework.util.CollectionUtils; * @author Jakub Narloch * @author Rossen Stoyanchev * @since 4.3 + * @deprecated as of Spring 5.0, with no direct replacement */ +@Deprecated public abstract class InterceptingAsyncHttpAccessor extends AsyncHttpAccessor { - private List interceptors = + private List interceptors = new ArrayList<>(); - /** - * Set the request interceptors that this accessor should use. - * @param interceptors the list of interceptors - */ - public void setInterceptors(List interceptors) { - this.interceptors = interceptors; - } + /** + * Set the request interceptors that this accessor should use. + * @param interceptors the list of interceptors + */ + public void setInterceptors(List interceptors) { + this.interceptors = interceptors; + } - /** - * Return the request interceptor that this accessor uses. - */ - public List getInterceptors() { - return this.interceptors; - } + /** + * Return the request interceptor that this accessor uses. + */ + public List getInterceptors() { + return this.interceptors; + } - @Override - public AsyncClientHttpRequestFactory getAsyncRequestFactory() { - AsyncClientHttpRequestFactory delegate = super.getAsyncRequestFactory(); - if (!CollectionUtils.isEmpty(getInterceptors())) { - return new InterceptingAsyncClientHttpRequestFactory(delegate, getInterceptors()); - } - else { - return delegate; - } - } + @Override + public org.springframework.http.client.AsyncClientHttpRequestFactory getAsyncRequestFactory() { + org.springframework.http.client.AsyncClientHttpRequestFactory delegate = super.getAsyncRequestFactory(); + if (!CollectionUtils.isEmpty(getInterceptors())) { + return new org.springframework.http.client.InterceptingAsyncClientHttpRequestFactory(delegate, getInterceptors()); + } + else { + return delegate; + } + } } diff --git a/spring-web/src/main/java/org/springframework/web/client/AsyncRequestCallback.java b/spring-web/src/main/java/org/springframework/web/client/AsyncRequestCallback.java index 5dae560cbe..dd878b4a44 100644 --- a/spring-web/src/main/java/org/springframework/web/client/AsyncRequestCallback.java +++ b/spring-web/src/main/java/org/springframework/web/client/AsyncRequestCallback.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,10 +18,8 @@ package org.springframework.web.client; import java.io.IOException; -import org.springframework.http.client.AsyncClientHttpRequest; - /** - * Callback interface for code that operates on an {@link AsyncClientHttpRequest}. Allows + * Callback interface for code that operates on an {@link org.springframework.http.client.AsyncClientHttpRequest}. Allows * to manipulate the request headers, and write to the request body. * *

Used internally by the {@link AsyncRestTemplate}, but also useful for application code. @@ -29,8 +27,10 @@ import org.springframework.http.client.AsyncClientHttpRequest; * @author Arjen Poutsma * @see org.springframework.web.client.AsyncRestTemplate#execute * @since 4.0 + * @deprecated as of Spring 5.0, in favor of {@link org.springframework.web.reactive.function.client.ExchangeFilterFunction} */ @FunctionalInterface +@Deprecated public interface AsyncRequestCallback { /** @@ -40,6 +40,6 @@ public interface AsyncRequestCallback { * @param request the active HTTP request * @throws java.io.IOException in case of I/O errors */ - void doWithRequest(AsyncClientHttpRequest request) throws IOException; + void doWithRequest(org.springframework.http.client.AsyncClientHttpRequest request) throws IOException; } diff --git a/spring-web/src/main/java/org/springframework/web/client/AsyncRestOperations.java b/spring-web/src/main/java/org/springframework/web/client/AsyncRestOperations.java index 19658f6bb6..a4f77d671f 100644 --- a/spring-web/src/main/java/org/springframework/web/client/AsyncRestOperations.java +++ b/spring-web/src/main/java/org/springframework/web/client/AsyncRestOperations.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,7 +37,9 @@ import org.springframework.util.concurrent.ListenableFuture; * @since 4.0 * @see AsyncRestTemplate * @see RestOperations + * @deprecated as of Spring 5.0, in favor of {@link org.springframework.web.reactive.function.client.WebClient} */ +@Deprecated public interface AsyncRestOperations { /** diff --git a/spring-web/src/main/java/org/springframework/web/client/AsyncRestTemplate.java b/spring-web/src/main/java/org/springframework/web/client/AsyncRestTemplate.java index a0ad553bf2..212e023981 100644 --- a/spring-web/src/main/java/org/springframework/web/client/AsyncRestTemplate.java +++ b/spring-web/src/main/java/org/springframework/web/client/AsyncRestTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,13 +33,10 @@ import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; -import org.springframework.http.client.AsyncClientHttpRequest; -import org.springframework.http.client.AsyncClientHttpRequestFactory; import org.springframework.http.client.ClientHttpRequest; import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.SimpleClientHttpRequestFactory; -import org.springframework.http.client.support.InterceptingAsyncHttpAccessor; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.util.Assert; import org.springframework.util.concurrent.ListenableFuture; @@ -59,15 +56,17 @@ import org.springframework.web.util.UriTemplateHandler; *

Note: by default {@code AsyncRestTemplate} relies on * standard JDK facilities to establish HTTP connections. You can switch to use * a different HTTP library such as Apache HttpComponents, Netty, and OkHttp by - * using a constructor accepting an {@link AsyncClientHttpRequestFactory}. + * using a constructor accepting an {@link org.springframework.http.client.AsyncClientHttpRequestFactory}. * *

For more information, please refer to the {@link RestTemplate} API documentation. * * @author Arjen Poutsma * @since 4.0 * @see RestTemplate + * @deprecated as of Spring 5.0, in favor of {@link org.springframework.web.reactive.function.client.WebClient} */ -public class AsyncRestTemplate extends InterceptingAsyncHttpAccessor implements AsyncRestOperations { +@Deprecated +public class AsyncRestTemplate extends org.springframework.http.client.support.InterceptingAsyncHttpAccessor implements AsyncRestOperations { private final RestTemplate syncTemplate; @@ -97,14 +96,14 @@ public class AsyncRestTemplate extends InterceptingAsyncHttpAccessor implements /** * Create a new instance of the {@code AsyncRestTemplate} using the given - * {@link AsyncClientHttpRequestFactory}. + * {@link org.springframework.http.client.AsyncClientHttpRequestFactory}. *

This constructor will cast the given asynchronous * {@code AsyncClientHttpRequestFactory} to a {@link ClientHttpRequestFactory}. Since * all implementations of {@code ClientHttpRequestFactory} provided in Spring also * implement {@code AsyncClientHttpRequestFactory}, this should not result in a * {@code ClassCastException}. */ - public AsyncRestTemplate(AsyncClientHttpRequestFactory asyncRequestFactory) { + public AsyncRestTemplate(org.springframework.http.client.AsyncClientHttpRequestFactory asyncRequestFactory) { this(asyncRequestFactory, (ClientHttpRequestFactory) asyncRequestFactory); } @@ -115,18 +114,18 @@ public class AsyncRestTemplate extends InterceptingAsyncHttpAccessor implements * @param syncRequestFactory the synchronous request factory */ public AsyncRestTemplate( - AsyncClientHttpRequestFactory asyncRequestFactory, ClientHttpRequestFactory syncRequestFactory) { + org.springframework.http.client.AsyncClientHttpRequestFactory asyncRequestFactory, ClientHttpRequestFactory syncRequestFactory) { this(asyncRequestFactory, new RestTemplate(syncRequestFactory)); } /** * Create a new instance of the {@code AsyncRestTemplate} using the given - * {@link AsyncClientHttpRequestFactory} and synchronous {@link RestTemplate}. + * {@link org.springframework.http.client.AsyncClientHttpRequestFactory} and synchronous {@link RestTemplate}. * @param requestFactory the asynchronous request factory to use * @param restTemplate the synchronous template to use */ - public AsyncRestTemplate(AsyncClientHttpRequestFactory requestFactory, RestTemplate restTemplate) { + public AsyncRestTemplate(org.springframework.http.client.AsyncClientHttpRequestFactory requestFactory, RestTemplate restTemplate) { Assert.notNull(restTemplate, "RestTemplate must not be null"); this.syncTemplate = restTemplate; setAsyncRequestFactory(requestFactory); @@ -505,7 +504,7 @@ public class AsyncRestTemplate extends InterceptingAsyncHttpAccessor implements Assert.notNull(url, "'url' must not be null"); Assert.notNull(method, "'method' must not be null"); try { - AsyncClientHttpRequest request = createAsyncRequest(url, method); + org.springframework.http.client.AsyncClientHttpRequest request = createAsyncRequest(url, method); if (requestCallback != null) { requestCallback.doWithRequest(request); } @@ -647,7 +646,7 @@ public class AsyncRestTemplate extends InterceptingAsyncHttpAccessor implements } @Override - public void doWithRequest(final AsyncClientHttpRequest request) throws IOException { + public void doWithRequest(final org.springframework.http.client.AsyncClientHttpRequest request) throws IOException { if (this.adaptee != null) { this.adaptee.doWithRequest(new ClientHttpRequest() { @Override