io.quarkus.resteasy.runtime.standalone.ResteasyConfigurationMPConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-resteasy Show documentation
Show all versions of quarkus-resteasy Show documentation
REST endpoint framework implementing JAX-RS and more
package io.quarkus.resteasy.runtime.standalone;
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
*
*/
public class ResteasyConfigurationMPConfig implements ResteasyConfiguration {
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) {
return null;
}
Optional value = Optional.empty();
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
return value.or(() -> config.getOptionalValue(name, String.class))
.orElse(null);
}
@Override
public Set getParameterNames() {
Config config = ConfigProvider.getConfig();
if (config == null) {
return Set.of();
}
HashSet set = new HashSet<>();
for (String name : config.getPropertyNames()) {
set.add(name);
}
set.addAll(RESTEASY_QUARKUS_MAPPING_PARAMS.keySet());
return set;
}
@Override
public String getInitParameter(String name) {
return getParameter(name);
}
@Override
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()));
}
}