Skip to content

Commit 75e569f

Browse files
authored
Remove deprecated code usage from core module (OpenFeign#1145)
Fixes OpenFeign#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 ee20541 commit 75e569f

60 files changed

Lines changed: 456 additions & 332 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
@@ -75,14 +75,15 @@ private void fetch(Object o) {
7575
}
7676
}
7777

78+
@SuppressWarnings("deprecation")
7879
@Setup(Level.Invocation)
7980
public void buildResponse() {
8081
response = Response.builder()
8182
.status(200)
8283
.reason("OK")
8384
.request(Request.create(HttpMethod.GET, "/", Collections.emptyMap(), null, Util.UTF_8))
8485
.headers(Collections.emptyMap())
85-
.body(carsJson(Integer.valueOf(size)), Util.UTF_8)
86+
.body(carsJson(Integer.parseInt(size)), Util.UTF_8)
8687
.build();
8788
}
8889

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

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

164-
if (request.requestBody().asBytes() != null) {
164+
if (request.body() != null) {
165165
if (contentLength != null) {
166166
connection.setFixedLengthStreamingMode(contentLength);
167167
} else {
@@ -175,7 +175,7 @@ HttpURLConnection convertAndSend(Request request, Options options) throws IOExce
175175
out = new DeflaterOutputStream(out);
176176
}
177177
try {
178-
out.write(request.requestBody().asBytes());
178+
out.write(request.body());
179179
} finally {
180180
try {
181181
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
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
55
* in compliance with the License. You may obtain a copy of the License at
@@ -278,7 +278,6 @@ public Default() {
278278
if (expander != Param.ToStringExpander.class) {
279279
data.indexToExpanderClass().put(paramIndex, expander);
280280
}
281-
data.indexToEncoded().put(paramIndex, paramAnnotation.encoded());
282281
if (!data.template().hasRequestVariable(name)) {
283282
data.formParams().add(name);
284283
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import feign.codec.Decoder;
2626
import feign.codec.Encoder;
2727
import feign.codec.ErrorDecoder;
28+
import feign.querymap.FieldQueryMapEncoder;
2829
import static feign.ExceptionPropagationPolicy.NONE;
2930

3031
/**
@@ -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
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
55
* in compliance with the License. You may obtain a copy of the License at
@@ -148,7 +148,7 @@ static FeignException errorReading(Request request, Response response, IOExcepti
148148
format("%s reading %s %s", cause.getMessage(), request.httpMethod(), request.url()),
149149
request,
150150
cause,
151-
request.requestBody().asBytes());
151+
request.body());
152152
}
153153

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

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@
1616
import java.io.IOException;
1717
import java.io.PrintWriter;
1818
import java.io.StringWriter;
19-
import java.util.concurrent.atomic.AtomicInteger;
2019
import java.util.logging.FileHandler;
2120
import java.util.logging.LogRecord;
2221
import java.util.logging.SimpleFormatter;
23-
import static feign.Util.UTF_8;
24-
import static feign.Util.decodeOrDefault;
25-
import static feign.Util.valuesOrEmpty;
22+
import static feign.Util.*;
2623

2724
/**
2825
* Simple logging abstraction for debug messages. Adapted from {@code retrofit.RestAdapter.Log}.
@@ -55,12 +52,12 @@ protected void logRequest(String configKey, Level logLevel, Request request) {
5552
}
5653

5754
int bodyLength = 0;
58-
if (request.requestBody().asBytes() != null) {
59-
bodyLength = request.requestBody().asBytes().length;
55+
if (request.body() != null) {
56+
bodyLength = request.length();
6057
if (logLevel.ordinal() >= Level.FULL.ordinal()) {
6158
String bodyText =
6259
request.charset() != null
63-
? new String(request.requestBody().asBytes(), request.charset())
60+
? new String(request.body(), request.charset())
6461
: null;
6562
log(configKey, ""); // CRLF
6663
log(configKey, "%s", bodyText != null ? bodyText : "Binary data");

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@
5353
* Once this conversion is applied, the query keys and resulting String values follow the same
5454
* contract as if they were set using {@link RequestTemplate#query(String, String...)}.
5555
*/
56+
@SuppressWarnings("deprecation")
5657
@Retention(RUNTIME)
5758
@java.lang.annotation.Target(PARAMETER)
5859
public @interface QueryMap {
60+
5961
/**
6062
* Specifies whether parameter names and values are already encoded.
6163
*

0 commit comments

Comments
 (0)