cancel
Showing results for 
Search instead for 
Did you mean: 

Method interception

ajv
Champ in-the-making
Champ in-the-making
Hi all,

I needed to intercept method calls "createSite" and I wired and Spring aspect to do it:


   <!– Advice –>
   <bean id="myService" class="MyServiceClass"/>

   <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
      <property name="beanNames">
         <value>SiteService</value>
      </property>
      <property name="interceptorNames">
         <list>
            <value>createSiteAspect</value>
         </list>
      </property>
   </bean>

   <bean name="createSitePointcut" class="org.springframework.aop.support.NameMatchMethodPointcut">
      <property name="mappedName" value="createSite" />
   </bean>

   <bean name="createSiteAspect" class="org.springframework.aop.support.DefaultPointcutAdvisor">
      <property name="advice" ref="myService" />
      <property name="pointcut" ref="createSitePointcut" />
   </bean>

This works fine: When the user creates a site, my service is called.
However, when I enable Alfresco audit (audit.enabled=true + audit.alfresco-access.enabled=true)….an exception is thrown:


2012-01-13 16:54:44,323  ERROR [extensions.webscripts.AbstractRuntime] [http-8080-3] Exception from executeScript - redirecting to status template error: 00130002 Wrapped Exception (with status template): 00130004 Failed to execute script 'classpath*:alfresco/templates/webscripts/org/alfresco/repository/site/sites.post.json.js': Bean named 'SiteService' must be of type [$Proxy85], but was actually of type [$Proxy87]
org.springframework.extensions.webscripts.WebScriptException: 00130002 Wrapped Exception (with status template): 00130004 Failed to execute script 'classpath*:alfresco/templates/webscripts/org/alfresco/repository/site/sites.post.json.js': Bean named 'SiteService' must be of type [$Proxy85], but was actually of type [$Proxy87]
   at org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:884)
   at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:171)
   at org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:400)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:388)
   at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:462)
   at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:500)
   at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:316)
   at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:352)
   at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:189)
   at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:118)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:58)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:465)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
   at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
   at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
   at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
   at java.lang.Thread.run(Thread.java:619)
Caused by: org.alfresco.scripts.ScriptException: 00130004 Failed to execute script 'classpath*:alfresco/templates/webscripts/org/alfresco/repository/site/sites.post.json.js': Bean named 'SiteService' must be of type [$Proxy85], but was actually of type [$Proxy87]
   at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:195)
   at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:282)
   at org.alfresco.repo.web.scripts.RepositoryScriptProcessor.executeScript(RepositoryScriptProcessor.java:102)
   at org.springframework.extensions.webscripts.AbstractWebScript.executeScript(AbstractWebScript.java:1107)
   at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:86)
   … 25 more
Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'SiteService' must be of type [$Proxy85], but was actually of type [$Proxy87]
   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:349)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:398)
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:388)
   at org.alfresco.repo.audit.BeanIdentifierImpl.getBeanNameImpl(BeanIdentifierImpl.java:105)
   at org.alfresco.repo.audit.BeanIdentifierImpl.getName(BeanIdentifierImpl.java:82)
   at org.alfresco.repo.audit.BeanIdentifierImpl.getBeanName(BeanIdentifierImpl.java:69)
   at org.alfresco.repo.audit.AuditMethodInterceptor.proceed(AuditMethodInterceptor.java:188)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:151)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at $Proxy85.createSite(Unknown Source)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
   at test.MyServiceClass.invoke(SiteServiceDcsAspect.java:79)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at $Proxy87.createSite(Unknown Source)
   at org.alfresco.repo.site.script.ScriptSiteService.createSite(ScriptSiteService.java:108)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:155)
   at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:243)
   at org.mozilla.javascript.optimizer.OptRuntime.callN(OptRuntime.java:86)
   at org.mozilla.javascript.gen.c5._c1(file:/E:/Alfresco/c40a/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/repository/site/sites.post.json.js:86)
   at org.mozilla.javascript.gen.c5.call(file:/E:/Alfresco/c40a/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/repository/site/sites.post.json.js)
   at org.mozilla.javascript.optimizer.OptRuntime.callName0(OptRuntime.java:108)
   at org.mozilla.javascript.gen.c5._c0(file:/E:/Alfresco/c40a/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/repository/site/sites.post.json.js:97)
   at org.mozilla.javascript.gen.c5.call(file:/E:/Alfresco/c40a/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/repository/site/sites.post.json.js)
   at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
   at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
   at org.mozilla.javascript.gen.c5.call(file:/E:/Alfresco/c40a/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/repository/site/sites.post.json.js)
   at org.mozilla.javascript.gen.c5.exec(file:/E:/Alfresco/c40a/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/repository/site/sites.post.json.js)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:483)
   at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:191)
   … 29 more
   
My class it's like this:
   

public class MyServiceClass implements MethodInterceptor {
   public Object invoke(MethodInvocation invocation) throws Throwable {
      …
      Object returnValue = invocation.proceed();
      …
   }
}
   


How I could combine interception method and Alfresco audit??   
Thanks in advance!
2 REPLIES 2

jaynil_bagdai
Champ in-the-making
Champ in-the-making
I am having the same issue.
Did you able to resolve this issue or not?

kaynezhang
World-Class Innovator
World-Class Innovator
Try to use

   <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
      <property name="beanNames">
         <value>siteService</value> //site is lower case instead of capital
      </property>
      <property name="interceptorNames">
         <list>
            <value>createSiteAspect</value>
         </list>
      </property>
   </bean>


or you can modify alfresco\site-services-context.xml file and add your interceptor to interceptorNames list

    <bean id="SiteService" class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="proxyInterfaces">
            <list>
                <value>org.alfresco.repo.site.SiteServiceInternal</value>
                <value>org.alfresco.service.cmr.site.SiteService</value>
            </list>
        </property>
        <property name="target">
            <ref bean="siteService"/>
        </property>
        <property name="interceptorNames">
            <list>
                <idref bean="siteServiceReadTxnAdvisor" />
                <idref bean="siteServiceWriteTxnAdvisor" />
                <idref bean="checkTxnAdvisor" />
                <idref bean="AuditMethodInterceptor"/>
                <idref bean="exceptionTranslator"/>
                <idref bean="SiteService_security"/>
            </list>
        </property>
    </bean>
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.