Skip to content

Commit 6b1a845

Browse files
committed
Polishing
1 parent d8f650e commit 6b1a845

File tree

2 files changed

+101
-65
lines changed

2 files changed

+101
-65
lines changed

spring-web/src/main/java/org/springframework/web/client/RestClientResponseException.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -54,30 +54,34 @@ public class RestClientResponseException extends RestClientException {
5454
* Construct a new instance of with the given response data.
5555
* @param statusCode the raw status code value
5656
* @param statusText the status text
57-
* @param responseHeaders the response headers (may be {@code null})
57+
* @param headers the response headers (may be {@code null})
5858
* @param responseBody the response body content (may be {@code null})
5959
* @param responseCharset the response body charset (may be {@code null})
6060
*/
61-
public RestClientResponseException(String message, int statusCode, String statusText,
62-
@Nullable HttpHeaders responseHeaders, @Nullable byte[] responseBody, @Nullable Charset responseCharset) {
63-
this(message, HttpStatusCode.valueOf(statusCode), statusText, responseHeaders, responseBody, responseCharset);
61+
public RestClientResponseException(
62+
String message, int statusCode, String statusText, @Nullable HttpHeaders headers,
63+
@Nullable byte[] responseBody, @Nullable Charset responseCharset) {
64+
65+
this(message, HttpStatusCode.valueOf(statusCode), statusText, headers, responseBody, responseCharset);
6466
}
6567

6668
/**
6769
* Construct a new instance of with the given response data.
6870
* @param statusCode the raw status code value
6971
* @param statusText the status text
70-
* @param responseHeaders the response headers (may be {@code null})
72+
* @param headers the response headers (may be {@code null})
7173
* @param responseBody the response body content (may be {@code null})
7274
* @param responseCharset the response body charset (may be {@code null})
7375
* @since 6.0
7476
*/
75-
public RestClientResponseException(String message, HttpStatusCode statusCode, String statusText,
76-
@Nullable HttpHeaders responseHeaders, @Nullable byte[] responseBody, @Nullable Charset responseCharset) {
77+
public RestClientResponseException(
78+
String message, HttpStatusCode statusCode, String statusText, @Nullable HttpHeaders headers,
79+
@Nullable byte[] responseBody, @Nullable Charset responseCharset) {
80+
7781
super(message);
7882
this.statusCode = statusCode;
7983
this.statusText = statusText;
80-
this.responseHeaders = responseHeaders;
84+
this.responseHeaders = headers;
8185
this.responseBody = (responseBody != null ? responseBody : new byte[0]);
8286
this.responseCharset = (responseCharset != null ? responseCharset.name() : null);
8387
}

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClientResponseException.java

Lines changed: 88 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@
3131
* @author Arjen Poutsma
3232
* @since 5.0
3333
*/
34+
@SuppressWarnings("RedundantSuppression")
3435
public class WebClientResponseException extends WebClientException {
3536

3637
private static final long serialVersionUID = 4127543205414951611L;
@@ -55,8 +56,9 @@ public class WebClientResponseException extends WebClientException {
5556
* Constructor with response data only, and a default message.
5657
* @since 5.1
5758
*/
58-
public WebClientResponseException(int statusCode, String statusText,
59-
@Nullable HttpHeaders headers, @Nullable byte[] body, @Nullable Charset charset) {
59+
public WebClientResponseException(
60+
int statusCode, String statusText, @Nullable HttpHeaders headers,
61+
@Nullable byte[] body, @Nullable Charset charset) {
6062

6163
this(statusCode, statusText, headers, body, charset, null);
6264
}
@@ -65,9 +67,9 @@ public WebClientResponseException(int statusCode, String statusText,
6567
* Constructor with response data only, and a default message.
6668
* @since 5.1.4
6769
*/
68-
public WebClientResponseException(int status, String reasonPhrase,
69-
@Nullable HttpHeaders headers, @Nullable byte[] body, @Nullable Charset charset,
70-
@Nullable HttpRequest request) {
70+
public WebClientResponseException(
71+
int status, String reasonPhrase, @Nullable HttpHeaders headers,
72+
@Nullable byte[] body, @Nullable Charset charset, @Nullable HttpRequest request) {
7173

7274
this(HttpStatusCode.valueOf(status), reasonPhrase, headers, body, charset, request);
7375
}
@@ -76,10 +78,12 @@ public WebClientResponseException(int status, String reasonPhrase,
7678
* Constructor with response data only, and a default message.
7779
* @since 6.0
7880
*/
79-
public WebClientResponseException(HttpStatusCode statusCode, String reasonPhrase,
80-
@Nullable HttpHeaders headers, @Nullable byte[] body, @Nullable Charset charset,
81-
@Nullable HttpRequest request) {
82-
this(initMessage(statusCode, reasonPhrase, request), statusCode, reasonPhrase, headers, body, charset, request);
81+
public WebClientResponseException(
82+
HttpStatusCode statusCode, String reasonPhrase, @Nullable HttpHeaders headers,
83+
@Nullable byte[] body, @Nullable Charset charset, @Nullable HttpRequest request) {
84+
85+
this(initMessage(statusCode, reasonPhrase, request),
86+
statusCode, reasonPhrase, headers, body, charset, request);
8387
}
8488

8589
private static String initMessage(HttpStatusCode status, String reasonPhrase, @Nullable HttpRequest request) {
@@ -90,18 +94,22 @@ private static String initMessage(HttpStatusCode status, String reasonPhrase, @N
9094
/**
9195
* Constructor with a prepared message.
9296
*/
93-
public WebClientResponseException(String message, int statusCode, String statusText,
97+
public WebClientResponseException(
98+
String message, int statusCode, String statusText,
9499
@Nullable HttpHeaders headers, @Nullable byte[] responseBody, @Nullable Charset charset) {
100+
95101
this(message, statusCode, statusText, headers, responseBody, charset, null);
96102
}
97103

98104
/**
99105
* Constructor with a prepared message.
100106
* @since 5.1.4
101107
*/
102-
public WebClientResponseException(String message, int statusCode, String statusText,
108+
public WebClientResponseException(
109+
String message, int statusCode, String statusText,
103110
@Nullable HttpHeaders headers, @Nullable byte[] responseBody, @Nullable Charset charset,
104111
@Nullable HttpRequest request) {
112+
105113
this(message, HttpStatusCode.valueOf(statusCode), statusText, headers, responseBody, charset, request);
106114

107115

@@ -210,8 +218,9 @@ public static WebClientResponseException create(
210218
* @since 5.1.4
211219
*/
212220
public static WebClientResponseException create(
213-
int statusCode, String statusText, HttpHeaders headers, byte[] body,
214-
@Nullable Charset charset, @Nullable HttpRequest request) {
221+
int statusCode, String statusText, HttpHeaders headers,
222+
byte[] body, @Nullable Charset charset, @Nullable HttpRequest request) {
223+
215224
return create(HttpStatusCode.valueOf(statusCode), statusText, headers, body, charset, request);
216225
}
217226

@@ -220,8 +229,8 @@ public static WebClientResponseException create(
220229
* @since 6.0
221230
*/
222231
public static WebClientResponseException create(
223-
HttpStatusCode statusCode, String statusText, HttpHeaders headers, byte[] body,
224-
@Nullable Charset charset, @Nullable HttpRequest request) {
232+
HttpStatusCode statusCode, String statusText, HttpHeaders headers,
233+
byte[] body, @Nullable Charset charset, @Nullable HttpRequest request) {
225234

226235
if (statusCode instanceof HttpStatus httpStatus) {
227236
switch (httpStatus) {
@@ -263,7 +272,6 @@ public static WebClientResponseException create(
263272
}
264273

265274

266-
267275
// Subclasses for specific, client-side, HTTP status codes
268276

269277
/**
@@ -273,8 +281,10 @@ public static WebClientResponseException create(
273281
@SuppressWarnings("serial")
274282
public static class BadRequest extends WebClientResponseException {
275283

276-
BadRequest(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
284+
BadRequest(
285+
String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
277286
@Nullable HttpRequest request) {
287+
278288
super(HttpStatus.BAD_REQUEST.value(), statusText, headers, body, charset, request);
279289
}
280290

@@ -287,8 +297,10 @@ public static class BadRequest extends WebClientResponseException {
287297
@SuppressWarnings("serial")
288298
public static class Unauthorized extends WebClientResponseException {
289299

290-
Unauthorized(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
300+
Unauthorized(
301+
String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
291302
@Nullable HttpRequest request) {
303+
292304
super(HttpStatus.UNAUTHORIZED.value(), statusText, headers, body, charset, request);
293305
}
294306
}
@@ -300,8 +312,10 @@ public static class Unauthorized extends WebClientResponseException {
300312
@SuppressWarnings("serial")
301313
public static class Forbidden extends WebClientResponseException {
302314

303-
Forbidden(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
315+
Forbidden(
316+
String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
304317
@Nullable HttpRequest request) {
318+
305319
super(HttpStatus.FORBIDDEN.value(), statusText, headers, body, charset, request);
306320
}
307321
}
@@ -313,8 +327,10 @@ public static class Forbidden extends WebClientResponseException {
313327
@SuppressWarnings("serial")
314328
public static class NotFound extends WebClientResponseException {
315329

316-
NotFound(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
330+
NotFound(
331+
String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
317332
@Nullable HttpRequest request) {
333+
318334
super(HttpStatus.NOT_FOUND.value(), statusText, headers, body, charset, request);
319335
}
320336
}
@@ -326,10 +342,11 @@ public static class NotFound extends WebClientResponseException {
326342
@SuppressWarnings("serial")
327343
public static class MethodNotAllowed extends WebClientResponseException {
328344

329-
MethodNotAllowed(String statusText, HttpHeaders headers, byte[] body,
330-
@Nullable Charset charset, @Nullable HttpRequest request) {
331-
super(HttpStatus.METHOD_NOT_ALLOWED.value(), statusText, headers, body, charset,
332-
request);
345+
MethodNotAllowed(
346+
String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
347+
@Nullable HttpRequest request) {
348+
349+
super(HttpStatus.METHOD_NOT_ALLOWED.value(), statusText, headers, body, charset, request);
333350
}
334351
}
335352

@@ -340,8 +357,10 @@ public static class MethodNotAllowed extends WebClientResponseException {
340357
@SuppressWarnings("serial")
341358
public static class NotAcceptable extends WebClientResponseException {
342359

343-
NotAcceptable(String statusText, HttpHeaders headers, byte[] body,
344-
@Nullable Charset charset, @Nullable HttpRequest request) {
360+
NotAcceptable(
361+
String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
362+
@Nullable HttpRequest request) {
363+
345364
super(HttpStatus.NOT_ACCEPTABLE.value(), statusText, headers, body, charset, request);
346365
}
347366
}
@@ -353,8 +372,10 @@ public static class NotAcceptable extends WebClientResponseException {
353372
@SuppressWarnings("serial")
354373
public static class Conflict extends WebClientResponseException {
355374

356-
Conflict(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
375+
Conflict(
376+
String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
357377
@Nullable HttpRequest request) {
378+
358379
super(HttpStatus.CONFLICT.value(), statusText, headers, body, charset, request);
359380
}
360381
}
@@ -366,8 +387,10 @@ public static class Conflict extends WebClientResponseException {
366387
@SuppressWarnings("serial")
367388
public static class Gone extends WebClientResponseException {
368389

369-
Gone(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
390+
Gone(
391+
String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
370392
@Nullable HttpRequest request) {
393+
371394
super(HttpStatus.GONE.value(), statusText, headers, body, charset, request);
372395
}
373396
}
@@ -379,11 +402,11 @@ public static class Gone extends WebClientResponseException {
379402
@SuppressWarnings("serial")
380403
public static class UnsupportedMediaType extends WebClientResponseException {
381404

382-
UnsupportedMediaType(String statusText, HttpHeaders headers, byte[] body,
383-
@Nullable Charset charset, @Nullable HttpRequest request) {
405+
UnsupportedMediaType(
406+
String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
407+
@Nullable HttpRequest request) {
384408

385-
super(HttpStatus.UNSUPPORTED_MEDIA_TYPE.value(), statusText, headers, body, charset,
386-
request);
409+
super(HttpStatus.UNSUPPORTED_MEDIA_TYPE.value(), statusText, headers, body, charset, request);
387410
}
388411
}
389412

@@ -394,10 +417,11 @@ public static class UnsupportedMediaType extends WebClientResponseException {
394417
@SuppressWarnings("serial")
395418
public static class UnprocessableEntity extends WebClientResponseException {
396419

397-
UnprocessableEntity(String statusText, HttpHeaders headers, byte[] body,
398-
@Nullable Charset charset, @Nullable HttpRequest request) {
399-
super(HttpStatus.UNPROCESSABLE_ENTITY.value(), statusText, headers, body, charset,
400-
request);
420+
UnprocessableEntity(
421+
String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
422+
@Nullable HttpRequest request) {
423+
424+
super(HttpStatus.UNPROCESSABLE_ENTITY.value(), statusText, headers, body, charset, request);
401425
}
402426
}
403427

@@ -408,10 +432,11 @@ public static class UnprocessableEntity extends WebClientResponseException {
408432
@SuppressWarnings("serial")
409433
public static class TooManyRequests extends WebClientResponseException {
410434

411-
TooManyRequests(String statusText, HttpHeaders headers, byte[] body,
412-
@Nullable Charset charset, @Nullable HttpRequest request) {
413-
super(HttpStatus.TOO_MANY_REQUESTS.value(), statusText, headers, body, charset,
414-
request);
435+
TooManyRequests(
436+
String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
437+
@Nullable HttpRequest request) {
438+
439+
super(HttpStatus.TOO_MANY_REQUESTS.value(), statusText, headers, body, charset, request);
415440
}
416441
}
417442

@@ -426,10 +451,11 @@ public static class TooManyRequests extends WebClientResponseException {
426451
@SuppressWarnings("serial")
427452
public static class InternalServerError extends WebClientResponseException {
428453

429-
InternalServerError(String statusText, HttpHeaders headers, byte[] body,
430-
@Nullable Charset charset, @Nullable HttpRequest request) {
431-
super(HttpStatus.INTERNAL_SERVER_ERROR.value(), statusText, headers, body, charset,
432-
request);
454+
InternalServerError(
455+
String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
456+
@Nullable HttpRequest request) {
457+
458+
super(HttpStatus.INTERNAL_SERVER_ERROR.value(), statusText, headers, body, charset, request);
433459
}
434460
}
435461

@@ -440,8 +466,10 @@ public static class InternalServerError extends WebClientResponseException {
440466
@SuppressWarnings("serial")
441467
public static class NotImplemented extends WebClientResponseException {
442468

443-
NotImplemented(String statusText, HttpHeaders headers, byte[] body,
444-
@Nullable Charset charset, @Nullable HttpRequest request) {
469+
NotImplemented(
470+
String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
471+
@Nullable HttpRequest request) {
472+
445473
super(HttpStatus.NOT_IMPLEMENTED.value(), statusText, headers, body, charset, request);
446474
}
447475
}
@@ -453,8 +481,10 @@ public static class NotImplemented extends WebClientResponseException {
453481
@SuppressWarnings("serial")
454482
public static class BadGateway extends WebClientResponseException {
455483

456-
BadGateway(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
484+
BadGateway(
485+
String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
457486
@Nullable HttpRequest request) {
487+
458488
super(HttpStatus.BAD_GATEWAY.value(), statusText, headers, body, charset, request);
459489
}
460490
}
@@ -466,10 +496,11 @@ public static class BadGateway extends WebClientResponseException {
466496
@SuppressWarnings("serial")
467497
public static class ServiceUnavailable extends WebClientResponseException {
468498

469-
ServiceUnavailable(String statusText, HttpHeaders headers, byte[] body,
470-
@Nullable Charset charset, @Nullable HttpRequest request) {
471-
super(HttpStatus.SERVICE_UNAVAILABLE.value(), statusText, headers, body, charset,
472-
request);
499+
ServiceUnavailable(
500+
String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
501+
@Nullable HttpRequest request) {
502+
503+
super(HttpStatus.SERVICE_UNAVAILABLE.value(), statusText, headers, body, charset, request);
473504
}
474505
}
475506

@@ -480,10 +511,11 @@ public static class ServiceUnavailable extends WebClientResponseException {
480511
@SuppressWarnings("serial")
481512
public static class GatewayTimeout extends WebClientResponseException {
482513

483-
GatewayTimeout(String statusText, HttpHeaders headers, byte[] body,
484-
@Nullable Charset charset, @Nullable HttpRequest request) {
485-
super(HttpStatus.GATEWAY_TIMEOUT.value(), statusText, headers, body, charset,
486-
request);
514+
GatewayTimeout(
515+
String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
516+
@Nullable HttpRequest request) {
517+
518+
super(HttpStatus.GATEWAY_TIMEOUT.value(), statusText, headers, body, charset, request);
487519
}
488520
}
489521

0 commit comments

Comments
 (0)