Skip to content

Commit 02dda9d

Browse files
authored
Merge pull request #45788 from IvanPetkov23/feature/resteasy-classic
Convert resteasy-classic to use @ConfigMapping
2 parents f00a574 + c7e75c3 commit 02dda9d

File tree

13 files changed

+68
-73
lines changed

13 files changed

+68
-73
lines changed

extensions/resteasy-classic/resteasy-common/deployment/pom.xml

-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@
4646
<version>${project.version}</version>
4747
</path>
4848
</annotationProcessorPaths>
49-
<compilerArgs>
50-
<arg>-AlegacyConfigRoot=true</arg>
51-
</compilerArgs>
5249
</configuration>
5350
</execution>
5451
</executions>

extensions/resteasy-classic/resteasy-common/deployment/src/main/java/io/quarkus/resteasy/common/deployment/ResteasyCommonProcessor.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void addStaticInitConfigSourceProvider(
120120

121121
@BuildStep
122122
ResteasyConfigBuildItem resteasyConfig(ResteasyJsonConfig resteasyJsonConfig, Capabilities capabilities) {
123-
return new ResteasyConfigBuildItem(resteasyJsonConfig.jsonDefault &&
123+
return new ResteasyConfigBuildItem(resteasyJsonConfig.jsonDefault() &&
124124
// RESTEASY_JACKSON or RESTEASY_JACKSON_CLIENT
125125
(capabilities.isCapabilityWithPrefixPresent(Capability.RESTEASY_JSON_JACKSON)
126126
// RESTEASY_JSONB or RESTEASY_JSONB_CLIENT
@@ -306,15 +306,15 @@ void registerJsonContextResolvers(CombinedIndexBuildItem combinedIndexBuildItem,
306306
if (capabilities.isCapabilityWithPrefixPresent(Capability.RESTEASY_JSON_JACKSON)) {
307307
registerJsonContextResolver(OBJECT_MAPPER, QUARKUS_OBJECT_MAPPER_CONTEXT_RESOLVER, combinedIndexBuildItem,
308308
jaxrsProvider, additionalBean, unremovable);
309-
if (resteasyJsonConfig.jsonDefault) {
309+
if (resteasyJsonConfig.jsonDefault()) {
310310
jaxrsProvider.produce(new ResteasyJaxrsProviderBuildItem(QUARKUS_JACKSON_SERIALIZER.toString()));
311311
}
312312
}
313313

314314
if (capabilities.isCapabilityWithPrefixPresent(Capability.RESTEASY_JSON_JSONB)) {
315315
registerJsonContextResolver(JSONB, QUARKUS_JSONB_CONTEXT_RESOLVER, combinedIndexBuildItem, jaxrsProvider,
316316
additionalBean, unremovable);
317-
if (resteasyJsonConfig.jsonDefault) {
317+
if (resteasyJsonConfig.jsonDefault()) {
318318
jaxrsProvider.produce(new ResteasyJaxrsProviderBuildItem(QUARKUS_JSONB_SERIALIZER.toString()));
319319
}
320320
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package io.quarkus.resteasy.common.deployment;
22

3-
import io.quarkus.runtime.annotations.ConfigItem;
43
import io.quarkus.runtime.annotations.ConfigPhase;
54
import io.quarkus.runtime.annotations.ConfigRoot;
5+
import io.smallrye.config.ConfigMapping;
6+
import io.smallrye.config.WithDefault;
67

78
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
8-
public class ResteasyJsonConfig {
9+
@ConfigMapping(prefix = "quarkus.resteasy-json")
10+
public interface ResteasyJsonConfig {
911

1012
/**
1113
* If this is true (the default) then JSON is set to the default media type. If a method has no
@@ -15,6 +17,6 @@ public class ResteasyJsonConfig {
1517
* Note that this will only take effect if a JSON provider has been installed, such as quarkus-resteasy-jsonb
1618
* or quarkus-resteasy-jackson.
1719
*/
18-
@ConfigItem(defaultValue = "true")
19-
public boolean jsonDefault;
20+
@WithDefault("true")
21+
boolean jsonDefault();
2022
}

extensions/resteasy-classic/resteasy-multipart/runtime/pom.xml

-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@
7878
<version>${project.version}</version>
7979
</path>
8080
</annotationProcessorPaths>
81-
<compilerArgs>
82-
<arg>-AlegacyConfigRoot=true</arg>
83-
</compilerArgs>
8481
</configuration>
8582
</execution>
8683
</executions>

extensions/resteasy-classic/resteasy-multipart/runtime/src/main/java/io/quarkus/resteasy/multipart/runtime/MultipartInputPartConfigContainerRequestFilter.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package io.quarkus.resteasy.multipart.runtime;
22

3-
import java.io.IOException;
4-
53
import jakarta.enterprise.inject.Instance;
64
import jakarta.inject.Inject;
75
import jakarta.ws.rs.container.ContainerRequestContext;
@@ -20,12 +18,12 @@ public class MultipartInputPartConfigContainerRequestFilter implements Container
2018
Instance<ResteasyMultipartRuntimeConfig> resteasyMultipartConfigInstance;
2119

2220
@Override
23-
public void filter(ContainerRequestContext requestContext) throws IOException {
21+
public void filter(ContainerRequestContext requestContext) {
2422
ResteasyMultipartRuntimeConfig resteasyMultipartConfig = resteasyMultipartConfigInstance.get();
2523

2624
requestContext.setProperty(InputPart.DEFAULT_CHARSET_PROPERTY,
27-
resteasyMultipartConfig.inputPart.defaultCharset.name());
25+
resteasyMultipartConfig.inputPart().defaultCharset().name());
2826
requestContext.setProperty(InputPart.DEFAULT_CONTENT_TYPE_PROPERTY,
29-
resteasyMultipartConfig.inputPart.defaultContentType);
27+
resteasyMultipartConfig.inputPart().defaultContentType());
3028
}
3129
}

extensions/resteasy-classic/resteasy-multipart/runtime/src/main/java/io/quarkus/resteasy/multipart/runtime/ResteasyMultipartRuntimeConfig.java

+11-10
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,35 @@
33
import java.nio.charset.Charset;
44

55
import io.quarkus.runtime.annotations.ConfigGroup;
6-
import io.quarkus.runtime.annotations.ConfigItem;
76
import io.quarkus.runtime.annotations.ConfigPhase;
87
import io.quarkus.runtime.annotations.ConfigRoot;
8+
import io.smallrye.config.ConfigMapping;
9+
import io.smallrye.config.WithDefault;
910

10-
@ConfigRoot(name = "resteasy.multipart", phase = ConfigPhase.RUN_TIME)
11-
public class ResteasyMultipartRuntimeConfig {
11+
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
12+
@ConfigMapping(prefix = "quarkus.resteasy.multipart")
13+
public interface ResteasyMultipartRuntimeConfig {
1214

1315
/**
1416
* Input part configuration.
1517
*/
16-
@ConfigItem
17-
public InputPartConfigGroup inputPart;
18+
InputPartConfigGroup inputPart();
1819

1920
@ConfigGroup
20-
public static class InputPartConfigGroup {
21+
interface InputPartConfigGroup {
2122

2223
/**
2324
* Default charset.
2425
* <p>
2526
* Note that the default value is UTF-8 which is different from RESTEasy's default value US-ASCII.
2627
*/
27-
@ConfigItem(defaultValue = "UTF-8")
28-
public Charset defaultCharset;
28+
@WithDefault("UTF-8")
29+
Charset defaultCharset();
2930

3031
/**
3132
* The default content-type.
3233
*/
33-
@ConfigItem(defaultValue = "text/plain")
34-
public String defaultContentType;
34+
@WithDefault("text/plain")
35+
String defaultContentType();
3536
}
3637
}

extensions/resteasy-classic/resteasy-server-common/deployment/pom.xml

-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@
5858
<version>${project.version}</version>
5959
</path>
6060
</annotationProcessorPaths>
61-
<compilerArgs>
62-
<arg>-AlegacyConfigRoot=true</arg>
63-
</compilerArgs>
6461
</configuration>
6562
</execution>
6663
</executions>

extensions/resteasy-classic/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java

+24-21
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,12 @@
8484
import io.quarkus.resteasy.server.common.spi.AdditionalJaxRsResourceDefiningAnnotationBuildItem;
8585
import io.quarkus.resteasy.server.common.spi.AdditionalJaxRsResourceMethodParamAnnotations;
8686
import io.quarkus.resteasy.server.common.spi.AllowedJaxRsAnnotationPrefixBuildItem;
87-
import io.quarkus.runtime.annotations.ConfigItem;
8887
import io.quarkus.runtime.annotations.ConfigRoot;
89-
import io.quarkus.runtime.annotations.ConvertWith;
9088
import io.quarkus.runtime.configuration.NormalizeRootHttpPathConverter;
89+
import io.smallrye.config.ConfigMapping;
90+
import io.smallrye.config.WithConverter;
91+
import io.smallrye.config.WithDefault;
92+
import io.smallrye.config.WithName;
9193

9294
/**
9395
* Processor that builds the RESTEasy server configuration.
@@ -125,7 +127,8 @@ public class ResteasyServerCommonProcessor {
125127
ResteasyCommonConfig commonConfig;
126128

127129
@ConfigRoot(phase = BUILD_TIME)
128-
static final class ResteasyConfig {
130+
@ConfigMapping(prefix = "quarkus.resteasy")
131+
interface ResteasyConfig {
129132
/**
130133
* If this is true then JAX-RS will use only a single instance of a resource
131134
* class to service all requests.
@@ -142,8 +145,8 @@ static final class ResteasyConfig {
142145
* a stereotype which has a different default scope the deployment fails with
143146
* IllegalStateException.
144147
*/
145-
@ConfigItem(defaultValue = "true")
146-
boolean singletonResources;
148+
@WithDefault("true")
149+
boolean singletonResources();
147150

148151
/**
149152
* Set this to override the default path for JAX-RS resources if there are no
@@ -156,9 +159,9 @@ static final class ResteasyConfig {
156159
* be {@literal /foo/bar}</li>
157160
* </ul>
158161
*/
159-
@ConfigItem(defaultValue = "/")
160-
@ConvertWith(NormalizeRootHttpPathConverter.class)
161-
String path;
162+
@WithDefault("/")
163+
@WithConverter(NormalizeRootHttpPathConverter.class)
164+
String path();
162165

163166
/**
164167
* Whether detailed JAX-RS metrics should be enabled if the smallrye-metrics
@@ -171,22 +174,22 @@ static final class ResteasyConfig {
171174
* @deprecated Use {@code quarkus.smallrye-metrics.jaxrs.enabled} instead.
172175
*/
173176
@Deprecated(forRemoval = true)
174-
@ConfigItem(name = "metrics.enabled")
175-
public Optional<Boolean> metricsEnabled;
177+
@WithName("metrics.enabled")
178+
Optional<Boolean> metricsEnabled();
176179

177180
/**
178181
* Ignore all explicit JAX-RS {@link Application} classes.
179182
* As multiple JAX-RS applications are not supported, this can be used to effectively merge all JAX-RS applications.
180183
*/
181-
@ConfigItem(defaultValue = "false")
182-
boolean ignoreApplicationClasses;
184+
@WithDefault("false")
185+
boolean ignoreApplicationClasses();
183186

184187
/**
185188
* Whether annotations such `@IfBuildTimeProfile`, `@IfBuildTimeProperty` and friends will be taken
186189
* into account when used on JAX-RS classes.
187190
*/
188-
@ConfigItem(defaultValue = "true")
189-
boolean buildTimeConditionAware;
191+
@WithDefault("true")
192+
boolean buildTimeConditionAware();
190193
}
191194

192195
@BuildStep
@@ -224,14 +227,14 @@ public void build(
224227

225228
final AnnotationInstance applicationPath;
226229
final Set<String> excludedClasses;
227-
if (resteasyConfig.buildTimeConditionAware) {
230+
if (resteasyConfig.buildTimeConditionAware()) {
228231
excludedClasses = getExcludedClasses(buildTimeConditions);
229232
} else {
230233
excludedClasses = Collections.emptySet();
231234
}
232235
final Set<String> allowedClasses;
233236
final String appClass;
234-
if (resteasyConfig.ignoreApplicationClasses) {
237+
if (resteasyConfig.ignoreApplicationClasses()) {
235238
applicationPath = null;
236239
allowedClasses = Collections.emptySet();
237240
appClass = null;
@@ -297,8 +300,8 @@ public void build(
297300
}
298301
path = rootPath;
299302
} else {
300-
rootPath = resteasyConfig.path;
301-
path = resteasyConfig.path;
303+
rootPath = resteasyConfig.path();
304+
path = resteasyConfig.path();
302305
}
303306
}
304307

@@ -514,7 +517,7 @@ public void transform(TransformationContext context) {
514517
} else if (subresources.contains(clazz.name())) {
515518
// Transform a class annotated with a request method designator
516519
Transformation transformation = context.transform()
517-
.add(resteasyConfig.singletonResources ? BuiltinScope.SINGLETON.getName()
520+
.add(resteasyConfig.singletonResources() ? BuiltinScope.SINGLETON.getName()
518521
: BuiltinScope.DEPENDENT.getName());
519522
if (clazz.declaredAnnotation(DotNames.TYPED) == null) {
520523
// Add @Typed(MySubresource.class)
@@ -620,7 +623,7 @@ private void makeResourcesAdditionalBeans(Map<DotName, ClassInfo> additionalClas
620623
BuildProducer<AdditionalBeanBuildItem> additionalBeans) {
621624
if (!additionalClassWithPath.isEmpty()) {
622625
AdditionalBeanBuildItem.Builder builder = AdditionalBeanBuildItem.builder()
623-
.setDefaultScope(resteasyConfig.singletonResources ? BuiltinScope.SINGLETON.getName() : null)
626+
.setDefaultScope(resteasyConfig.singletonResources() ? BuiltinScope.SINGLETON.getName() : null)
624627
.setUnremovable();
625628
for (Map.Entry<DotName, ClassInfo> classWithPath : additionalClassWithPath.entrySet()) {
626629
if (scopes.isScopeDeclaredOn(classWithPath.getValue())) {
@@ -641,7 +644,7 @@ private void makeResourcesAdditionalBeans(Map<DotName, ClassInfo> additionalClas
641644
void beanDefiningAnnotations(BuildProducer<BeanDefiningAnnotationBuildItem> beanDefiningAnnotations) {
642645
beanDefiningAnnotations
643646
.produce(new BeanDefiningAnnotationBuildItem(ResteasyDotNames.PATH,
644-
resteasyConfig.singletonResources ? BuiltinScope.SINGLETON.getName() : null));
647+
resteasyConfig.singletonResources() ? BuiltinScope.SINGLETON.getName() : null));
645648
beanDefiningAnnotations
646649
.produce(new BeanDefiningAnnotationBuildItem(ResteasyDotNames.APPLICATION_PATH,
647650
BuiltinScope.SINGLETON.getName()));

extensions/resteasy-classic/resteasy/deployment/src/main/java/io/quarkus/resteasy/deployment/ResteasyBuiltinsProcessor.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ public class ResteasyBuiltinsProcessor {
4141
@BuildStep
4242
void setUpDenyAllJaxRs(JaxRsSecurityConfig securityConfig,
4343
BuildProducer<DefaultSecurityCheckBuildItem> defaultSecurityCheckProducer) {
44-
if (securityConfig.denyJaxRs) {
44+
if (securityConfig.denyUnannotatedEndpoints()) {
4545
defaultSecurityCheckProducer.produce(DefaultSecurityCheckBuildItem.denyAll());
46-
} else if (securityConfig.defaultRolesAllowed.isPresent()) {
46+
} else if (securityConfig.defaultRolesAllowed().isPresent()) {
4747
defaultSecurityCheckProducer
48-
.produce(DefaultSecurityCheckBuildItem.rolesAllowed(securityConfig.defaultRolesAllowed.get()));
48+
.produce(DefaultSecurityCheckBuildItem.rolesAllowed(securityConfig.defaultRolesAllowed().get()));
4949
}
5050
}
5151

extensions/resteasy-classic/resteasy/runtime/pom.xml

-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@
6565
<version>${project.version}</version>
6666
</path>
6767
</annotationProcessorPaths>
68-
<compilerArgs>
69-
<arg>-AlegacyConfigRoot=true</arg>
70-
</compilerArgs>
7168
</configuration>
7269
</execution>
7370
</executions>

extensions/resteasy-classic/resteasy/runtime/src/main/java/io/quarkus/resteasy/runtime/JaxRsSecurityConfig.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
import java.util.List;
44
import java.util.Optional;
55

6-
import io.quarkus.runtime.annotations.ConfigItem;
76
import io.quarkus.runtime.annotations.ConfigPhase;
87
import io.quarkus.runtime.annotations.ConfigRoot;
8+
import io.smallrye.config.ConfigMapping;
9+
import io.smallrye.config.WithDefault;
910

1011
/**
1112
* @author Michal Szynkiewicz, [email protected]
1213
*/
13-
@ConfigRoot(name = "security.jaxrs", phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
14-
public class JaxRsSecurityConfig {
14+
@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
15+
@ConfigMapping(prefix = "quarkus.security.jaxrs")
16+
public interface JaxRsSecurityConfig {
1517
/**
1618
* if set to true, access to all JAX-RS resources will be denied by default
1719
*/
18-
@ConfigItem(name = "deny-unannotated-endpoints")
19-
public boolean denyJaxRs;
20+
@WithDefault("false")
21+
boolean denyUnannotatedEndpoints();
2022

2123
/**
2224
* If no security annotations are affecting a method then they will default to requiring these roles,
@@ -25,7 +27,6 @@ public class JaxRsSecurityConfig {
2527
* The role of '**' means any authenticated user, which is equivalent to the {@link io.quarkus.security.Authenticated}
2628
* annotation.
2729
*/
28-
@ConfigItem
29-
public Optional<List<String>> defaultRolesAllowed;
30+
Optional<List<String>> defaultRolesAllowed();
3031

3132
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
package io.quarkus.resteasy.runtime;
22

3-
import io.quarkus.runtime.annotations.ConfigItem;
3+
import io.quarkus.runtime.annotations.ConfigPhase;
44
import io.quarkus.runtime.annotations.ConfigRoot;
5+
import io.smallrye.config.ConfigMapping;
6+
import io.smallrye.config.WithDefault;
57

6-
@ConfigRoot(name = "resteasy.vertx")
7-
public class ResteasyVertxConfig {
8+
@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
9+
@ConfigMapping(prefix = "quarkus.resteasy.vertx")
10+
public interface ResteasyVertxConfig {
811

912
/**
1013
* The size of the output stream response buffer. If a response is larger than this and no content-length
1114
* is provided then the request will be chunked.
1215
*
1316
* Larger values may give slight performance increases for large responses, at the expense of more memory usage.
1417
*/
15-
@ConfigItem(defaultValue = "8191")
16-
public int responseBufferSize;
17-
18+
@WithDefault("8191")
19+
int responseBufferSize();
1820
}

extensions/resteasy-classic/resteasy/runtime/src/main/java/io/quarkus/resteasy/runtime/standalone/ResteasyStandaloneRecorder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public Handler<RoutingContext> vertxRequestHandler(Supplier<Vertx> vertx, Execut
9999
ResteasyVertxConfig config, HttpBuildTimeConfig httpBuildTimeConfig) {
100100
if (deployment != null) {
101101
Handler<RoutingContext> handler = new VertxRequestHandler(vertx.get(), deployment, contextPath,
102-
new ResteasyVertxAllocator(config.responseBufferSize), executor,
102+
new ResteasyVertxAllocator(config.responseBufferSize()), executor,
103103
readTimeout.getValue().readTimeout.toMillis());
104104

105105
Set<String> compressMediaTypes = httpBuildTimeConfig.compressMediaTypes.map(Set::copyOf).orElse(Set.of());
@@ -128,7 +128,7 @@ public Handler<RoutingContext> vertxFailureHandler(Supplier<Vertx> vertx, Execut
128128
// allow customization of auth failures with exception mappers; this failure handler is only
129129
// used when auth failed before RESTEasy Classic began processing the request
130130
return new VertxRequestHandler(vertx.get(), deployment, contextPath,
131-
new ResteasyVertxAllocator(config.responseBufferSize), executor,
131+
new ResteasyVertxAllocator(config.responseBufferSize()), executor,
132132
readTimeout.getValue().readTimeout.toMillis()) {
133133

134134
@Override

0 commit comments

Comments
 (0)