Skip to content

Commit ef80593

Browse files
committed
GH-11268: Suppress RestTemplate removal warnings
Fixes: #11268 Add @SuppressWarnings("removal") on remaining RestTemplate-based HTTP outbound APIs and tests until that client is removed. Migrate the uri-expression unit test onto RestClient + requestFactory. Signed-off-by: Burak KALAYCI <kalayciburak1996@gmail.com>
1 parent fe5e7d8 commit ef80593

7 files changed

Lines changed: 39 additions & 5 deletions

File tree

spring-integration-http/src/main/java/org/springframework/integration/http/dsl/Http.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
* @author Artem Bilan
3838
* @author Shiliang Li
3939
* @author Arun Sethumadhavan
40+
* @author Burak Kalayci
4041
*
4142
* @since 5.0
4243
*/
@@ -90,6 +91,7 @@ public static HttpMessageHandlerSpec outboundChannelAdapter(Expression uriExpres
9091
* @deprecated Since 7.1 in favor of {@link RestClient}-based configuration.
9192
*/
9293
@Deprecated(since = "7.1", forRemoval = true)
94+
@SuppressWarnings("removal")
9395
public static HttpMessageHandlerSpec outboundChannelAdapter(URI uri, @Nullable RestTemplate restTemplate) {
9496
return outboundChannelAdapter(uri, toRestClient(restTemplate));
9597
}
@@ -115,6 +117,7 @@ public static HttpMessageHandlerSpec outboundChannelAdapter(URI uri, @Nullable R
115117
* @deprecated Since 7.1 in favor of {@link RestClient}-based configuration.
116118
*/
117119
@Deprecated(since = "7.1", forRemoval = true)
120+
@SuppressWarnings("removal")
118121
public static HttpMessageHandlerSpec outboundChannelAdapter(String uri, @Nullable RestTemplate restTemplate) {
119122
return outboundChannelAdapter(uri, toRestClient(restTemplate));
120123
}
@@ -142,6 +145,7 @@ public static HttpMessageHandlerSpec outboundChannelAdapter(String uri, @Nullabl
142145
* @deprecated Since 7.1 in favor of {@link RestClient}-based configuration.
143146
*/
144147
@Deprecated(since = "7.1", forRemoval = true)
148+
@SuppressWarnings("removal")
145149
public static <P> HttpMessageHandlerSpec outboundChannelAdapter(Function<Message<P>, ?> uriFunction,
146150
RestTemplate restTemplate) {
147151

@@ -174,6 +178,7 @@ public static <P> HttpMessageHandlerSpec outboundChannelAdapter(Function<Message
174178
* @deprecated Since 7.1 in favor of {@link RestClient}-based configuration.
175179
*/
176180
@Deprecated(since = "7.1", forRemoval = true)
181+
@SuppressWarnings("removal")
177182
public static HttpMessageHandlerSpec outboundChannelAdapter(Expression uriExpression,
178183
@Nullable RestTemplate restTemplate) {
179184

@@ -243,6 +248,7 @@ public static HttpMessageHandlerSpec outboundGateway(Expression uriExpression) {
243248
* @deprecated Since 7.1 in favor of {@link RestClient}-based configuration.
244249
*/
245250
@Deprecated(since = "7.1", forRemoval = true)
251+
@SuppressWarnings("removal")
246252
public static HttpMessageHandlerSpec outboundGateway(URI uri, @Nullable RestTemplate restTemplate) {
247253
return outboundGateway(uri, toRestClient(restTemplate));
248254
}
@@ -268,6 +274,7 @@ public static HttpMessageHandlerSpec outboundGateway(URI uri, @Nullable RestClie
268274
* @deprecated Since 7.1 in favor of {@link RestClient}-based configuration.
269275
*/
270276
@Deprecated(since = "7.1", forRemoval = true)
277+
@SuppressWarnings("removal")
271278
public static HttpMessageHandlerSpec outboundGateway(String uri, @Nullable RestTemplate restTemplate) {
272279
return outboundGateway(uri, toRestClient(restTemplate));
273280
}
@@ -295,6 +302,7 @@ public static HttpMessageHandlerSpec outboundGateway(String uri, @Nullable RestC
295302
* @deprecated Since 7.1 in favor of {@link RestClient}-based configuration.
296303
*/
297304
@Deprecated(since = "7.1", forRemoval = true)
305+
@SuppressWarnings("removal")
298306
public static <P> HttpMessageHandlerSpec outboundGateway(Function<Message<P>, ?> uriFunction,
299307
RestTemplate restTemplate) {
300308

@@ -327,6 +335,7 @@ public static <P> HttpMessageHandlerSpec outboundGateway(Function<Message<P>, ?>
327335
* @deprecated Since 7.1 in favor of {@link RestClient}-based configuration.
328336
*/
329337
@Deprecated(since = "7.1", forRemoval = true)
338+
@SuppressWarnings("removal")
330339
public static HttpMessageHandlerSpec outboundGateway(Expression uriExpression,
331340
@Nullable RestTemplate restTemplate) {
332341

@@ -360,6 +369,7 @@ private static HttpMessageHandlerSpec outboundGatewaySpec(Expression uriExpressi
360369
return new HttpMessageHandlerSpec(uriExpression, restClient);
361370
}
362371

372+
@SuppressWarnings("removal")
363373
private static @Nullable RestClient toRestClient(@Nullable RestTemplate restTemplate) {
364374
return restTemplate != null ? RestClient.create(restTemplate) : null;
365375
}

spring-integration-http/src/main/java/org/springframework/integration/http/dsl/HttpMessageHandlerSpec.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
* @author Oleksii Komlyk
4343
* @author Arun Sethumadhavan
4444
* @author Glenn Renfro
45+
* @author Burak Kalayci
4546
*
4647
* @since 5.0
4748
*
@@ -56,6 +57,7 @@ public class HttpMessageHandlerSpec
5657
* @deprecated Since 7.1 in favor of {@link RestClient}-based configuration.
5758
*/
5859
@Deprecated(since = "7.1", forRemoval = true)
60+
@SuppressWarnings("removal")
5961
protected HttpMessageHandlerSpec(URI uri, @Nullable RestTemplate restTemplate) {
6062
this(new ValueExpression<>(uri), restTemplate != null ? RestClient.create(restTemplate) : null);
6163
}
@@ -64,6 +66,7 @@ protected HttpMessageHandlerSpec(URI uri, @Nullable RestTemplate restTemplate) {
6466
* @deprecated Since 7.1 in favor of {@link RestClient}-based configuration.
6567
*/
6668
@Deprecated(since = "7.1", forRemoval = true)
69+
@SuppressWarnings("removal")
6770
protected HttpMessageHandlerSpec(String uri, @Nullable RestTemplate restTemplate) {
6871
this(new LiteralExpression(uri), restTemplate != null ? RestClient.create(restTemplate) : null);
6972
}
@@ -72,6 +75,7 @@ protected HttpMessageHandlerSpec(String uri, @Nullable RestTemplate restTemplate
7275
* @deprecated Since 7.1 in favor of {@link RestClient}-based configuration.
7376
*/
7477
@Deprecated(since = "7.1", forRemoval = true)
78+
@SuppressWarnings("removal")
7579
protected HttpMessageHandlerSpec(Expression uriExpression, @Nullable RestTemplate restTemplate) {
7680
this(uriExpression, restTemplate != null ? RestClient.create(restTemplate) : null);
7781
}
@@ -109,6 +113,7 @@ public HttpMessageHandlerSpec requestFactory(ClientHttpRequestFactory requestFac
109113
* @deprecated Since 7.2 in favor of {@link RestClient.ResponseSpec.ErrorHandler}.
110114
*/
111115
@Deprecated(since = "7.2", forRemoval = true)
116+
@SuppressWarnings("removal")
112117
public HttpMessageHandlerSpec errorHandler(ResponseErrorHandler errorHandler) {
113118
Assert.isTrue(!isClientSet(), "the 'errorHandler' must be specified on the provided client");
114119
this.target.setErrorHandler(errorHandler);

spring-integration-http/src/main/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandler.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,13 @@
6767
* @author Shiliang Li
6868
* @author Arun Sethumadhavan
6969
* @author Glenn Renfro
70+
* @author Burak Kalayci
7071
*
7172
* @since 2.0
7273
*/
7374
public class HttpRequestExecutingMessageHandler extends AbstractHttpRequestExecutingMessageHandler {
7475

76+
@SuppressWarnings("removal")
7577
private final @Nullable RestTemplate restTemplate;
7678

7779
private volatile @Nullable RestClient restClient;
@@ -113,6 +115,7 @@ public HttpRequestExecutingMessageHandler(Expression uriExpression) {
113115
* @deprecated Since 7.1 in favor of {@link RestClient}-based configuration.
114116
*/
115117
@Deprecated(since = "7.1", forRemoval = true)
118+
@SuppressWarnings("removal")
116119
public HttpRequestExecutingMessageHandler(String uri, @Nullable RestTemplate restTemplate) {
117120
this(new LiteralExpression(uri), restTemplate);
118121
/*
@@ -131,6 +134,7 @@ public HttpRequestExecutingMessageHandler(String uri, @Nullable RestTemplate res
131134
* @deprecated Since 7.1 in favor of {@link RestClient}-based configuration.
132135
*/
133136
@Deprecated(since = "7.1", forRemoval = true)
137+
@SuppressWarnings("removal")
134138
public HttpRequestExecutingMessageHandler(Expression uriExpression, @Nullable RestTemplate restTemplate) {
135139
this(uriExpression, restTemplate, null);
136140
}
@@ -162,6 +166,7 @@ public HttpRequestExecutingMessageHandler(Expression uriExpression, @Nullable Re
162166
this(uriExpression, null, restClient);
163167
}
164168

169+
@SuppressWarnings("removal")
165170
private HttpRequestExecutingMessageHandler(Expression uriExpression,
166171
@Nullable RestTemplate restTemplate, @Nullable RestClient restClient) {
167172

@@ -226,6 +231,7 @@ protected void doInit() {
226231
* @see RestTemplate#setErrorHandler(ResponseErrorHandler)
227232
*/
228233
@Deprecated(since = "7.2", forRemoval = true)
234+
@SuppressWarnings("removal")
229235
public void setErrorHandler(ResponseErrorHandler errorHandler) {
230236
assertLocalClient("errorHandler");
231237
RestClient.Builder localRestClientBuilder = this.localRestClientBuilder;
@@ -325,6 +331,7 @@ public void setEncodingMode(DefaultUriBuilderFactory.EncodingMode encodingMode)
325331
}
326332
}
327333

334+
@SuppressWarnings("removal")
328335
private ResponseEntity<?> exchangeWithRestTemplate(Object uri, HttpMethod httpMethod, HttpEntity<?> httpRequest,
329336
Object expectedResponseType, Map<String, ?> uriVariables) {
330337

spring-integration-http/src/test/java/org/springframework/integration/http/HttpProxyScenarioTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@
5959
* @author Artem Bilan
6060
* @author Gary Russell
6161
* @author Arun Sethumadhavan
62+
* @author Burak Kalayci
6263
*
6364
* @since 3.0
6465
*/
6566
@SpringJUnitConfig
6667
@DirtiesContext
68+
@SuppressWarnings("removal")
6769
public class HttpProxyScenarioTests {
6870

6971
private final HandlerAdapter handlerAdapter = new HttpRequestHandlerAdapter();

spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundChannelAdapterParserTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@
6363
* @author Shiliang Li
6464
* @author Glenn Renfro
6565
* @author Arun Sethumadhavan
66+
* @author Burak Kalayci
6667
*/
6768
@SpringJUnitConfig
6869
@DirtiesContext
70+
@SuppressWarnings("removal")
6971
public class HttpOutboundChannelAdapterParserTests {
7072

7173
@Autowired

spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundGatewayParserTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@
6060
* @author Biju Kunjummen
6161
* @author Glenn Renfro
6262
* @author Arun Sethumadhavan
63+
* @author Burak Kalayci
6364
*/
6465
@SpringJUnitConfig
6566
@DirtiesContext
67+
@SuppressWarnings("removal")
6668
public class HttpOutboundGatewayParserTests {
6769

6870
public static final ResponseErrorHandler mockResponseErrorHandler = mock();

spring-integration-http/src/test/java/org/springframework/integration/http/outbound/HttpRequestExecutingMessageHandlerTests.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
* @author Florian Schöffl
9494
* @author Glenn Renfro
9595
* @author Arun Sethumadhavan
96+
* @author Burak Kalayci
9697
*/
9798
public class HttpRequestExecutingMessageHandlerTests implements TestApplicationContextAware {
9899

@@ -793,11 +794,14 @@ public void testHttpOutboundGatewayWithinChain() {
793794
}
794795

795796
@Test
796-
@SuppressWarnings("removal")
797797
public void testUriExpression() {
798-
MockRestTemplate restTemplate = new MockRestTemplate();
798+
AtomicReference<URI> actualUri = new AtomicReference<>();
799799
HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler(
800-
new SpelExpressionParser().parseExpression("headers['foo']"), restTemplate);
800+
new SpelExpressionParser().parseExpression("headers['foo']"));
801+
handler.setRequestFactory((uri, httpMethod) -> {
802+
actualUri.set(uri);
803+
throw new RuntimeException("intentional");
804+
});
801805
setBeanFactory(handler);
802806
handler.afterPropertiesSet();
803807
String theURL = "https://bar/baz?foo#bar";
@@ -806,7 +810,7 @@ public void testUriExpression() {
806810
assertThatException()
807811
.isThrownBy(() -> handler.handleMessage(message));
808812

809-
assertThat(restTemplate.actualUrl.get()).isEqualTo(theURL);
813+
assertThat(actualUri.get()).hasToString(theURL);
810814
}
811815

812816
@Test
@@ -966,6 +970,7 @@ private static void setBeanFactory(HttpRequestExecutingMessageHandler handler) {
966970
handler.setBeanFactory(TEST_INTEGRATION_CONTEXT);
967971
}
968972

973+
@SuppressWarnings("removal")
969974
private static void setRestTemplateForTesting(HttpRequestExecutingMessageHandler handler,
970975
RestTemplate restTemplate) {
971976

@@ -1010,6 +1015,7 @@ public String toString() {
10101015

10111016
}
10121017

1018+
@SuppressWarnings("removal")
10131019
private static class MockRestTemplate extends RestTemplate {
10141020

10151021
private final AtomicReference<HttpEntity<?>> lastRequestEntity = new AtomicReference<>();
@@ -1027,7 +1033,7 @@ protected <T> T doExecute(URI url, String uriTemplate, HttpMethod method,
10271033

10281034
}
10291035

1030-
@SuppressWarnings("unused")
1036+
@SuppressWarnings({"unused", "removal"})
10311037
private static class MockRestTemplate2 extends RestTemplate {
10321038

10331039
private final AtomicReference<String> actualUrl = new AtomicReference<>();

0 commit comments

Comments
 (0)