Skip to content

Commit 7c64073

Browse files
committed
Do not reinitialize ClientConfig with default values when building HTTP Client
1 parent 9374dbd commit 7c64073

146 files changed

Lines changed: 6884 additions & 40 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.

modules/openapi-generator/src/main/resources/Java/libraries/jersey2/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-
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
/**

samples/client/others/java/jersey2-oneOf-Mixed/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-
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
/**

samples/client/others/java/jersey2-oneOf-duplicates/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-
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
/**

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

Lines changed: 10 additions & 4 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
/**

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

Lines changed: 10 additions & 4 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
/**

samples/openapi3/client/extensions/x-auth-id-alias/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ public boolean isDebugging() {
522522
*/
523523
public ApiClient setDebugging(boolean debugging) {
524524
this.debugging = debugging;
525+
applyDebugSetting(this.clientConfig);
525526
// Rebuild HTTP Client according to the new "debugging" value.
526527
this.httpClient = buildHttpClient();
527528
return this;
@@ -1188,8 +1189,10 @@ public <T> ApiResponse<T> invokeAPI(String path, String method, List<Pair> query
11881189
* @return Client
11891190
*/
11901191
protected Client buildHttpClient() {
1191-
// recreate the client config to pickup changes
1192-
clientConfig = getDefaultClientConfig();
1192+
// Create ClientConfig if it has not been initialized yet
1193+
if (clientConfig == null) {
1194+
clientConfig = getDefaultClientConfig();
1195+
}
11931196

11941197
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
11951198
clientBuilder = clientBuilder.withConfig(clientConfig);
@@ -1210,6 +1213,11 @@ public ClientConfig getDefaultClientConfig() {
12101213
clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
12111214
// turn off compliance validation to be able to send payloads with DELETE calls
12121215
clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
1216+
applyDebugSetting(clientConfig);
1217+
return clientConfig;
1218+
}
1219+
1220+
private void applyDebugSetting(ClientConfig clientConfig) {
12131221
if (debugging) {
12141222
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 */));
12151223
clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);
@@ -1219,8 +1227,6 @@ public ClientConfig getDefaultClientConfig() {
12191227
// suppress warnings for payloads with DELETE calls:
12201228
java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE);
12211229
}
1222-
1223-
return clientConfig;
12241230
}
12251231

12261232
/**

samples/openapi3/client/petstore/java/jersey2-java8-special-characters/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-
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
/**

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ public boolean isDebugging() {
598598
*/
599599
public ApiClient setDebugging(boolean debugging) {
600600
this.debugging = debugging;
601+
applyDebugSetting(this.clientConfig);
601602
// Rebuild HTTP Client according to the new "debugging" value.
602603
this.httpClient = buildHttpClient();
603604
return this;
@@ -1280,8 +1281,10 @@ public <T> ApiResponse<T> invokeAPI(String path, String method, List<Pair> query
12801281
* @return Client
12811282
*/
12821283
protected Client buildHttpClient() {
1283-
// recreate the client config to pickup changes
1284-
clientConfig = getDefaultClientConfig();
1284+
// Create ClientConfig if it has not been initialized yet
1285+
if (clientConfig == null) {
1286+
clientConfig = getDefaultClientConfig();
1287+
}
12851288

12861289
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
12871290
clientBuilder = clientBuilder.withConfig(clientConfig);
@@ -1302,6 +1305,11 @@ public ClientConfig getDefaultClientConfig() {
13021305
clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
13031306
// turn off compliance validation to be able to send payloads with DELETE calls
13041307
clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
1308+
applyDebugSetting(clientConfig);
1309+
return clientConfig;
1310+
}
1311+
1312+
private void applyDebugSetting(ClientConfig clientConfig) {
13051313
if (debugging) {
13061314
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 */));
13071315
clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);
@@ -1311,8 +1319,6 @@ public ClientConfig getDefaultClientConfig() {
13111319
// suppress warnings for payloads with DELETE calls:
13121320
java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE);
13131321
}
1314-
1315-
return clientConfig;
13161322
}
13171323

13181324
/**

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ public boolean isDebugging() {
598598
*/
599599
public ApiClient setDebugging(boolean debugging) {
600600
this.debugging = debugging;
601+
applyDebugSetting(this.clientConfig);
601602
// Rebuild HTTP Client according to the new "debugging" value.
602603
this.httpClient = buildHttpClient();
603604
return this;
@@ -1280,8 +1281,10 @@ public <T> ApiResponse<T> invokeAPI(String path, String method, List<Pair> query
12801281
* @return Client
12811282
*/
12821283
protected Client buildHttpClient() {
1283-
// recreate the client config to pickup changes
1284-
clientConfig = getDefaultClientConfig();
1284+
// Create ClientConfig if it has not been initialized yet
1285+
if (clientConfig == null) {
1286+
clientConfig = getDefaultClientConfig();
1287+
}
12851288

12861289
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
12871290
clientBuilder = clientBuilder.withConfig(clientConfig);
@@ -1302,6 +1305,11 @@ public ClientConfig getDefaultClientConfig() {
13021305
clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
13031306
// turn off compliance validation to be able to send payloads with DELETE calls
13041307
clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
1308+
applyDebugSetting(clientConfig);
1309+
return clientConfig;
1310+
}
1311+
1312+
private void applyDebugSetting(ClientConfig clientConfig) {
13051313
if (debugging) {
13061314
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 */));
13071315
clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY);
@@ -1311,8 +1319,6 @@ public ClientConfig getDefaultClientConfig() {
13111319
// suppress warnings for payloads with DELETE calls:
13121320
java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE);
13131321
}
1314-
1315-
return clientConfig;
13161322
}
13171323

13181324
/**

0 commit comments

Comments
 (0)