CDI Interceptors to intercept all EJB @Schedule methods

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

CDI Interceptors to intercept all EJB @Schedule methods

cocorossello
Hi,

Is there any way to apply a CDI interceptor to existing @Schedule without
explicitly usign @Interceptors in all methods? I haven't found anything in
the spec.

Or is there any easy way to create my own @Schedule CDI interceptor?

Thanks in advance.



--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
Reply | Threaded
Open this post in threaded view
|

Re: CDI Interceptors to intercept all EJB @Schedule methods

Romain Manni-Bucau
Hi,

did you put @AroundTimeout on the interceptor method? AroundInvoke is not
triggered for @Schedule.

Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://rmannibucau.metawerx.net/> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book
<https://www.packtpub.com/application-development/java-ee-8-high-performance>


Le jeu. 20 sept. 2018 à 11:45, cocorossello <[hidden email]> a
écrit :

> Hi,
>
> Is there any way to apply a CDI interceptor to existing @Schedule without
> explicitly usign @Interceptors in all methods? I haven't found anything in
> the spec.
>
> Or is there any easy way to create my own @Schedule CDI interceptor?
>
> Thanks in advance.
>
>
>
> --
> Sent from:
> http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html
>
Reply | Threaded
Open this post in threaded view
|

Re: CDI Interceptors to intercept all EJB @Schedule methods

cocorossello
Sorry, I made a mistake (I made the interceptor without parameters and didn't
read the tomee warnings)

It works with an ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         version="3.2"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/ejb-jar_3_2.xsd">
    <assembly-descriptor>
        <interceptor-binding>
            <ejb-name>*</ejb-name>
            <interceptor-class>com.ScheduleInterceptor</interceptor-class>
        </interceptor-binding>
    </assembly-descriptor>
</ejb-jar>

and


public class ScheduleInterceptor {

    @AroundTimeout
    public Object intercept(InvocationContext ctx) throws Exception {
        System.out.println("hi");
        return super.intercept(ctx);
    }
}






--
Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html