Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] AbstractMethodError excpetion with Mixin on Interfaces but not on its implemenation @AspectJ

Hello,

We got the following excpetion AbstractMethodError when we used mixin on interfaces. The exception does not occur when we applied the same aspect on implementation - See below the aspect.

We would like to know what we're doing wrong when we use interfaces? The behavior is a logging aspect. We want to logging all methods from the interfaces, especially the find* methods.

I've put >>>> 45  et >>>> 34 to give you the line number where the error is triggered inside the code.

By the past, in "coded-style", with "declare parents", applying aspect on interfaces did not raise an error.

Best regards


=============
ERROR TRACE
=============

java.lang.AbstractMethodError: com/cpny/crm/aspects/LoggingBaseBehavior$Loggable.getLog()Lorg/slf4j/Logger;
        at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
        at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
        ... 39 more
Caused by: java.lang.AbstractMethodError: com/intact/cpny/aspects/LoggingBaseBehavior$Loggable.getLog()Lorg/slf4j/Logger;
        at com.cpny.crm.aspects.LoggingServiceBehavior.loggerService(LoggingServiceBehavior.java:45)
        at com.cpny.crm.domain.services.impl.EDocService.findDocumentsByPolicy(EDocService.java:34)


==========================================
ASPECT (LoggingServiceBehavior)
==========================================

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.DeclareMixin;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class LoggingServiceBehavior extends LoggingBaseBehavior {

        @DeclareMixin("com.cpny.crm.domain.services.interfaces.*")
        public static Loggable createLoggerDelegate(Object o) {
                return new ServantLogger(o.getClass());
        }

        @Pointcut("execution(* com.cpny.crm.domain.services.interfaces.*.find*(..))")
        public void serviceLogger() {};


        @Before(value = "serviceLogger() && this(log)")
        public void loggerService(JoinPoint jp, JoinPoint.StaticPart jps, Loggable log) {
>>>> 45                if (log.getLog().isDebugEnabled()) {
                        final String args = buildParameters(jp.getArgs());
                        log.getLog().debug(jps.getSignature().getName() + " - Entering..." + (args.isEmpty() ? "" : " - params: " + args));
                }
        }
}

===================
ASPECT BASE
==================
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Aspect
public abstract class LoggingBaseBehavior {

        protected String buildParameters(Object[] parameters) {
                StringBuilder sb = new StringBuilder(64);
                if (parameters == null) return null;
                        for(int i = 0; i< parameters.length; i++) {
                                sb.append("Param")
                                  .append(i+1)
                                  .append(" : ")
                                  .append("'")
                                  .append(parameters[i])
                                  .append("'");
                                if (i+1 < parameters.length) { sb.append(" - "); }
                        }
                return sb.toString();
        }

        /*
         * The interface and the implementation of Loggable class.
         */
        public interface Loggable {
                public Logger getLog();
        };

        public static class ServantLogger implements Loggable {
                private transient Logger log = null;

                public ServantLogger(Class<? extends Object> clazz) {
                        this.log =  LoggerFactory.getLogger(clazz);
                }

                @Override
                public Logger getLog() {
                        return log;
                }
        }
}


=================================
THE SERVICE INTERFACES
=================================
public interface IEDocService extends Serializable {

        public IEdocTree findDocumentsByPolicy(String policyNumber, Date inceptionDate, List<IAgreement> clientAgreementList, UserBean user);
}

==============================================================
THE SERVICE IMPLEMENTATION - EDocService.java
==============================================================
@Named
@Scope("singleton")
public class EDocService implements IEDocService {

        private static final long serialVersionUID = 1101L;

        private final String SSDC_APPLICATION_CRM_ID = "EDOC";

        @Override
        public IEdocTree findDocumentsByPolicy(String policyNumber
                                            , Date inceptionDate
                                            , List<IAgreement> clientAgreementList
                                            , UserBean user) {
>>>> 34                IEdocTree eDocTree = null;

                final Map<String, ElectronicDocumentByPolicy> eDocPolicies =
                  new HashMap<String,ElectronicDocumentByPolicy>();
                final Map<String, IEdocTree> eDocTreeCurrent = new HashMap<String, IEdocTree>();
                final Map<String, IEdocTree> eDocTreeHistory = new HashMap<String, IEdocTree>();
                final Map<String, DescriptionRuleHistory> eDocDescriptions =
                  new HashMap<String, DescriptionRuleHistory>();
                final Map<String,Object> alreadySeenEDocs = new HashMap<String,Object>();

                IDocumentPresentationService eDocService =
                  DocumentPresentationFactory.getDocumentPresentationService();

                eDocTree = eDocService.getEdocTreeHistory( eDocPolicies
                                                                 , eDocTreeCurrent
                                                                 , eDocTreeHistory
                                                                 , eDocDescriptions
                                                                 , alreadySeenEDocs
                                                                 , policyNumber
                                                                 , inceptionDate
                                                                 , user.getBusinessUnit().getProvince()
                                                                 , user.getLocale().getLanguage()
                                                                 , buildTerm(clientAgreementList)
                                                                 , false
                                                                 , user.getIvUser()
                                                                 , user.getUserType()
                                                                 , SSDC_APPLICATION_CRM_ID
                                                                 , user.getBusinessUnit().getManufacturerCompany()
                                                                 , user.getBusinessUnit().getDistributionChannel()
                                                                 , user.getBusinessUnit().getInsuranceBusiness());
                return eDocTree;
        }
}


Back to the top