Skip to content

Commit d1199f6

Browse files
mstrYodakdavisk6
authored andcommitted
Feature/replace deprecated body (#959)
In this pr the old `body()` method calls replaced with `requestBody().asBytes()` method which both exists in Request class. The intention is to remove deprecated code and keep source code clean. Related to #857 * replaced old body with new Body.asBytes()
1 parent 03ff13e commit d1199f6

File tree

11 files changed

+21
-18
lines changed

11 files changed

+21
-18
lines changed

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

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

117-
if (request.body() != null) {
117+
if (request.requestBody().asBytes() != null) {
118118
if (contentLength != null) {
119119
connection.setFixedLengthStreamingMode(contentLength);
120120
} else {
@@ -128,7 +128,7 @@ HttpURLConnection convertAndSend(Request request, Options options) throws IOExce
128128
out = new DeflaterOutputStream(out);
129129
}
130130
try {
131-
out.write(request.body());
131+
out.write(request.requestBody().asBytes());
132132
} finally {
133133
try {
134134
out.close();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static FeignException errorReading(Request request, Response response, IOExcepti
6969
response.status(),
7070
format("%s reading %s %s", cause.getMessage(), request.httpMethod(), request.url()),
7171
cause,
72-
request.body());
72+
request.requestBody().asBytes());
7373
}
7474

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

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ protected void logRequest(String configKey, Level logLevel, Request request) {
5454
}
5555

5656
int bodyLength = 0;
57-
if (request.body() != null) {
58-
bodyLength = request.body().length;
57+
if (request.requestBody().asBytes() != null) {
58+
bodyLength = request.requestBody().asBytes().length;
5959
if (logLevel.ordinal() >= Level.FULL.ordinal()) {
6060
String bodyText =
61-
request.charset() != null ? new String(request.body(), request.charset()) : null;
61+
request.charset() != null
62+
? new String(request.requestBody().asBytes(), request.charset())
63+
: null;
6264
log(configKey, ""); // CRLF
6365
log(configKey, "%s", bodyText != null ? bodyText : "Binary data");
6466
}

core/src/test/java/feign/TargetTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public Request apply(RequestTemplate input) {
6161
urlEncoded.httpMethod(),
6262
urlEncoded.url().replace("%2F", "/"),
6363
urlEncoded.headers(),
64-
urlEncoded.body(), urlEncoded.charset());
64+
urlEncoded.requestBody().asBytes(), urlEncoded.charset());
6565
}
6666
};
6767

httpclient/src/main/java/feign/httpclient/ApacheHttpClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@ HttpUriRequest toHttpUriRequest(Request request, Request.Options options)
134134
}
135135

136136
// request body
137-
if (request.body() != null) {
137+
if (request.requestBody().asBytes() != null) {
138138
HttpEntity entity = null;
139139
if (request.charset() != null) {
140140
ContentType contentType = getContentType(request);
141-
String content = new String(request.body(), request.charset());
141+
String content = new String(request.requestBody().asBytes(), request.charset());
142142
entity = new StringEntity(content, contentType);
143143
} else {
144-
entity = new ByteArrayEntity(request.body());
144+
entity = new ByteArrayEntity(request.requestBody().asBytes());
145145
}
146146

147147
requestBuilder.setEntity(entity);

java11/src/main/java/feign/http2client/Http2Client.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ private Builder newRequestBuilder(Request request) throws IOException {
8080
}
8181

8282
final BodyPublisher body;
83-
if (request.body() == null) {
83+
if (request.requestBody().asBytes() == null) {
8484
body = BodyPublishers.noBody();
8585
} else {
86-
body = BodyPublishers.ofByteArray(request.body());
86+
body = BodyPublishers.ofByteArray(request.requestBody().asBytes());
8787
}
8888

8989
final Builder requestBuilder = HttpRequest.newBuilder()

jaxrs2/src/main/java/feign/jaxrs2/JAXRSClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ public feign.Response execute(feign.Request request, Options options) throws IOE
6969
}
7070

7171
private Entity<byte[]> createRequestEntity(feign.Request request) {
72-
if (request.body() == null) {
72+
if (request.requestBody().asBytes() == null) {
7373
return null;
7474
}
7575

7676
return Entity.entity(
77-
request.body(),
77+
request.requestBody().asBytes(),
7878
new Variant(mediaType(request.headers()), locale(request.headers()),
7979
encoding(request.charset())));
8080
}

mock/src/main/java/feign/mock/RequestKey.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private RequestKey(Request request) {
112112
this.url = buildUrl(request);
113113
this.headers = RequestHeaders.of(request.headers());
114114
this.charset = request.charset();
115-
this.body = request.body();
115+
this.body = request.requestBody().asBytes();
116116
}
117117

118118
public HttpMethod getMethod() {

mock/src/test/java/feign/mock/MockClientTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ public void verifyInvocation() {
165165
mockClient.verifyTimes(HttpMethod.POST, "/repos/netflix/feign/contributors", 1);
166166
assertThat(results, hasSize(1));
167167

168-
byte[] body = mockClient.verifyOne(HttpMethod.POST, "/repos/netflix/feign/contributors").body();
168+
byte[] body = mockClient.verifyOne(HttpMethod.POST, "/repos/netflix/feign/contributors")
169+
.requestBody().asBytes();
169170
assertThat(body, notNullValue());
170171

171172
String message = new String(body);

okhttp/src/main/java/feign/okhttp/OkHttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static Request toOkHttpRequest(feign.Request input) {
7171
requestBuilder.addHeader("Accept", "*/*");
7272
}
7373

74-
byte[] inputBody = input.body();
74+
byte[] inputBody = input.requestBody().asBytes();
7575
boolean isMethodWithBody =
7676
HttpMethod.POST == input.httpMethod() || HttpMethod.PUT == input.httpMethod()
7777
|| HttpMethod.PATCH == input.httpMethod();

0 commit comments

Comments
 (0)