From a66dd207837e0c1c6cecf6f0a79cff8d4b7e1e70 Mon Sep 17 00:00:00 2001 From: jheyens Date: Wed, 23 Apr 2025 09:24:22 +0200 Subject: [PATCH] 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 --- .../Java/libraries/jersey2/ApiClient.mustache | 16 +++++++++++----- .../Java/libraries/jersey3/ApiClient.mustache | 14 ++++++++++---- .../java/org/openapitools/client/ApiClient.java | 16 +++++++++++----- .../java/org/openapitools/client/ApiClient.java | 16 +++++++++++----- .../java/org/openapitools/client/ApiClient.java | 16 +++++++++++----- .../java/org/openapitools/client/ApiClient.java | 16 +++++++++++----- .../java/org/openapitools/client/ApiClient.java | 14 ++++++++++---- .../java/org/openapitools/client/ApiClient.java | 14 ++++++++++---- .../java/org/openapitools/client/ApiClient.java | 16 +++++++++++----- .../java/org/openapitools/client/ApiClient.java | 16 +++++++++++----- .../java/org/openapitools/client/ApiClient.java | 16 +++++++++++----- .../java/org/openapitools/client/ApiClient.java | 16 +++++++++++----- .../java/org/openapitools/client/ApiClient.java | 16 +++++++++++----- 13 files changed, 140 insertions(+), 62 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache index 218f5452ce2..646fb87b260 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache @@ -694,6 +694,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { */ public ApiClient setDebugging(boolean debugging) { this.debugging = debugging; + applyDebugSetting(this.clientConfig); // Rebuild HTTP Client according to the new "debugging" value. this.httpClient = buildHttpClient(); return this; @@ -1383,8 +1384,10 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { * @return Client */ protected Client buildHttpClient() { - // recreate the client config to pickup changes - clientConfig = getDefaultClientConfig(); + // Create ClientConfig if it has not been initialized yet + if (clientConfig == null) { + clientConfig = getDefaultClientConfig(); + } ClientBuilder clientBuilder = ClientBuilder.newBuilder(); clientBuilder = clientBuilder.withConfig(clientConfig); @@ -1405,6 +1408,11 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true); // turn off compliance validation to be able to send payloads with DELETE calls clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); + applyDebugSetting(clientConfig); + return clientConfig; + } + + private void applyDebugSetting(ClientConfig clientConfig) { if (debugging) { 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 */)); clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY); @@ -1414,8 +1422,6 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { // suppress warnings for payloads with DELETE calls: java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE); } - - return clientConfig; } /** @@ -1507,4 +1513,4 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri); } } -} +} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/ApiClient.mustache index 046a9f9bc8f..e7cffd5738f 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey3/ApiClient.mustache @@ -694,6 +694,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { */ public ApiClient setDebugging(boolean debugging) { this.debugging = debugging; + applyDebugSetting(this.clientConfig); // Rebuild HTTP Client according to the new "debugging" value. this.httpClient = buildHttpClient(); return this; @@ -1383,8 +1384,10 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { * @return Client */ protected Client buildHttpClient() { - // recreate the client config to pickup changes + // Create ClientConfig if it has not been initialized yet + if (clientConfig == null) { clientConfig = getDefaultClientConfig(); + } ClientBuilder clientBuilder = ClientBuilder.newBuilder(); clientBuilder = clientBuilder.withConfig(clientConfig); @@ -1405,6 +1408,11 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true); // turn off compliance validation to be able to send payloads with DELETE calls clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); + applyDebugSetting(clientConfig); + return clientConfig; + } + + private void applyDebugSetting(ClientConfig clientConfig) { if (debugging) { 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 */)); clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY); @@ -1414,8 +1422,6 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { // suppress warnings for payloads with DELETE calls: java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE); } - - return clientConfig; } /** @@ -1507,4 +1513,4 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri); } } -} +} \ No newline at end of file diff --git a/samples/client/others/java/jersey2-oneOf-Mixed/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/others/java/jersey2-oneOf-Mixed/src/main/java/org/openapitools/client/ApiClient.java index b03ef6c6362..49d0ed5b5a8 100644 --- a/samples/client/others/java/jersey2-oneOf-Mixed/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/others/java/jersey2-oneOf-Mixed/src/main/java/org/openapitools/client/ApiClient.java @@ -473,6 +473,7 @@ public class ApiClient extends JavaTimeFormatter { */ public ApiClient setDebugging(boolean debugging) { this.debugging = debugging; + applyDebugSetting(this.clientConfig); // Rebuild HTTP Client according to the new "debugging" value. this.httpClient = buildHttpClient(); return this; @@ -1139,8 +1140,10 @@ public class ApiClient extends JavaTimeFormatter { * @return Client */ protected Client buildHttpClient() { - // recreate the client config to pickup changes - clientConfig = getDefaultClientConfig(); + // Create ClientConfig if it has not been initialized yet + if (clientConfig == null) { + clientConfig = getDefaultClientConfig(); + } ClientBuilder clientBuilder = ClientBuilder.newBuilder(); clientBuilder = clientBuilder.withConfig(clientConfig); @@ -1161,6 +1164,11 @@ public class ApiClient extends JavaTimeFormatter { clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true); // turn off compliance validation to be able to send payloads with DELETE calls clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); + applyDebugSetting(clientConfig); + return clientConfig; + } + + private void applyDebugSetting(ClientConfig clientConfig) { if (debugging) { 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 */)); clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY); @@ -1170,8 +1178,6 @@ public class ApiClient extends JavaTimeFormatter { // suppress warnings for payloads with DELETE calls: java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE); } - - return clientConfig; } /** @@ -1263,4 +1269,4 @@ public class ApiClient extends JavaTimeFormatter { auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri); } } -} +} \ No newline at end of file diff --git a/samples/client/others/java/jersey2-oneOf-duplicates/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/others/java/jersey2-oneOf-duplicates/src/main/java/org/openapitools/client/ApiClient.java index b03ef6c6362..49d0ed5b5a8 100644 --- a/samples/client/others/java/jersey2-oneOf-duplicates/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/others/java/jersey2-oneOf-duplicates/src/main/java/org/openapitools/client/ApiClient.java @@ -473,6 +473,7 @@ public class ApiClient extends JavaTimeFormatter { */ public ApiClient setDebugging(boolean debugging) { this.debugging = debugging; + applyDebugSetting(this.clientConfig); // Rebuild HTTP Client according to the new "debugging" value. this.httpClient = buildHttpClient(); return this; @@ -1139,8 +1140,10 @@ public class ApiClient extends JavaTimeFormatter { * @return Client */ protected Client buildHttpClient() { - // recreate the client config to pickup changes - clientConfig = getDefaultClientConfig(); + // Create ClientConfig if it has not been initialized yet + if (clientConfig == null) { + clientConfig = getDefaultClientConfig(); + } ClientBuilder clientBuilder = ClientBuilder.newBuilder(); clientBuilder = clientBuilder.withConfig(clientConfig); @@ -1161,6 +1164,11 @@ public class ApiClient extends JavaTimeFormatter { clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true); // turn off compliance validation to be able to send payloads with DELETE calls clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); + applyDebugSetting(clientConfig); + return clientConfig; + } + + private void applyDebugSetting(ClientConfig clientConfig) { if (debugging) { 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 */)); clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY); @@ -1170,8 +1178,6 @@ public class ApiClient extends JavaTimeFormatter { // suppress warnings for payloads with DELETE calls: java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE); } - - return clientConfig; } /** @@ -1263,4 +1269,4 @@ public class ApiClient extends JavaTimeFormatter { auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri); } } -} +} \ No newline at end of file diff --git a/samples/client/petstore/java/jersey2-java8-localdatetime/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/jersey2-java8-localdatetime/src/main/java/org/openapitools/client/ApiClient.java index 3129a103c85..96254f20438 100644 --- a/samples/client/petstore/java/jersey2-java8-localdatetime/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2-java8-localdatetime/src/main/java/org/openapitools/client/ApiClient.java @@ -614,6 +614,7 @@ public class ApiClient extends JavaTimeFormatter { */ public ApiClient setDebugging(boolean debugging) { this.debugging = debugging; + applyDebugSetting(this.clientConfig); // Rebuild HTTP Client according to the new "debugging" value. this.httpClient = buildHttpClient(); return this; @@ -1296,8 +1297,10 @@ public class ApiClient extends JavaTimeFormatter { * @return Client */ protected Client buildHttpClient() { - // recreate the client config to pickup changes - clientConfig = getDefaultClientConfig(); + // Create ClientConfig if it has not been initialized yet + if (clientConfig == null) { + clientConfig = getDefaultClientConfig(); + } ClientBuilder clientBuilder = ClientBuilder.newBuilder(); clientBuilder = clientBuilder.withConfig(clientConfig); @@ -1318,6 +1321,11 @@ public class ApiClient extends JavaTimeFormatter { clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true); // turn off compliance validation to be able to send payloads with DELETE calls clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); + applyDebugSetting(clientConfig); + return clientConfig; + } + + private void applyDebugSetting(ClientConfig clientConfig) { if (debugging) { 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 */)); clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY); @@ -1327,8 +1335,6 @@ public class ApiClient extends JavaTimeFormatter { // suppress warnings for payloads with DELETE calls: java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE); } - - return clientConfig; } /** @@ -1420,4 +1426,4 @@ public class ApiClient extends JavaTimeFormatter { auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri); } } -} +} \ No newline at end of file diff --git a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java index 3129a103c85..96254f20438 100644 --- a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java @@ -614,6 +614,7 @@ public class ApiClient extends JavaTimeFormatter { */ public ApiClient setDebugging(boolean debugging) { this.debugging = debugging; + applyDebugSetting(this.clientConfig); // Rebuild HTTP Client according to the new "debugging" value. this.httpClient = buildHttpClient(); return this; @@ -1296,8 +1297,10 @@ public class ApiClient extends JavaTimeFormatter { * @return Client */ protected Client buildHttpClient() { - // recreate the client config to pickup changes - clientConfig = getDefaultClientConfig(); + // Create ClientConfig if it has not been initialized yet + if (clientConfig == null) { + clientConfig = getDefaultClientConfig(); + } ClientBuilder clientBuilder = ClientBuilder.newBuilder(); clientBuilder = clientBuilder.withConfig(clientConfig); @@ -1318,6 +1321,11 @@ public class ApiClient extends JavaTimeFormatter { clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true); // turn off compliance validation to be able to send payloads with DELETE calls clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); + applyDebugSetting(clientConfig); + return clientConfig; + } + + private void applyDebugSetting(ClientConfig clientConfig) { if (debugging) { 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 */)); clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY); @@ -1327,8 +1335,6 @@ public class ApiClient extends JavaTimeFormatter { // suppress warnings for payloads with DELETE calls: java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE); } - - return clientConfig; } /** @@ -1420,4 +1426,4 @@ public class ApiClient extends JavaTimeFormatter { auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri); } } -} +} \ No newline at end of file diff --git a/samples/client/petstore/java/jersey3-oneOf/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/jersey3-oneOf/src/main/java/org/openapitools/client/ApiClient.java index 5e6d65d6344..91574d13337 100644 --- a/samples/client/petstore/java/jersey3-oneOf/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/jersey3-oneOf/src/main/java/org/openapitools/client/ApiClient.java @@ -473,6 +473,7 @@ public class ApiClient extends JavaTimeFormatter { */ public ApiClient setDebugging(boolean debugging) { this.debugging = debugging; + applyDebugSetting(this.clientConfig); // Rebuild HTTP Client according to the new "debugging" value. this.httpClient = buildHttpClient(); return this; @@ -1139,8 +1140,10 @@ public class ApiClient extends JavaTimeFormatter { * @return Client */ protected Client buildHttpClient() { - // recreate the client config to pickup changes + // Create ClientConfig if it has not been initialized yet + if (clientConfig == null) { clientConfig = getDefaultClientConfig(); + } ClientBuilder clientBuilder = ClientBuilder.newBuilder(); clientBuilder = clientBuilder.withConfig(clientConfig); @@ -1161,6 +1164,11 @@ public class ApiClient extends JavaTimeFormatter { clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true); // turn off compliance validation to be able to send payloads with DELETE calls clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); + applyDebugSetting(clientConfig); + return clientConfig; + } + + private void applyDebugSetting(ClientConfig clientConfig) { if (debugging) { 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 */)); clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY); @@ -1170,8 +1178,6 @@ public class ApiClient extends JavaTimeFormatter { // suppress warnings for payloads with DELETE calls: java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE); } - - return clientConfig; } /** @@ -1263,4 +1269,4 @@ public class ApiClient extends JavaTimeFormatter { auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri); } } -} +} \ No newline at end of file diff --git a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/ApiClient.java index efb7cda085e..c729df4f014 100644 --- a/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/jersey3/src/main/java/org/openapitools/client/ApiClient.java @@ -696,6 +696,7 @@ public class ApiClient extends JavaTimeFormatter { */ public ApiClient setDebugging(boolean debugging) { this.debugging = debugging; + applyDebugSetting(this.clientConfig); // Rebuild HTTP Client according to the new "debugging" value. this.httpClient = buildHttpClient(); return this; @@ -1378,8 +1379,10 @@ public class ApiClient extends JavaTimeFormatter { * @return Client */ protected Client buildHttpClient() { - // recreate the client config to pickup changes + // Create ClientConfig if it has not been initialized yet + if (clientConfig == null) { clientConfig = getDefaultClientConfig(); + } ClientBuilder clientBuilder = ClientBuilder.newBuilder(); clientBuilder = clientBuilder.withConfig(clientConfig); @@ -1400,6 +1403,11 @@ public class ApiClient extends JavaTimeFormatter { clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true); // turn off compliance validation to be able to send payloads with DELETE calls clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); + applyDebugSetting(clientConfig); + return clientConfig; + } + + private void applyDebugSetting(ClientConfig clientConfig) { if (debugging) { 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 */)); clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY); @@ -1409,8 +1417,6 @@ public class ApiClient extends JavaTimeFormatter { // suppress warnings for payloads with DELETE calls: java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE); } - - return clientConfig; } /** @@ -1502,4 +1508,4 @@ public class ApiClient extends JavaTimeFormatter { auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri); } } -} +} \ No newline at end of file diff --git a/samples/openapi3/client/extensions/x-auth-id-alias/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java b/samples/openapi3/client/extensions/x-auth-id-alias/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java index e4f654dc04b..5ff46154865 100644 --- a/samples/openapi3/client/extensions/x-auth-id-alias/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/openapi3/client/extensions/x-auth-id-alias/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java @@ -522,6 +522,7 @@ public class ApiClient extends JavaTimeFormatter { */ public ApiClient setDebugging(boolean debugging) { this.debugging = debugging; + applyDebugSetting(this.clientConfig); // Rebuild HTTP Client according to the new "debugging" value. this.httpClient = buildHttpClient(); return this; @@ -1188,8 +1189,10 @@ public class ApiClient extends JavaTimeFormatter { * @return Client */ protected Client buildHttpClient() { - // recreate the client config to pickup changes - clientConfig = getDefaultClientConfig(); + // Create ClientConfig if it has not been initialized yet + if (clientConfig == null) { + clientConfig = getDefaultClientConfig(); + } ClientBuilder clientBuilder = ClientBuilder.newBuilder(); clientBuilder = clientBuilder.withConfig(clientConfig); @@ -1210,6 +1213,11 @@ public class ApiClient extends JavaTimeFormatter { clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true); // turn off compliance validation to be able to send payloads with DELETE calls clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); + applyDebugSetting(clientConfig); + return clientConfig; + } + + private void applyDebugSetting(ClientConfig clientConfig) { if (debugging) { 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 */)); clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY); @@ -1219,8 +1227,6 @@ public class ApiClient extends JavaTimeFormatter { // suppress warnings for payloads with DELETE calls: java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE); } - - return clientConfig; } /** @@ -1312,4 +1318,4 @@ public class ApiClient extends JavaTimeFormatter { auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri); } } -} +} \ No newline at end of file diff --git a/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/src/main/java/org/openapitools/client/ApiClient.java b/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/src/main/java/org/openapitools/client/ApiClient.java index 2b0c723159f..ac1c71efcb3 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/src/main/java/org/openapitools/client/ApiClient.java @@ -473,6 +473,7 @@ public class ApiClient extends JavaTimeFormatter { */ public ApiClient setDebugging(boolean debugging) { this.debugging = debugging; + applyDebugSetting(this.clientConfig); // Rebuild HTTP Client according to the new "debugging" value. this.httpClient = buildHttpClient(); return this; @@ -1139,8 +1140,10 @@ public class ApiClient extends JavaTimeFormatter { * @return Client */ protected Client buildHttpClient() { - // recreate the client config to pickup changes - clientConfig = getDefaultClientConfig(); + // Create ClientConfig if it has not been initialized yet + if (clientConfig == null) { + clientConfig = getDefaultClientConfig(); + } ClientBuilder clientBuilder = ClientBuilder.newBuilder(); clientBuilder = clientBuilder.withConfig(clientConfig); @@ -1161,6 +1164,11 @@ public class ApiClient extends JavaTimeFormatter { clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true); // turn off compliance validation to be able to send payloads with DELETE calls clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); + applyDebugSetting(clientConfig); + return clientConfig; + } + + private void applyDebugSetting(ClientConfig clientConfig) { if (debugging) { 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 */)); clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY); @@ -1170,8 +1178,6 @@ public class ApiClient extends JavaTimeFormatter { // suppress warnings for payloads with DELETE calls: java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE); } - - return clientConfig; } /** @@ -1263,4 +1269,4 @@ public class ApiClient extends JavaTimeFormatter { auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri); } } -} +} \ No newline at end of file diff --git a/samples/openapi3/client/petstore/java/jersey2-java8-swagger1/src/main/java/org/openapitools/client/ApiClient.java b/samples/openapi3/client/petstore/java/jersey2-java8-swagger1/src/main/java/org/openapitools/client/ApiClient.java index 17d9353fd64..983f809a0f6 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8-swagger1/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8-swagger1/src/main/java/org/openapitools/client/ApiClient.java @@ -598,6 +598,7 @@ public class ApiClient extends JavaTimeFormatter { */ public ApiClient setDebugging(boolean debugging) { this.debugging = debugging; + applyDebugSetting(this.clientConfig); // Rebuild HTTP Client according to the new "debugging" value. this.httpClient = buildHttpClient(); return this; @@ -1280,8 +1281,10 @@ public class ApiClient extends JavaTimeFormatter { * @return Client */ protected Client buildHttpClient() { - // recreate the client config to pickup changes - clientConfig = getDefaultClientConfig(); + // Create ClientConfig if it has not been initialized yet + if (clientConfig == null) { + clientConfig = getDefaultClientConfig(); + } ClientBuilder clientBuilder = ClientBuilder.newBuilder(); clientBuilder = clientBuilder.withConfig(clientConfig); @@ -1302,6 +1305,11 @@ public class ApiClient extends JavaTimeFormatter { clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true); // turn off compliance validation to be able to send payloads with DELETE calls clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); + applyDebugSetting(clientConfig); + return clientConfig; + } + + private void applyDebugSetting(ClientConfig clientConfig) { if (debugging) { 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 */)); clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY); @@ -1311,8 +1319,6 @@ public class ApiClient extends JavaTimeFormatter { // suppress warnings for payloads with DELETE calls: java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE); } - - return clientConfig; } /** @@ -1404,4 +1410,4 @@ public class ApiClient extends JavaTimeFormatter { auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri); } } -} +} \ No newline at end of file diff --git a/samples/openapi3/client/petstore/java/jersey2-java8-swagger2/src/main/java/org/openapitools/client/ApiClient.java b/samples/openapi3/client/petstore/java/jersey2-java8-swagger2/src/main/java/org/openapitools/client/ApiClient.java index 17d9353fd64..983f809a0f6 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8-swagger2/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8-swagger2/src/main/java/org/openapitools/client/ApiClient.java @@ -598,6 +598,7 @@ public class ApiClient extends JavaTimeFormatter { */ public ApiClient setDebugging(boolean debugging) { this.debugging = debugging; + applyDebugSetting(this.clientConfig); // Rebuild HTTP Client according to the new "debugging" value. this.httpClient = buildHttpClient(); return this; @@ -1280,8 +1281,10 @@ public class ApiClient extends JavaTimeFormatter { * @return Client */ protected Client buildHttpClient() { - // recreate the client config to pickup changes - clientConfig = getDefaultClientConfig(); + // Create ClientConfig if it has not been initialized yet + if (clientConfig == null) { + clientConfig = getDefaultClientConfig(); + } ClientBuilder clientBuilder = ClientBuilder.newBuilder(); clientBuilder = clientBuilder.withConfig(clientConfig); @@ -1302,6 +1305,11 @@ public class ApiClient extends JavaTimeFormatter { clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true); // turn off compliance validation to be able to send payloads with DELETE calls clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); + applyDebugSetting(clientConfig); + return clientConfig; + } + + private void applyDebugSetting(ClientConfig clientConfig) { if (debugging) { 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 */)); clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY); @@ -1311,8 +1319,6 @@ public class ApiClient extends JavaTimeFormatter { // suppress warnings for payloads with DELETE calls: java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE); } - - return clientConfig; } /** @@ -1404,4 +1410,4 @@ public class ApiClient extends JavaTimeFormatter { auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri); } } -} +} \ No newline at end of file diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java index 60d1dd07ae8..4447de0f8c9 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java @@ -696,6 +696,7 @@ public class ApiClient extends JavaTimeFormatter { */ public ApiClient setDebugging(boolean debugging) { this.debugging = debugging; + applyDebugSetting(this.clientConfig); // Rebuild HTTP Client according to the new "debugging" value. this.httpClient = buildHttpClient(); return this; @@ -1378,8 +1379,10 @@ public class ApiClient extends JavaTimeFormatter { * @return Client */ protected Client buildHttpClient() { - // recreate the client config to pickup changes - clientConfig = getDefaultClientConfig(); + // Create ClientConfig if it has not been initialized yet + if (clientConfig == null) { + clientConfig = getDefaultClientConfig(); + } ClientBuilder clientBuilder = ClientBuilder.newBuilder(); clientBuilder = clientBuilder.withConfig(clientConfig); @@ -1400,6 +1403,11 @@ public class ApiClient extends JavaTimeFormatter { clientConfig.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true); // turn off compliance validation to be able to send payloads with DELETE calls clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); + applyDebugSetting(clientConfig); + return clientConfig; + } + + private void applyDebugSetting(ClientConfig clientConfig) { if (debugging) { 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 */)); clientConfig.property(LoggingFeature.LOGGING_FEATURE_VERBOSITY, LoggingFeature.Verbosity.PAYLOAD_ANY); @@ -1409,8 +1417,6 @@ public class ApiClient extends JavaTimeFormatter { // suppress warnings for payloads with DELETE calls: java.util.logging.Logger.getLogger("org.glassfish.jersey.client").setLevel(java.util.logging.Level.SEVERE); } - - return clientConfig; } /** @@ -1502,4 +1508,4 @@ public class ApiClient extends JavaTimeFormatter { auth.applyToParams(queryParams, headerParams, cookieParams, payload, method, uri); } } -} +} \ No newline at end of file