-
Notifications
You must be signed in to change notification settings - Fork 77
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
Getting interceptor bindings in standard way #592
Comments
If only we could change the |
True, we could try that - it's too late for EE 10 anyway. |
The original solution is the key right? I can change the invocation interface, but the Interceptors spec is technically still CDI independent. We have at least 14 days for EE 10 btw. |
Technically speaking, if we standardized the key, then we could add a few methods to |
You're right, so essentially what we have today is: Set<Annotation> bindings = (Set<Annotation>)
invocationContext.getContextData().get("org.jboss.weld.interceptor.bindings"); We indeed should define it in the Interceptor spec. But nobody really wants to touch Enterprise Beans I guess. It technically doesn't have to comply, although it may. For instance, in Faces we defined some functionality that Facelets complied to but JSP just didn't. Nobody wanted to touch JSP anymore. The method could be: public interface InvocationContext {
default Set<Annotation> getInterceptorBindings() {
return emptySet(); // or null?
} |
+1 for default |
That sounds good. I am also +1 for empty set (rather than |
My understanding is that EJB also has to implement the full Interceptors specification, just like CDI, so even though the idiomatic way of associating interceptor with components in CDI is through interceptor binding annotations and in EJB through That said, I'd be fine with adding something like the following to /**
* Returns the set of interceptor binding annotations used to associate interceptors with the target component.
* Returns an empty set if all interceptors are associated with the target component using the {@link Interceptors @Interceptors} annotation.
* <p>
* No requirements exist on mutability or shareability of the returned set.
* <p>
* This method is not required to be implemented by EJB containers.
* It must be implemented by CDI containers.
*
* @return the set of interceptor bindings, never {@code null}
*/
default Set<Annotation> getInterceptorBindings() {
return Collections.emptySet();
}
/**
* Returns the interceptor binding annotation of given type used to associate interceptors with the target component.
* Returns {@code null} if the {@link #getInterceptorBindings() full set} of interceptor bindings does not contain an annotation of given type,
* or if all interceptors are associated with the target component using the {@link Interceptors @Interceptors} annotation.
* <p>
* In case of repeatable interceptor bindings, {@link #getInterceptorBindings(Class)} should be used.
* <p>
* This method is not required to be implemented by EJB containers.
* It must be implemented by CDI containers.
*
* @param annotationType type of the interceptor binding annotation, must not be {@code null}
* @return the interceptor binding annotation of given type, may be {@code null}
*/
default <T extends Annotation> T getInterceptorBinding(Class<T> annotationType) {
for (Annotation interceptorBinding : getInterceptorBindings()) {
if (interceptorBinding.annotationType().equals(annotationType)) {
return (T) annotation;
}
}
return null;
}
/**
* Returns the set of interceptor binding annotations of given type used to associate interceptors with the target component.
* The result is typically a singleton set, unless repeatable interceptor bindings are used.
* Returns an empty set if all interceptors are associated with the target component using the {@link Interceptors @Interceptors} annotation.
* <p>
* No requirements exist on mutability or shareability of the returned set.
* <p>
* This method is not required to be implemented by EJB containers.
* It must be implemented by CDI containers.
*
* @param annotationType type of the interceptor binding annotation, must not be {@code null}
* @return the set of interceptor bindings of given type, never {@code null}
*/
default <T extends Annotation> Set<T> getInterceptorBindings(Class<T> annotationType) {
Set<T> result = new HashSet<>();
for (Annotation interceptorBinding : getInterceptorBindings()) {
if (interceptorBinding.annotationType().equals(annotationType)) {
result.add((T) interceptorBinding);
}
}
return result;
} I understand that the Interceptors spec ignores the existence of repeatable annotations (because they didn't exist at that time), so I'd be fine with dropping the last method (and the paragraph mentioning repeatable interceptor bindings in the javadoc of the 2nd). The 2nd seems pretty useful to me. |
Well, the thing is that EJB session beans are considered CDI beans anyway. I don't think the EJB impls implement CDI-style interceptors by themselves, instead they delegate to the CDI container.
I would not include these sentences at all.
Hm, I'd prefer to say that the returned set is immutable. This wording does not help anyone. A client should not modify the set and the CDI implementor should either return a new set or make it immutable (to protect users from shooting in their own leg ;-). |
Hmm, assuming that
actually means that interceptor bindings are always handled by CDI, then indeed this provision
is unnecessary. When it comes to mutability etc., I'd be fine with requiring the resulting sets to be immutable, for sure. |
Okay, so I think that for the next release cycle (post EE 10), we have our work cut out then ;) |
It would be nice to see this added in Jakarta EE 11. We ran into some difficulty where we are needing to rely on the WELD-specific approach in our implementation of the Transactional interceptor to properly detect the information configured on the interceptor binding at class level. |
Yes, I think this is something we want to get in, but ideally via interceptors spec (change to |
Note to self: if we go forward with this, need to add tests to the CDI TCK for this. |
Submitted jakartaee/interceptors#99 for this. |
The linked interceptors PR was merged, I think we can close this and open a tracking issue for TCK coverage. EDIT: Mea culpa, we already have the PR! See jakartaee/cdi-tck#479 |
This is already resolved in the interceptors spec and TCK coverage has been merged as well; closing this issue. |
As per the discussion here:
https://www.eclipse.org/lists/cdi-dev/msg00133.html
Essentially boils down to standardising the implementation specific key for this.
The text was updated successfully, but these errors were encountered: