I'm learning about using AOP about RESTful webservices. I choose Tomcat
as platform and Weld
to bring CDI, I also use CXF
as JAX-RS
implementation (this is a commitee specific technological constraint in which I am pretty new). This is my sandbox.
As far as I can see Weld
is correctly loaded, I got Tomcat + Weld
configuration from here, and it find my interceptor (here is a log snapshot):
...
2017-02-02 11:26:03 DEBUG Bootstrap:238 - WELD-000105: Enabled interceptor types for Weld BeanManager for /SecProof_/WEB-INF/classes [bean count=2]:
- class org.jboss.weld.context.activator.ActivateRequestContextInterceptor,
- class edu.pezzati.sec.CanAccessImpl
2017-02-02 11:26:03 DEBUG Bootstrap:236 - WELD-000103: Enabled alternatives for Weld BeanManager for org.jboss.weld.environment.deployment.WeldDeployment.additionalClasses [bean count=3]: (empty collection)
2017-02-02 11:26:03 DEBUG Bootstrap:237 - WELD-000104: Enabled decorator types for Weld BeanManager for org.jboss.weld.environment.deployment.WeldDeployment.additionalClasses [bean count=3]: (empty collection)
2017-02-02 11:26:03 DEBUG Bootstrap:238 - WELD-000105: Enabled interceptor types for Weld BeanManager for org.jboss.weld.environment.deployment.WeldDeployment.additionalClasses [bean count=3]:
- class org.jboss.weld.context.activator.ActivateRequestContextInterceptor
2017-02-02 11:26:03 INFO servletTomcat:45 - WELD-ENV-001100: Tomcat 7+ detected, CDI injection will be available in Servlets, Filters and Listeners.
2017-02-02 11:26:03 TRACE Bean:300 - WELD-001536: Found [] constructors annotated with @Inject for [EnhancedAnnotatedTypeImpl] public @Path class edu.pezzati.sec.WebBoundary
2017-02-02 11:26:03 TRACE Bean:300 - WELD-001536: Found [] constructors annotated with @Inject for [EnhancedAnnotatedTypeImpl] public @CanAccess @Interceptor class edu.pezzati.sec.CanAccessImpl
2017-02-02 11:26:03 TRACE Bean:309 - WELD-000002: Exactly one constructor ([EnhancedAnnotatedConstructorImpl] public edu.pezzati.sec.WebBoundary()) defined, using it as the bean constructor for [EnhancedAnnotatedTypeImpl] public @Path class edu.pezzati.sec.WebBoundary
2017-02-02 11:26:03 TRACE Bean:309 - WELD-000002: Exactly one constructor ([EnhancedAnnotatedConstructorImpl] public edu.pezzati.sec.CanAccessImpl()) defined, using it as the bean constructor for [EnhancedAnnotatedTypeImpl] public @CanAccess @Interceptor class edu.pezzati.sec.CanAccessImpl
2017-02-02 11:26:03 TRACE Bean:300 - WELD-001536: Found [] constructors annotated with @Inject for [EnhancedAnnotatedTypeImpl] public @CanAccess @Interceptor class edu.pezzati.sec.CanAccessImpl
2017-02-02 11:26:03 TRACE Bean:309 - WELD-000002: Exactly one constructor ([EnhancedAnnotatedConstructorImpl] public edu.pezzati.sec.CanAccessImpl()) defined, using it as the bean constructor for [EnhancedAnnotatedTypeImpl] public @CanAccess @Interceptor class edu.pezzati.sec.CanAccessImpl
2017-02-02 11:26:03 TRACE Bean:300 - WELD-001536: Found [] constructors annotated with @Inject for [EnhancedAnnotatedTypeImpl] public @Path class edu.pezzati.sec.WebBoundary
...
Well, I can reach my trivial service but my interceptor is not triggered. Here is what Tomcat gives back to me:
...
INFORMAZIONI: Server startup in 2293 ms
2017-02-02 11:28:59 TRACE Servlet:232 - WELD-000708: Initializing request org.apache.catalina.connector.Request@2b2c4052
2017-02-02 11:28:59 DEBUG Reflection:82 - WELD-000620: interface javax.enterprise.inject.Intercepted is not declared @Target(METHOD, FIELD, PARAMETER, TYPE). Weld will use this annotation, however this may make the application unportable.
2017-02-02 11:28:59 DEBUG Reflection:82 - WELD-000620: interface javax.enterprise.inject.Decorated is not declared @Target(METHOD, FIELD, PARAMETER, TYPE). Weld will use this annotation, however this may make the application unportable.
2017-02-02 11:28:59 TRACE Context:69 - WELD-000222: Loading bean store org.jboss.weld.context.beanstore.http.LazySessionBeanStore@366ca776 map from session null
2017-02-02 11:28:59 TRACE DefaultListableBeanFactory:568 - No bean named 'org.apache.cxf.phase.PhaseManager' found in org.springframework.beans.factory.support.DefaultListableBeanFactory@2c80a98d: defining beans [cxf,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,sec,secproof]; root of factory hierarchy
2017-02-02 11:28:59 TRACE DefaultListableBeanFactory:568 - No bean named 'org.apache.cxf.policy.PolicyDataEngine' found in org.springframework.beans.factory.support.DefaultListableBeanFactory@2c80a98d: defining beans [cxf,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,sec,secproof]; root of factory hierarchy
2017-02-02 11:28:59 TRACE Servlet:293 - WELD-000709: Destroying request org.apache.catalina.connector.Request@2b2c4052
...
What am I missing?
Nevermind. It was only lack of configuration. I had to use the cxf-integration-cdi
to make it works this blog post and this example were fundamentals. Thanks goes to the author.