[JBoss JIRA] (WFLY-11956) @PostConstruct on @ApplicationScoped bean called too late in case @Valid is annotated on a business method
by Gunnar Morling (Jira)
[ https://issues.jboss.org/browse/WFLY-11956?page=com.atlassian.jira.plugin... ]
Gunnar Morling edited comment on WFLY-11956 at 4/25/19 12:20 PM:
-----------------------------------------------------------------
Hi, AFAICS, this is a case of (mostly) "works as designed": JAX-RS mandates the validation of properties on the resource class (see the validation routine in 7.6 of the [JAX-RS 2.0. spec|https://download.oracle.com/otn-pub/jcp/jaxrs-2_0-fr-eval-spec/jsr33...], phase 2 ("Validate annotations on fields, property getters (if enabled) and the resource class."). So a resource method that follows the bean property naming semantics would be validated here. Note I say "mostly", is this should only explain *one* invocation, but not two.
As [~guillaume.smet] points out, suppressing this validation will not be trivial, as in all likelyhood one still would want to validate any other getters which are not also resource endpoints to be validated in that phase 2. The immediate work-around would be indeed to avoid naming resource endpoint methods as getters.
In addition we might explore providing more fine-grained control over the properties to validate during phase 2. Essentially, it'd require some sort of filtering SPI provided by HV and implemented by RESTEasy which gives the latter the control to exclude specific properties from validation. But I'd consider this more as feature request for future versions than as a bug fix (again apart from the fact that the method seems to be invoked twice before post-construct).
was (Author: gunnar.morling):
Hi, AFAICS, this is a case of (mostly) "works as designed": JAX-RS mandates the validation of properties on the resource class (see the validation routine in 7.6 of the JAX-RS spec, phase 2 ("Validate annotations on fields, property getters (if enabled) and the resource class."). So a resource method that follows the bean property naming semantics would be validated here. Note I say "mostly", is this should only explain *one* invocation, but not two.
As [~guillaume.smet] points out, suppressing this validation will not be trivial, as in all likelyhood one still would want to validate any other getters which are not also resource endpoints to be validated in that phase 2. The immediate work-around would be indeed to avoid naming resource endpoint methods as getters.
In addition we might explore providing more fine-grained control over the properties to validate during phase 2. Essentially, it'd require some sort of filtering SPI provided by HV and implemented by RESTEasy which gives the latter the control to exclude specific properties from validation. But I'd consider this more as feature request for future versions than as a bug fix (again apart from the fact that the method seems to be invoked twice before post-construct).
> @PostConstruct on @ApplicationScoped bean called too late in case @Valid is annotated on a business method
> ----------------------------------------------------------------------------------------------------------
>
> Key: WFLY-11956
> URL: https://issues.jboss.org/browse/WFLY-11956
> Project: WildFly
> Issue Type: Bug
> Components: Bean Validation, REST
> Affects Versions: 16.0.0.Final
> Reporter: Joerg Baesner
> Assignee: Ronald Sigal
> Priority: Major
> Attachments: logging.txt, playground.zip
>
>
> Having a bean class with {{@ApplicationScoped}}, which has a {{@PostConstruct}} and is implementing the following _Interface_:
> {code}
> @Path("/validated")
> public interface ValidatedJaxRsInterface {
>
> @GET
> @Valid
> @Produces(MediaType.APPLICATION_JSON)
> GreetingModel getHelloGreeting();
> }
> {code}
> will result in calling the {{getHelloGreeting}} method of the implementation class twice *_before_* the {{@PostConstruct}} is getting executed.
> This can be reproduced with the attached reproducer application...
--
This message was sent by Atlassian Jira
(v7.12.1#712002)
5 years, 5 months
[JBoss JIRA] (WFLY-11956) @PostConstruct on @ApplicationScoped bean called too late in case @Valid is annotated on a business method
by Gunnar Morling (Jira)
[ https://issues.jboss.org/browse/WFLY-11956?page=com.atlassian.jira.plugin... ]
Gunnar Morling reassigned WFLY-11956:
-------------------------------------
Assignee: Ronald Sigal (was: Gunnar Morling)
> @PostConstruct on @ApplicationScoped bean called too late in case @Valid is annotated on a business method
> ----------------------------------------------------------------------------------------------------------
>
> Key: WFLY-11956
> URL: https://issues.jboss.org/browse/WFLY-11956
> Project: WildFly
> Issue Type: Bug
> Components: Bean Validation, REST
> Affects Versions: 16.0.0.Final
> Reporter: Joerg Baesner
> Assignee: Ronald Sigal
> Priority: Major
> Attachments: logging.txt, playground.zip
>
>
> Having a bean class with {{@ApplicationScoped}}, which has a {{@PostConstruct}} and is implementing the following _Interface_:
> {code}
> @Path("/validated")
> public interface ValidatedJaxRsInterface {
>
> @GET
> @Valid
> @Produces(MediaType.APPLICATION_JSON)
> GreetingModel getHelloGreeting();
> }
> {code}
> will result in calling the {{getHelloGreeting}} method of the implementation class twice *_before_* the {{@PostConstruct}} is getting executed.
> This can be reproduced with the attached reproducer application...
--
This message was sent by Atlassian Jira
(v7.12.1#712002)
5 years, 5 months
[JBoss JIRA] (WFLY-11956) @PostConstruct on @ApplicationScoped bean called too late in case @Valid is annotated on a business method
by Gunnar Morling (Jira)
[ https://issues.jboss.org/browse/WFLY-11956?page=com.atlassian.jira.plugin... ]
Gunnar Morling commented on WFLY-11956:
---------------------------------------
Hi, AFAICS, this is a case of (mostly) "works as designed": JAX-RS mandates the validation of properties on the resource class (see the validation routine in 7.6 of the JAX-RS spec, phase 2 ("Validate annotations on fields, property getters (if enabled) and the resource class."). So a resource method that follows the bean property naming semantics would be validated here. Note I say "mostly", is this should only explain *one* invocation, but not two.
As [~guillaume.smet] points out, suppressing this validation will not be trivial, as in all likelyhood one still would want to validate any other getters which are not also resource endpoints to be validated in that phase 2. The immediate work-around would be indeed to avoid naming resource endpoint methods as getters.
In addition we might explore providing more fine-grained control over the properties to validate during phase 2. Essentially, it'd require some sort of filtering SPI provided by HV and implemented by RESTEasy which gives the latter the control to exclude specific properties from validation. But I'd consider this more as feature request for future versions than as a bug fix (again apart from the fact that the method seems to be invoked twice before post-construct).
> @PostConstruct on @ApplicationScoped bean called too late in case @Valid is annotated on a business method
> ----------------------------------------------------------------------------------------------------------
>
> Key: WFLY-11956
> URL: https://issues.jboss.org/browse/WFLY-11956
> Project: WildFly
> Issue Type: Bug
> Components: Bean Validation, REST
> Affects Versions: 16.0.0.Final
> Reporter: Joerg Baesner
> Assignee: Gunnar Morling
> Priority: Major
> Attachments: logging.txt, playground.zip
>
>
> Having a bean class with {{@ApplicationScoped}}, which has a {{@PostConstruct}} and is implementing the following _Interface_:
> {code}
> @Path("/validated")
> public interface ValidatedJaxRsInterface {
>
> @GET
> @Valid
> @Produces(MediaType.APPLICATION_JSON)
> GreetingModel getHelloGreeting();
> }
> {code}
> will result in calling the {{getHelloGreeting}} method of the implementation class twice *_before_* the {{@PostConstruct}} is getting executed.
> This can be reproduced with the attached reproducer application...
--
This message was sent by Atlassian Jira
(v7.12.1#712002)
5 years, 5 months
[JBoss JIRA] (WFLY-11956) @PostConstruct on @ApplicationScoped bean called too late in case @Valid is annotated on a business method
by Gunnar Morling (Jira)
[ https://issues.jboss.org/browse/WFLY-11956?page=com.atlassian.jira.plugin... ]
Gunnar Morling reassigned WFLY-11956:
-------------------------------------
Assignee: Gunnar Morling (was: Ronald Sigal)
> @PostConstruct on @ApplicationScoped bean called too late in case @Valid is annotated on a business method
> ----------------------------------------------------------------------------------------------------------
>
> Key: WFLY-11956
> URL: https://issues.jboss.org/browse/WFLY-11956
> Project: WildFly
> Issue Type: Bug
> Components: Bean Validation, REST
> Affects Versions: 16.0.0.Final
> Reporter: Joerg Baesner
> Assignee: Gunnar Morling
> Priority: Major
> Attachments: logging.txt, playground.zip
>
>
> Having a bean class with {{@ApplicationScoped}}, which has a {{@PostConstruct}} and is implementing the following _Interface_:
> {code}
> @Path("/validated")
> public interface ValidatedJaxRsInterface {
>
> @GET
> @Valid
> @Produces(MediaType.APPLICATION_JSON)
> GreetingModel getHelloGreeting();
> }
> {code}
> will result in calling the {{getHelloGreeting}} method of the implementation class twice *_before_* the {{@PostConstruct}} is getting executed.
> This can be reproduced with the attached reproducer application...
--
This message was sent by Atlassian Jira
(v7.12.1#712002)
5 years, 5 months