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
This commit is contained in:
jheyens
2025-04-23 09:24:22 +02:00
committed by GitHub
parent 346231083f
commit a66dd20783
13 changed files with 140 additions and 62 deletions

View File

@@ -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);
}
}
}
}