-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CDI annotations to the annotations that need them. Updated the si… #1221
base: release-5.0
Are you sure you want to change the base?
Conversation
@@ -65,6 +68,8 @@ | |||
@Target({ ElementType.TYPE, ElementType.METHOD }) | |||
@Retention(RetentionPolicy.RUNTIME) | |||
@Documented | |||
@Stereotype | |||
@RequestScoped |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it possibly clash with @singleton?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I don't know how that works since @Singleton
is not part of CDI. However, resources should be @RequestScoped
per the specification documentation. I don't see anything in the CDI specification that clears this up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CDI says @Singleton
is the pseudoscope. Which I am not sure how it is handled by Weld. Would need to do some testing.
However, the REST spec supports the @jakarta.inject.Singleton
resource classes, for instance in Section 9.4.
It also mandates:
In a product that supports EJBs, an implementation MUST support the use of stateless and singleton session beans as root resource classes
Though it is jakarta.ejb.Singleton, I still feel some potential clash with @RequestScoped
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what Weld throws (3.1 @Path
- Not modified, yet) :
org.jboss.weld.exceptions.DefinitionException: WELD-000046: At most one scope may be specified on [EnhancedAnnotatedTypeImpl] public
@RequestScoped
@Singleton
@Path
class AnnotatedTestResource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That only happens if you add both @RequestScoped
and @Singleton
to the resource though. If you only add @Singleton
and @Path
it will work. A stereotypes scope can be overridden as it's just the default scope. From the end of https://jakarta.ee/specifications/cdi/4.0/jakarta-cdi-spec-4.0#stereotype_default_scope
For example, the following stereotype might be used to identify action classes in a web application:
@RequestScoped @Stereotype @Target(TYPE) @Retention(RUNTIME) public @interface Action {}
Then actions would have scope @RequestScoped unless the scope is explicitly specified by the bean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I was not aware of it, that resolves my concerns. Keeping unresolved for others should they have the same doubts.
For the pure client and SE env we should not mandate CDI API. Unlike with classes, JDK ignores annotations when it does not know the dependency. |
Agreed and I made both the |
There is one more catch, each What's the expected behaviour, should the unregistered While the former more comply with the
the scanning phase happens just when the The latter on the other hand looks like an unpleasant overhead given all the possibilities of how the provider can be registered. |
I'd need to think more through the lifecycle, but you might be able to veto the types that are not in an |
The problem I see is that during the CDI extension run, there is no Application available yet, as the Application might be both not annotated with a bean-defining annotation or the application might be scanned after the provider being handled in the extension. Yes, it can be filtered in the Providers, but then the implementation needs to know the list of registered providers (but the provider might be registered directly into the injection framework). Maybe I miss something. Or perhaps a clarification of provider discovery in a CDI environment can be added to a Spec. I am under the impression that now (at least in Jersey) the providers annotated as CDI beans are used in the CDI-managed environment (such as Helidon). |
Yes, that's my concern with being able to use a CDI extension as well. I'm not sure, like you say, the
I do understand this concern as well. It will likely be a bit messy, I haven't thought it fully through yet, but there will probably need to be lookup in the
I'm all for some clarification in the spec. IMO it's okay to require the |
One of the reasons to come to CDI is that CDI does all the magic which the REST implementation does not need to do. That was why we wanted the CDI to be able to invoke the resource methods so that the implementation does not need to. And now it looks like we want to go against how CDI works and filter its beans somehow. (We may filter those beans, but the user still would see them all should he used the BeanManager directly). What's even more important is what the customer want to have. I am in doubt the customer wants to come happily to the CDI environment, create CDI beans, and then have to register those beans in the application to beat our tremendous effort to filter unregistered beans. Should we not define the Providers to be auto-added in the CDI environment, i.e. to define "discoverable" in the CDI container? I am trying to find the behaviour that should be expected by the Spec, in the CDI container, and I am trying to see how much incompatible the changes could potentially be. |
I definitely agree with this and it's one of my primary reasons I like the plan of adding the
I feel it's not that different to what we have now TBH. The spec does require Providers are CDI beans in a CDI environment. That said, I do know in RESTEasy before we make a provider a CDI bean, we do check to see if it CAN be a CDI bean. That said, with a CDI portable extension this should still work by checking if a bean cannot be a CDI bean and veto it.
Totally understandable for sure. The language to use in the spec personally seems the trickiest to me. Not that implementing will be easy, but wording it so all implementations at least roughly behave the same is the trick. |
Same catch for resource type annotated with new CDI stereotype
For what it worth, here are my two cent's as a user:
I think thats how QUARKUS behave for example, except that -- Nicolas |
…gnature test profile to use the new maven plugin for generation. Signed-off-by: James R. Perkins <[email protected]>
Note that for some reason signature tests are failing for me on two default constants:
I'm not sure why yet, but I have a feeling it's tooling on the test side, not what was generated by the tool as those lines did not change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks.
I am sorry, I do not follow. What do you mean by "it CAN be a CDI bean"? When it cannot be a CDI bean? |
Sorry, what I mean by this is you during processing you could check if the bean is a valid CDI bean and if not veto it. Something like: public <T> void observeProviders(@WithAnnotations({ Provider.class }) @Observes ProcessAnnotatedType<T> event) {
AnnotatedType<T> annotatedType = event.getAnnotatedType();
if (isUnproxyableClass(annotatedType.getJavaClass())) {
event.veto();
}
} The Without making these annotations bean defining annotations the user would be required to use a |
This feels backwards to me. CDI would not discover the
I still thing discovery is needed here. I actually don't really know how we'd determine this because we can't lookup the application and determine this during bean scanning. The |
Maybe I was not clear enough, sorry for that but I think we are saying the same thing.
Just to be clear I'm not talking about CDI discovery. CDI discovery is mandatory for me as well. I think that mixing both JAKARTA RS auto discovery and explicit declration of providers and resource to register can be a bit misleading for user and will go againts the previous spec (section 2.3.2) where both explicit declaration and auto-discovery where exclusive.
Well maybe I'm missing something and do not hesitate to tell me, but why do we want to do this during CDI discovery ?
-- Nicolas |
@NicoNes Yes, it appears we were saying the same thing :) I apologize for adding confusion. |
…gnature test profile to use the new maven plugin for generation.
This bumps CDI to the 4.0.0-M1 version and adds explicit module dependencies on
jakarta.cdi
andjakarta.inject
. Technically we do not need thejakarta.inject
dependency as it's transitive injakarta.cdi
. However, I felt we should be explicit.Note that I've upgraded the
sigtest-maven-plugin
to use the latestjakarta.tck
version. However, there is a bug which blocks it from working. I've manually updated the signature tests for now. We will need to update the signature file once a new release of the plugin is done with the fix.resolves #952
resolves #556