Skip to content

Commit a66dd20

Browse files
authored
Jersey2: Do not reinitialize ClientConfig with default values when building HTTP Client (#20687)
* Do not reinitialize ClientConfig with default values when building HTTP Client * Regenerate Jersey2/3 examples
1 parent 3462310 commit a66dd20

File tree

13 files changed

+140
-62
lines changed
  • modules/openapi-generator/src/main/resources/Java/libraries
  • samples
    • client
      • others/java
        • jersey2-oneOf-Mixed/src/main/java/org/openapitools/client
        • jersey2-oneOf-duplicates/src/main/java/org/openapitools/client
      • petstore/java
    • openapi3/client
      • extensions/x-auth-id-alias/java/jersey2-java8/src/main/java/org/openapitools/client
      • petstore/java
        • jersey2-java8-special-characters/src/main/java/org/openapitools/client
        • jersey2-java8-swagger1/src/main/java/org/openapitools/client
        • jersey2-java8-swagger2/src/main/java/org/openapitools/client
        • jersey2-java8/src/main/java/org/openapitools/client

13 files changed

+140
-62
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
694694
*/
695695
public ApiClient setDebugging(boolean debugging) {
696696
this.debugging = debugging;
697+
applyDebugSetting(this.clientConfig);
697698
// Rebuild HTTP Client according to the new "debugging" value.
698699
this.httpClient = buildHttpClient();
699700
return this;
@@ -1383,8 +1384,10 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
13831384
* @return Client
13841385
*/
13851386
protected Client buildHttpClient() {
1386-
// recreate the client config to pickup changes
1387-
clientConfig = getDefaultClientConfig();
1387+
// Create ClientConfig if it has not been initialized yet
1388+
if (clientConfig == null) {
1389+
clientConfig = getDefaultClientConfig();
1390+
}
13881391

13891392
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
13901393
clientBuilder = clientBuilder.withConfig(clientConfig);
@@ -1405,6 +1408,11 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
14051408
clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
14061409
// turn off compliance validation to be able to send payloads with DELETE calls
14071410
clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
1411+
applyDebugSetting(clientConfig);
1412+
return clientConfig;
1413+
}
1414+
1415+
private void applyDebugSetting(ClientConfig clientConfig) {
14081416
if (debugging) {
14091417
clientConfig.register(new LoggingFeature(java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), java.util.logging.Level.INFO, LoggingFeature.Verbosity.PAYLOAD_ANY, 1024*50 /* Log payloads up to 50K */));
14101418
clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);
@@ -1414,8 +1422,6 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
14141422
// suppress warnings for payloads with DELETE calls:
14151423
java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE);
14161424
}
1417-
1418-
return clientConfig;
14191425
}
14201426

14211427
/**
@@ -1507,4 +1513,4 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
15071513
auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri);
15081514
}
15091515
}
1510-
}
1516+
}

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
694694
*/
695695
public ApiClient setDebugging(boolean debugging) {
696696
this.debugging = debugging;
697+
applyDebugSetting(this.clientConfig);
697698
// Rebuild HTTP Client according to the new "debugging" value.
698699
this.httpClient = buildHttpClient();
699700
return this;
@@ -1383,8 +1384,10 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
13831384
* @return Client
13841385
*/
13851386
protected Client buildHttpClient() {
1386-
// recreate the client config to pickup changes
1387+
// Create ClientConfig if it has not been initialized yet
1388+
if (clientConfig == null) {
13871389
clientConfig = getDefaultClientConfig();
1390+
}
13881391

13891392
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
13901393
clientBuilder = clientBuilder.withConfig(clientConfig);
@@ -1405,6 +1408,11 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
14051408
clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
14061409
// turn off compliance validation to be able to send payloads with DELETE calls
14071410
clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
1411+
applyDebugSetting(clientConfig);
1412+
return clientConfig;
1413+
}
1414+
1415+
private void applyDebugSetting(ClientConfig clientConfig) {
14081416
if (debugging) {
14091417
clientConfig.register(new LoggingFeature(java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), java.util.logging.Level.INFO, LoggingFeature.Verbosity.PAYLOAD_ANY, 1024*50 /* Log payloads up to 50K */));
14101418
clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);
@@ -1414,8 +1422,6 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
14141422
// suppress warnings for payloads with DELETE calls:
14151423
java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE);
14161424
}
1417-
1418-
return clientConfig;
14191425
}
14201426

14211427
/**
@@ -1507,4 +1513,4 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
15071513
auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri);
15081514
}
15091515
}
1510-
}
1516+
}

samples/client/others/java/jersey2-oneOf-Mixed/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ public boolean isDebugging() {
473473
*/
474474
public ApiClient setDebugging(boolean debugging) {
475475
this.debugging = debugging;
476+
applyDebugSetting(this.clientConfig);
476477
// Rebuild HTTP Client according to the new "debugging" value.
477478
this.httpClient = buildHttpClient();
478479
return this;
@@ -1139,8 +1140,10 @@ public <T> ApiResponse<T> invokeAPI(String path, String method, List<Pair> query
11391140
* @return Client
11401141
*/
11411142
protected Client buildHttpClient() {
1142-
// recreate the client config to pickup changes
1143-
clientConfig = getDefaultClientConfig();
1143+
// Create ClientConfig if it has not been initialized yet
1144+
if (clientConfig == null) {
1145+
clientConfig = getDefaultClientConfig();
1146+
}
11441147

11451148
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
11461149
clientBuilder = clientBuilder.withConfig(clientConfig);
@@ -1161,6 +1164,11 @@ public ClientConfig getDefaultClientConfig() {
11611164
clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
11621165
// turn off compliance validation to be able to send payloads with DELETE calls
11631166
clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
1167+
applyDebugSetting(clientConfig);
1168+
return clientConfig;
1169+
}
1170+
1171+
private void applyDebugSetting(ClientConfig clientConfig) {
11641172
if (debugging) {
11651173
clientConfig.register(new LoggingFeature(java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), java.util.logging.Level.INFO, LoggingFeature.Verbosity.PAYLOAD_ANY, 1024*50 /* Log payloads up to 50K */));
11661174
clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);
@@ -1170,8 +1178,6 @@ public ClientConfig getDefaultClientConfig() {
11701178
// suppress warnings for payloads with DELETE calls:
11711179
java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE);
11721180
}
1173-
1174-
return clientConfig;
11751181
}
11761182

11771183
/**
@@ -1263,4 +1269,4 @@ protected void updateParamsForAuth(String[] authNames, List<Pair> queryParams, M
12631269
auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri);
12641270
}
12651271
}
1266-
}
1272+
}

samples/client/others/java/jersey2-oneOf-duplicates/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ public boolean isDebugging() {
473473
*/
474474
public ApiClient setDebugging(boolean debugging) {
475475
this.debugging = debugging;
476+
applyDebugSetting(this.clientConfig);
476477
// Rebuild HTTP Client according to the new "debugging" value.
477478
this.httpClient = buildHttpClient();
478479
return this;
@@ -1139,8 +1140,10 @@ public <T> ApiResponse<T> invokeAPI(String path, String method, List<Pair> query
11391140
* @return Client
11401141
*/
11411142
protected Client buildHttpClient() {
1142-
// recreate the client config to pickup changes
1143-
clientConfig = getDefaultClientConfig();
1143+
// Create ClientConfig if it has not been initialized yet
1144+
if (clientConfig == null) {
1145+
clientConfig = getDefaultClientConfig();
1146+
}
11441147

11451148
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
11461149
clientBuilder = clientBuilder.withConfig(clientConfig);
@@ -1161,6 +1164,11 @@ public ClientConfig getDefaultClientConfig() {
11611164
clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
11621165
// turn off compliance validation to be able to send payloads with DELETE calls
11631166
clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
1167+
applyDebugSetting(clientConfig);
1168+
return clientConfig;
1169+
}
1170+
1171+
private void applyDebugSetting(ClientConfig clientConfig) {
11641172
if (debugging) {
11651173
clientConfig.register(new LoggingFeature(java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), java.util.logging.Level.INFO, LoggingFeature.Verbosity.PAYLOAD_ANY, 1024*50 /* Log payloads up to 50K */));
11661174
clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);
@@ -1170,8 +1178,6 @@ public ClientConfig getDefaultClientConfig() {
11701178
// suppress warnings for payloads with DELETE calls:
11711179
java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE);
11721180
}
1173-
1174-
return clientConfig;
11751181
}
11761182

11771183
/**
@@ -1263,4 +1269,4 @@ protected void updateParamsForAuth(String[] authNames, List<Pair> queryParams, M
12631269
auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri);
12641270
}
12651271
}
1266-
}
1272+
}

samples/client/petstore/java/jersey2-java8-localdatetime/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ public boolean isDebugging() {
614614
*/
615615
public ApiClient setDebugging(boolean debugging) {
616616
this.debugging = debugging;
617+
applyDebugSetting(this.clientConfig);
617618
// Rebuild HTTP Client according to the new "debugging" value.
618619
this.httpClient = buildHttpClient();
619620
return this;
@@ -1296,8 +1297,10 @@ public <T> ApiResponse<T> invokeAPI(String path, String method, List<Pair> query
12961297
* @return Client
12971298
*/
12981299
protected Client buildHttpClient() {
1299-
// recreate the client config to pickup changes
1300-
clientConfig = getDefaultClientConfig();
1300+
// Create ClientConfig if it has not been initialized yet
1301+
if (clientConfig == null) {
1302+
clientConfig = getDefaultClientConfig();
1303+
}
13011304

13021305
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
13031306
clientBuilder = clientBuilder.withConfig(clientConfig);
@@ -1318,6 +1321,11 @@ public ClientConfig getDefaultClientConfig() {
13181321
clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
13191322
// turn off compliance validation to be able to send payloads with DELETE calls
13201323
clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
1324+
applyDebugSetting(clientConfig);
1325+
return clientConfig;
1326+
}
1327+
1328+
private void applyDebugSetting(ClientConfig clientConfig) {
13211329
if (debugging) {
13221330
clientConfig.register(new LoggingFeature(java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), java.util.logging.Level.INFO, LoggingFeature.Verbosity.PAYLOAD_ANY, 1024*50 /* Log payloads up to 50K */));
13231331
clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);
@@ -1327,8 +1335,6 @@ public ClientConfig getDefaultClientConfig() {
13271335
// suppress warnings for payloads with DELETE calls:
13281336
java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE);
13291337
}
1330-
1331-
return clientConfig;
13321338
}
13331339

13341340
/**
@@ -1420,4 +1426,4 @@ protected void updateParamsForAuth(String[] authNames, List<Pair> queryParams, M
14201426
auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri);
14211427
}
14221428
}
1423-
}
1429+
}

samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ public boolean isDebugging() {
614614
*/
615615
public ApiClient setDebugging(boolean debugging) {
616616
this.debugging = debugging;
617+
applyDebugSetting(this.clientConfig);
617618
// Rebuild HTTP Client according to the new "debugging" value.
618619
this.httpClient = buildHttpClient();
619620
return this;
@@ -1296,8 +1297,10 @@ public <T> ApiResponse<T> invokeAPI(String path, String method, List<Pair> query
12961297
* @return Client
12971298
*/
12981299
protected Client buildHttpClient() {
1299-
// recreate the client config to pickup changes
1300-
clientConfig = getDefaultClientConfig();
1300+
// Create ClientConfig if it has not been initialized yet
1301+
if (clientConfig == null) {
1302+
clientConfig = getDefaultClientConfig();
1303+
}
13011304

13021305
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
13031306
clientBuilder = clientBuilder.withConfig(clientConfig);
@@ -1318,6 +1321,11 @@ public ClientConfig getDefaultClientConfig() {
13181321
clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
13191322
// turn off compliance validation to be able to send payloads with DELETE calls
13201323
clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
1324+
applyDebugSetting(clientConfig);
1325+
return clientConfig;
1326+
}
1327+
1328+
private void applyDebugSetting(ClientConfig clientConfig) {
13211329
if (debugging) {
13221330
clientConfig.register(new LoggingFeature(java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), java.util.logging.Level.INFO, LoggingFeature.Verbosity.PAYLOAD_ANY, 1024*50 /* Log payloads up to 50K */));
13231331
clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);
@@ -1327,8 +1335,6 @@ public ClientConfig getDefaultClientConfig() {
13271335
// suppress warnings for payloads with DELETE calls:
13281336
java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE);
13291337
}
1330-
1331-
return clientConfig;
13321338
}
13331339

13341340
/**
@@ -1420,4 +1426,4 @@ protected void updateParamsForAuth(String[] authNames, List<Pair> queryParams, M
14201426
auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri);
14211427
}
14221428
}
1423-
}
1429+
}

samples/client/petstore/java/jersey3-oneOf/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ public boolean isDebugging() {
473473
*/
474474
public ApiClient setDebugging(boolean debugging) {
475475
this.debugging = debugging;
476+
applyDebugSetting(this.clientConfig);
476477
// Rebuild HTTP Client according to the new "debugging" value.
477478
this.httpClient = buildHttpClient();
478479
return this;
@@ -1139,8 +1140,10 @@ public <T> ApiResponse<T> invokeAPI(String path, String method, List<Pair> query
11391140
* @return Client
11401141
*/
11411142
protected Client buildHttpClient() {
1142-
// recreate the client config to pickup changes
1143+
// Create ClientConfig if it has not been initialized yet
1144+
if (clientConfig == null) {
11431145
clientConfig = getDefaultClientConfig();
1146+
}
11441147

11451148
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
11461149
clientBuilder = clientBuilder.withConfig(clientConfig);
@@ -1161,6 +1164,11 @@ public ClientConfig getDefaultClientConfig() {
11611164
clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
11621165
// turn off compliance validation to be able to send payloads with DELETE calls
11631166
clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
1167+
applyDebugSetting(clientConfig);
1168+
return clientConfig;
1169+
}
1170+
1171+
private void applyDebugSetting(ClientConfig clientConfig) {
11641172
if (debugging) {
11651173
clientConfig.register(new LoggingFeature(java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), java.util.logging.Level.INFO, LoggingFeature.Verbosity.PAYLOAD_ANY, 1024*50 /* Log payloads up to 50K */));
11661174
clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);
@@ -1170,8 +1178,6 @@ public ClientConfig getDefaultClientConfig() {
11701178
// suppress warnings for payloads with DELETE calls:
11711179
java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE);
11721180
}
1173-
1174-
return clientConfig;
11751181
}
11761182

11771183
/**
@@ -1263,4 +1269,4 @@ protected void updateParamsForAuth(String[] authNames, List<Pair> queryParams, M
12631269
auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri);
12641270
}
12651271
}
1266-
}
1272+
}

samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ public boolean isDebugging() {
696696
*/
697697
public ApiClient setDebugging(boolean debugging) {
698698
this.debugging = debugging;
699+
applyDebugSetting(this.clientConfig);
699700
// Rebuild HTTP Client according to the new "debugging" value.
700701
this.httpClient = buildHttpClient();
701702
return this;
@@ -1378,8 +1379,10 @@ public <T> ApiResponse<T> invokeAPI(String path, String method, List<Pair> query
13781379
* @return Client
13791380
*/
13801381
protected Client buildHttpClient() {
1381-
// recreate the client config to pickup changes
1382+
// Create ClientConfig if it has not been initialized yet
1383+
if (clientConfig == null) {
13821384
clientConfig = getDefaultClientConfig();
1385+
}
13831386

13841387
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
13851388
clientBuilder = clientBuilder.withConfig(clientConfig);
@@ -1400,6 +1403,11 @@ public ClientConfig getDefaultClientConfig() {
14001403
clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
14011404
// turn off compliance validation to be able to send payloads with DELETE calls
14021405
clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
1406+
applyDebugSetting(clientConfig);
1407+
return clientConfig;
1408+
}
1409+
1410+
private void applyDebugSetting(ClientConfig clientConfig) {
14031411
if (debugging) {
14041412
clientConfig.register(new LoggingFeature(java.util.logging.Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), java.util.logging.Level.INFO, LoggingFeature.Verbosity.PAYLOAD_ANY, 1024*50 /* Log payloads up to 50K */));
14051413
clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);
@@ -1409,8 +1417,6 @@ public ClientConfig getDefaultClientConfig() {
14091417
// suppress warnings for payloads with DELETE calls:
14101418
java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE);
14111419
}
1412-
1413-
return clientConfig;
14141420
}
14151421

14161422
/**
@@ -1502,4 +1508,4 @@ protected void updateParamsForAuth(String[] authNames, List<Pair> queryParams, M
15021508
auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri);
15031509
}
15041510
}
1505-
}
1511+
}

0 commit comments

Comments
 (0)