Skip to content

Commit 49d5194

Browse files
committed
Jersey2/3: Fix a bug where, when using OAuth, the HTTP 401 status code persisted even if the second request after renewing the Bearer access token succeeded
1 parent 89b0bc4 commit 49d5194

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,11 +1299,9 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
12991299
try {
13001300
response = sendRequest(method, invocationBuilder, entity);
13011301
1302-
final int statusCode = response.getStatusInfo().getStatusCode();
1303-
13041302
{{#hasOAuthMethods}}
13051303
// If OAuth is used and a status 401 is received, renew the access token and retry the request
1306-
if (authNames != null && statusCode == Status.UNAUTHORIZED.getStatusCode()) {
1304+
if (authNames != null && response.getStatusInfo().getStatusCode() == Status.UNAUTHORIZED.getStatusCode()) {
13071305
for (String authName : authNames) {
13081306
Authentication authentication = authentications.get(authName);
13091307
if (authentication instanceof OAuth) {
@@ -1317,8 +1315,10 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
13171315
}
13181316
}
13191317
}
1320-
1318+
13211319
{{/hasOAuthMethods}}
1320+
final int statusCode = response.getStatusInfo().getStatusCode();
1321+
13221322
Map<String, List<String>> responseHeaders = buildResponseHeaders(response);
13231323

13241324
if (statusCode == Status.NO_CONTENT.getStatusCode()) {

modules/openapi-generator/src/main/resources/Java/libraries/jersey3/ApiClient.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,11 +1299,9 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
12991299
try {
13001300
response = sendRequest(method, invocationBuilder, entity);
13011301
1302-
final int statusCode = response.getStatusInfo().getStatusCode();
1303-
13041302
{{#hasOAuthMethods}}
13051303
// If OAuth is used and a status 401 is received, renew the access token and retry the request
1306-
if (authNames != null && statusCode == Status.UNAUTHORIZED.getStatusCode()) {
1304+
if (authNames != null && response.getStatusInfo().getStatusCode() == Status.UNAUTHORIZED.getStatusCode()) {
13071305
for (String authName : authNames) {
13081306
Authentication authentication = authentications.get(authName);
13091307
if (authentication instanceof OAuth) {
@@ -1319,6 +1317,8 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
13191317
}
13201318

13211319
{{/hasOAuthMethods}}
1320+
final int statusCode = response.getStatusInfo().getStatusCode();
1321+
13221322
Map<String, List<String>> responseHeaders = buildResponseHeaders(response);
13231323

13241324
if (statusCode == Status.NO_CONTENT.getStatusCode()) {

0 commit comments

Comments
 (0)