Skip to content

Commit 7fbe085

Browse files
authored
Issue #6002 | Ignore warnings for get method consumes entity (#6015)
1 parent e4f5745 commit 7fbe085

File tree

5 files changed

+53
-9
lines changed

5 files changed

+53
-9
lines changed

core-server/src/main/java/org/glassfish/jersey/server/ApplicationHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2021 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2025 Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2018 Payara Foundation and/or its affiliates.
44
*
55
* This program and the accompanying materials are made available under the
@@ -366,7 +366,7 @@ private ServerRuntime initialize(InjectionManager injectionManager, List<Bootstr
366366

367367
if (!disableValidation()) {
368368
ComponentModelValidator validator = new ComponentModelValidator(
369-
bootstrapBag.getValueParamProviders(), bootstrapBag.getMessageBodyWorkers());
369+
bootstrapBag.getValueParamProviders(), bootstrapBag.getMessageBodyWorkers(), runtimeConfig);
370370
validator.validate(bootstrapBag.getResourceModel());
371371
}
372372

core-server/src/main/java/org/glassfish/jersey/server/ServerProperties.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2024 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2025 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -461,6 +461,23 @@ public final class ServerProperties {
461461
public static final String RESOURCE_VALIDATION_IGNORE_ERRORS =
462462
"jersey.config.server.resource.validation.ignoreErrors";
463463

464+
/**
465+
* If {@code true} then validation of application resource models will not log a warning when a get resource method consumes an entity.
466+
*
467+
* This impacts both the validation of root resources during deployment as well as validation of any sub resources
468+
* returned from sub-resource locators.
469+
* <p>
470+
* The default value is {@code false}.
471+
* </p>
472+
* <p>
473+
* The name of the configuration property is <tt>{@value}</tt>.
474+
* </p>
475+
*
476+
* @see #RESOURCE_VALIDATION_DISABLE
477+
*/
478+
public static final String RESOURCE_VALIDATION_IGNORE_GET_CONSUMES_ENTITY_WARNINGS =
479+
"jersey.config.server.resource.validation.ignoreGetConsumesEntityWarnings";
480+
464481
/**
465482
* If {@code true} then application monitoring will be enabled.
466483
*

core-server/src/main/java/org/glassfish/jersey/server/internal/routing/RuntimeLocatorModelBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -228,7 +228,7 @@ private void validateResource(final ResourceModelComponent component) {
228228
Errors.process(new Runnable() {
229229
@Override
230230
public void run() {
231-
final ComponentModelValidator validator = new ComponentModelValidator(valueSuppliers, messageBodyWorkers);
231+
final ComponentModelValidator validator = new ComponentModelValidator(valueSuppliers, messageBodyWorkers, config);
232232
validator.validate(component);
233233

234234
if (Errors.fatalIssuesFound() && !ignoreValidationErrors) {

core-server/src/main/java/org/glassfish/jersey/server/model/ComponentModelValidator.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2025 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -23,9 +23,12 @@
2323
import org.glassfish.jersey.Severity;
2424
import org.glassfish.jersey.internal.Errors;
2525
import org.glassfish.jersey.message.MessageBodyWorkers;
26+
import org.glassfish.jersey.server.ServerProperties;
2627
import org.glassfish.jersey.server.model.internal.ModelErrors;
2728
import org.glassfish.jersey.server.spi.internal.ValueParamProvider;
2829

30+
import javax.ws.rs.core.Configuration;
31+
2932
/**
3033
* A resource model validator that checks the given resource model.
3134
*
@@ -57,10 +60,16 @@ public final class ComponentModelValidator {
5760
private final List<ResourceModelIssue> issueList = new LinkedList<>();
5861

5962
public ComponentModelValidator(Collection<ValueParamProvider> valueParamProviders, MessageBodyWorkers msgBodyWorkers) {
63+
this(valueParamProviders, msgBodyWorkers, null);
64+
}
65+
66+
public ComponentModelValidator(Collection<ValueParamProvider> valueParamProviders,
67+
MessageBodyWorkers msgBodyWorkers,
68+
Configuration configuration) {
6069
validators = new ArrayList<>();
6170
validators.add(new ResourceValidator());
6271
validators.add(new RuntimeResourceModelValidator(msgBodyWorkers));
63-
validators.add(new ResourceMethodValidator(valueParamProviders));
72+
validators.add(new ResourceMethodValidator(valueParamProviders, configuration));
6473
validators.add(new InvocableValidator());
6574
}
6675

core-server/src/main/java/org/glassfish/jersey/server/model/ResourceMethodValidator.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2025 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -37,9 +37,11 @@
3737
import javax.ws.rs.Path;
3838
import javax.ws.rs.PathParam;
3939
import javax.ws.rs.QueryParam;
40+
import javax.ws.rs.core.Configuration;
4041

4142
import org.glassfish.jersey.internal.Errors;
4243
import org.glassfish.jersey.server.ContainerRequest;
44+
import org.glassfish.jersey.server.ServerProperties;
4345
import org.glassfish.jersey.server.internal.LocalizationMessages;
4446
import org.glassfish.jersey.server.model.internal.SseTypeResolver;
4547
import org.glassfish.jersey.server.spi.internal.ParameterValueHelper;
@@ -54,9 +56,15 @@
5456
class ResourceMethodValidator extends AbstractResourceModelVisitor {
5557

5658
private final Collection<ValueParamProvider> valueParamProviders;
59+
private final Configuration configuration;
5760

5861
ResourceMethodValidator(Collection<ValueParamProvider> valueParamProviders) {
62+
this(valueParamProviders, null);
63+
}
64+
65+
ResourceMethodValidator(Collection<ValueParamProvider> valueParamProviders, Configuration configuration) {
5966
this.valueParamProviders = valueParamProviders;
67+
this.configuration = configuration;
6068
}
6169

6270
@Override
@@ -99,7 +107,7 @@ private void checkMethod(ResourceMethod method) {
99107
}
100108

101109
// ensure GET does not consume an entity parameter, if not inflector-based
102-
if (invocable.requiresEntity() && !invocable.isInflector()) {
110+
if (invocable.requiresEntity() && !invocable.isInflector() && !shouldIgnoreGetConsumesEntityWarnings(configuration)) {
103111
Errors.warning(method, LocalizationMessages.GET_CONSUMES_ENTITY(invocable.getHandlingMethod()));
104112
}
105113
// ensure GET does not consume any @FormParam annotated parameter
@@ -153,6 +161,16 @@ private void checkMethod(ResourceMethod method) {
153161
}
154162
}
155163

164+
private static Boolean shouldIgnoreGetConsumesEntityWarnings(Configuration configuration) {
165+
if (configuration == null) {
166+
return Boolean.FALSE;
167+
}
168+
return ServerProperties.getValue(configuration.getProperties(),
169+
ServerProperties.RESOURCE_VALIDATION_IGNORE_GET_CONSUMES_ENTITY_WARNINGS,
170+
Boolean.FALSE,
171+
Boolean.class);
172+
}
173+
156174
private void checkUnexpectedAnnotations(ResourceMethod resourceMethod) {
157175
Invocable invocable = resourceMethod.getInvocable();
158176
for (Annotation annotation : invocable.getHandlingMethod().getDeclaredAnnotations()) {

0 commit comments

Comments
 (0)