Skip to content

Commit 2fe169a

Browse files
authored
Remove deprecated code usage from core module (#1145)
Fixes #857 To simply removal, Request.Body was returned back to an internal component and additional methods were added to Request to expose it's capabilities outside of the object. All other deprecated usage in core modules has been removed. Deprecated code still exists in the test cases and will be removed once the deprecated methods are removed in our next major release.
1 parent a41caeb commit 2fe169a

60 files changed

Lines changed: 429 additions & 328 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

benchmark/src/main/java/feign/benchmark/DecoderIteratorsBenchmark.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ private void fetch(Object o) {
7373
}
7474
}
7575

76+
@SuppressWarnings("deprecation")
7677
@Setup(Level.Invocation)
7778
public void buildResponse() {
7879
response =
@@ -81,7 +82,7 @@ public void buildResponse() {
8182
.reason("OK")
8283
.request(Request.create(HttpMethod.GET, "/", Collections.emptyMap(), null, Util.UTF_8))
8384
.headers(Collections.emptyMap())
84-
.body(carsJson(Integer.valueOf(size)), Util.UTF_8)
85+
.body(carsJson(Integer.parseInt(size)), Util.UTF_8)
8586
.build();
8687
}
8788

core/src/main/java/feign/Client.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ HttpURLConnection convertAndSend(Request request, Options options) throws IOExce
159159
connection.addRequestProperty("Accept", "*/*");
160160
}
161161

162-
if (request.requestBody().asBytes() != null) {
162+
if (request.body() != null) {
163163
if (contentLength != null) {
164164
connection.setFixedLengthStreamingMode(contentLength);
165165
} else {
@@ -173,7 +173,7 @@ HttpURLConnection convertAndSend(Request request, Options options) throws IOExce
173173
out = new DeflaterOutputStream(out);
174174
}
175175
try {
176-
out.write(request.requestBody().asBytes());
176+
out.write(request.body());
177177
} finally {
178178
try {
179179
out.close();

core/src/main/java/feign/Contract.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2019 The Feign Authors
2+
* Copyright 2012-2020 The Feign Authors
33
*
44
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
55
* except in compliance with the License. You may obtain a copy of the License at
@@ -302,7 +302,6 @@ public Default() {
302302
if (expander != Param.ToStringExpander.class) {
303303
data.indexToExpanderClass().put(paramIndex, expander);
304304
}
305-
data.indexToEncoded().put(paramIndex, paramAnnotation.encoded());
306305
if (!data.template().hasRequestVariable(name)) {
307306
data.formParams().add(name);
308307
}

core/src/main/java/feign/Feign.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import feign.codec.Decoder;
2323
import feign.codec.Encoder;
2424
import feign.codec.ErrorDecoder;
25+
import feign.querymap.FieldQueryMapEncoder;
2526
import java.io.IOException;
2627
import java.lang.reflect.Method;
2728
import java.lang.reflect.Type;
@@ -103,7 +104,7 @@ public static class Builder {
103104
private Logger logger = new NoOpLogger();
104105
private Encoder encoder = new Encoder.Default();
105106
private Decoder decoder = new Decoder.Default();
106-
private QueryMapEncoder queryMapEncoder = new QueryMapEncoder.Default();
107+
private QueryMapEncoder queryMapEncoder = new FieldQueryMapEncoder();
107108
private ErrorDecoder errorDecoder = new ErrorDecoder.Default();
108109
private Options options = new Options();
109110
private InvocationHandlerFactory invocationHandlerFactory =

core/src/main/java/feign/FeignException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2019 The Feign Authors
2+
* Copyright 2012-2020 The Feign Authors
33
*
44
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
55
* except in compliance with the License. You may obtain a copy of the License at
@@ -147,7 +147,7 @@ static FeignException errorReading(Request request, Response response, IOExcepti
147147
format("%s reading %s %s", cause.getMessage(), request.httpMethod(), request.url()),
148148
request,
149149
cause,
150-
request.requestBody().asBytes());
150+
request.body());
151151
}
152152

153153
public static FeignException errorStatus(String methodKey, Response response) {

core/src/main/java/feign/Logger.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
*/
1414
package feign;
1515

16-
import static feign.Util.UTF_8;
17-
import static feign.Util.decodeOrDefault;
18-
import static feign.Util.valuesOrEmpty;
16+
import static feign.Util.*;
1917

2018
import java.io.IOException;
2119
import java.io.PrintWriter;
@@ -56,13 +54,11 @@ protected void logRequest(String configKey, Level logLevel, Request request) {
5654
}
5755

5856
int bodyLength = 0;
59-
if (request.requestBody().asBytes() != null) {
60-
bodyLength = request.requestBody().asBytes().length;
57+
if (request.body() != null) {
58+
bodyLength = request.length();
6159
if (logLevel.ordinal() >= Level.FULL.ordinal()) {
6260
String bodyText =
63-
request.charset() != null
64-
? new String(request.requestBody().asBytes(), request.charset())
65-
: null;
61+
request.charset() != null ? new String(request.body(), request.charset()) : null;
6662
log(configKey, ""); // CRLF
6763
log(configKey, "%s", bodyText != null ? bodyText : "Binary data");
6864
}

core/src/main/java/feign/QueryMap.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@
5656
* Once this conversion is applied, the query keys and resulting String values follow the same
5757
* contract as if they were set using {@link RequestTemplate#query(String, String...)}.
5858
*/
59+
@SuppressWarnings("deprecation")
5960
@Retention(RUNTIME)
6061
@java.lang.annotation.Target(PARAMETER)
6162
public @interface QueryMap {
63+
6264
/**
6365
* Specifies whether parameter names and values are already encoded.
6466
*

0 commit comments

Comments
 (0)