From 47bcd5c0faaf7a4f315f6afa1b5f63d2e8c664a5 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Tue, 2 Apr 2024 12:04:28 +0200 Subject: [PATCH] Properly convert MemorySize to RESTEasy configuration Some part of RESTEasy are using ResteasyConfigurationMPConfig to map the config and we were incorrectly pushing the raw string for quarkus.resteasy.gzip.max-input. Fixes #39636 --- .../ResteasyConfigurationMPConfig.java | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/extensions/resteasy-classic/resteasy/runtime/src/main/java/io/quarkus/resteasy/runtime/standalone/ResteasyConfigurationMPConfig.java b/extensions/resteasy-classic/resteasy/runtime/src/main/java/io/quarkus/resteasy/runtime/standalone/ResteasyConfigurationMPConfig.java index d11e7146f7093..bdf70a82a1603 100644 --- a/extensions/resteasy-classic/resteasy/runtime/src/main/java/io/quarkus/resteasy/runtime/standalone/ResteasyConfigurationMPConfig.java +++ b/extensions/resteasy-classic/resteasy/runtime/src/main/java/io/quarkus/resteasy/runtime/standalone/ResteasyConfigurationMPConfig.java @@ -1,35 +1,39 @@ package io.quarkus.resteasy.runtime.standalone; -import java.util.Collections; import java.util.HashSet; import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.function.Function; import org.eclipse.microprofile.config.Config; import org.eclipse.microprofile.config.ConfigProvider; import org.jboss.resteasy.plugins.server.servlet.ResteasyContextParameters; import org.jboss.resteasy.spi.ResteasyConfiguration; +import io.quarkus.runtime.configuration.MemorySize; + /** - * Some resteasy components use this class for configuration. This bridges MP Config to ResteasyConfiguration + * Some RESTEasy components use this class for configuration. This bridges MP Config to ResteasyConfiguration * */ public class ResteasyConfigurationMPConfig implements ResteasyConfiguration { - private static final Map RESTEASY_QUARKUS_MAPPING_PARAMS = Map.of( - ResteasyContextParameters.RESTEASY_GZIP_MAX_INPUT, "quarkus.resteasy.gzip.max-input"); + private static final Map>> RESTEASY_QUARKUS_MAPPING_PARAMS = Map.of( + ResteasyContextParameters.RESTEASY_GZIP_MAX_INPUT, ResteasyConfigurationMPConfig::getGzipMaxInput); @Override public String getParameter(String name) { Config config = ConfigProvider.getConfig(); - if (config == null) + if (config == null) { return null; + } + Optional value = Optional.empty(); - String mappedProperty = RESTEASY_QUARKUS_MAPPING_PARAMS.get(name); - if (mappedProperty != null) { - // try to use quarkus parameter - value = config.getOptionalValue(mappedProperty, String.class); + Function> mappingFunction = RESTEASY_QUARKUS_MAPPING_PARAMS.get(name); + if (mappingFunction != null) { + // try to use Quarkus configuration + value = mappingFunction.apply(config); } // if the parameter name is not mapped or there is no value, use the parameter name as provided @@ -40,12 +44,15 @@ public String getParameter(String name) { @Override public Set getParameterNames() { Config config = ConfigProvider.getConfig(); - if (config == null) - return Collections.EMPTY_SET; + if (config == null) { + return Set.of(); + } HashSet set = new HashSet<>(); - for (String name : config.getPropertyNames()) + for (String name : config.getPropertyNames()) { set.add(name); + } set.addAll(RESTEASY_QUARKUS_MAPPING_PARAMS.keySet()); + return set; } @@ -58,4 +65,14 @@ public String getInitParameter(String name) { public Set getInitParameterNames() { return getParameterNames(); } + + private static Optional getGzipMaxInput(Config config) { + Optional rawValue = config.getOptionalValue("quarkus.resteasy.gzip.max-input", MemorySize.class); + + if (rawValue.isEmpty()) { + return Optional.empty(); + } + + return Optional.of(Long.toString(rawValue.get().asLongValue())); + } }