Forums de discussion
Adding Aspect to Liferay Service
Jan Geißler, modifié il y a 12 années.
Adding Aspect to Liferay Service
Liferay Master Publications: 735 Date d'inscription: 05/07/11 Publications récentes
Hello all.
I wonder if anybody tried or even succeded in implementing an additional Aspect for ServiceBuilder-generated service classes.
Setup:
I using a spring Web-MVC setup with annotations for my controller.
So here is what i tried:
Created a simple Aspect based on:
com.liferay.portal.monitoring.statistics.service.ServiceMonitorAdvice
Well, and now the variations I tried:
added
aspects.xml
to
docroot/WEB-INF/src/META-INF
with content:
added
to web.xml
well.... didnt work. No calls were Intercepted.
Pointcut tries:
execution(* *..service..*(..))
execution(* update*(..))
execution(* *(..))
had no success with Annotated aspects via AspectJ autoproxa either.
Funny thing is:
I expose some helper Classes by adding them as subpackages to
docroot/WEB-INF/service
-> de.osc.commons.service
these Classes get instantiated in the PortletContext , and calls to these classes get intercepted when adding the Aspect in my <portlet>-context.xml.
So I figured that the ServiceMethods live in another ApplicationContext.
Thats when i tried to add the Aspect to the portlet context via web.xml. This didnt work out either, nor adding the context to portlet-spring.xml or base-spring.xml
Adding the aspect.xml to service.properties also didn't work.
I am out of ideas right now...
Any help or suggestions would be really more then appreciated, because there is absolutly NO documentation about how to do this.
The lack of documentation is sometimes really frustrating. Espacially when it takes you days to figure out how to do something, because you seem to be the first guy in the world who ever tried to do that (Even though I do not believe that.)
Frustrated greeting after 8 hours of trying
Jan
I wonder if anybody tried or even succeded in implementing an additional Aspect for ServiceBuilder-generated service classes.
Setup:
I using a spring Web-MVC setup with annotations for my controller.
So here is what i tried:
Created a simple Aspect based on:
com.liferay.portal.monitoring.statistics.service.ServiceMonitorAdvice
package de.osc.commons.service.aspects;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
public class DataLoggingInterceptor implements MethodInterceptor {
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
System.out.println("Hello World!");
return methodInvocation.proceed();
}
}
Well, and now the variations I tried:
added
aspects.xml
to
docroot/WEB-INF/src/META-INF
with content:
<!--?xml version="1.0" encoding="UTF-8"?-->
<beans default-destroy-method="destroy" default-init-method="afterPropertiesSet" xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<aop:config>
<aop:pointcut id="serviceOperation" expression="execution(* *..service.*(..))" />
<aop:advisor advice-ref="dataLoggingAdvice" pointcut-ref="serviceOperation" />
</aop:config>
<bean id="dataLoggingAdvice" class="de.osc.commons.service.aspects.DataLoggingInterceptor"></bean>
</beans>
added
<context-param>
<param-name>portalContextConfigLocation</param-name>
<param-value>/WEB-INF/classes/META-INF/aspects.xml</param-value>
</context-param>
to web.xml
well.... didnt work. No calls were Intercepted.
Pointcut tries:
execution(* *..service..*(..))
execution(* update*(..))
execution(* *(..))
had no success with Annotated aspects via AspectJ autoproxa either.
Funny thing is:
I expose some helper Classes by adding them as subpackages to
docroot/WEB-INF/service
-> de.osc.commons.service
these Classes get instantiated in the PortletContext , and calls to these classes get intercepted when adding the Aspect in my <portlet>-context.xml.
So I figured that the ServiceMethods live in another ApplicationContext.
Thats when i tried to add the Aspect to the portlet context via web.xml. This didnt work out either, nor adding the context to portlet-spring.xml or base-spring.xml
Adding the aspect.xml to service.properties also didn't work.
I am out of ideas right now...
Any help or suggestions would be really more then appreciated, because there is absolutly NO documentation about how to do this.
The lack of documentation is sometimes really frustrating. Espacially when it takes you days to figure out how to do something, because you seem to be the first guy in the world who ever tried to do that (Even though I do not believe that.)
Frustrated greeting after 8 hours of trying
Jan
Jan Geißler, modifié il y a 12 années.
RE: Adding Aspect to Liferay Service
Liferay Master Publications: 735 Date d'inscription: 05/07/11 Publications récentes
Update....
I think the problem is getting the Aspect in the correct applicationContext. This has to be the ServiceBuilder Context, not the Spring-Web-Portlet Context.
So I have to register my aspects in an additional spring-config file.
i did this as follows:
created ext-spring.xml in
docroot/WEB-INF/src/META-INF
with content:
well, this is my what i get for doing this:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'de.osc.commons.service.DataLogLocalService' defined in ServletContext resource [/WEB-INF/classes/META-INF/portlet-spring.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'de.osc.commons.service.DataLogService' defined in ServletContext resource [/WEB-INF/classes/META-INF/portlet-spring.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'de.osc.commons.service.persistence.DataLogPersistence' defined in ServletContext resource [/WEB-INF/classes/META-INF/portlet-spring.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'de.osc.commons.service.aspects.DataLoggingInterceptor' must be of type [org.aopalliance.aop.Advice], but was actually of type [de.osc.commons.service.aspects.DataLoggingInterceptor]
if I define the exact same aspect and pointcut to my Controller, all works fine. So I suspect a ClassLoader Problem.
Asking google for the Problem "must be of type [org.aopalliance.aop.Advice], but was actually of type " resulted all in ClassLoader problems. 2 times org.aopalliance.aop.Advice on the Classpath.
Slightly strange....
I think the problem is getting the Aspect in the correct applicationContext. This has to be the ServiceBuilder Context, not the Spring-Web-Portlet Context.
So I have to register my aspects in an additional spring-config file.
i did this as follows:
created ext-spring.xml in
docroot/WEB-INF/src/META-INF
with content:
<aop:config proxy-target-class="true">
<aop:advisor advice-ref="de.osc.commons.service.aspects.DataLoggingInterceptor" pointcut="bean(*Persistence) || bean(*Finder)" />
</aop:config>
<bean id="de.osc.commons.service.aspects.DataLoggingInterceptor" class="de.osc.commons.service.aspects.DataLoggingInterceptor"></bean>
well, this is my what i get for doing this:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'de.osc.commons.service.DataLogLocalService' defined in ServletContext resource [/WEB-INF/classes/META-INF/portlet-spring.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'de.osc.commons.service.DataLogService' defined in ServletContext resource [/WEB-INF/classes/META-INF/portlet-spring.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'de.osc.commons.service.persistence.DataLogPersistence' defined in ServletContext resource [/WEB-INF/classes/META-INF/portlet-spring.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'de.osc.commons.service.aspects.DataLoggingInterceptor' must be of type [org.aopalliance.aop.Advice], but was actually of type [de.osc.commons.service.aspects.DataLoggingInterceptor]
if I define the exact same aspect and pointcut to my Controller, all works fine. So I suspect a ClassLoader Problem.
Asking google for the Problem "must be of type [org.aopalliance.aop.Advice], but was actually of type " resulted all in ClassLoader problems. 2 times org.aopalliance.aop.Advice on the Classpath.
Slightly strange....
Jan Geißler, modifié il y a 12 années.
RE: Adding Aspect to Liferay Service
Liferay Master Publications: 735 Date d'inscription: 05/07/11 Publications récentes
*push*
Jan Geißler, modifié il y a 12 années.
RE: Adding Aspect to Liferay Service
Liferay Master Publications: 735 Date d'inscription: 05/07/11 Publications récentes
Still hoping someone has an idea on that problem....
Regards Jan
Regards Jan
Jan Geißler, modifié il y a 12 années.
RE: Adding Aspect to Liferay Service
Liferay Master Publications: 735 Date d'inscription: 05/07/11 Publications récentes
Come on girls and guys... no one ever tried to do that?? Hard to believe. I am really stuck on that s**t.
Wole Adetiba, modifié il y a 11 années.
RE: Adding Aspect to Liferay Service
New Member Publications: 12 Date d'inscription: 09/11/07 Publications récentes
Hi Jan,
Were you able to figure this out? I have a requirement that looks similar to this.
Wole
Were you able to figure this out? I have a requirement that looks similar to this.
Wole
Jan Geißler, modifié il y a 11 années.
RE: Adding Aspect to Liferay Service
Liferay Master Publications: 735 Date d'inscription: 05/07/11 Publications récentes
Actually not. After some more Headaches I used ModelListeners.