Hi,

Ive just started using aop for some simple logging in a new project. Ive
read through quite a few threads and various sites but cant seem to quite
understand why Im getting the problem.

I am using Spring 2.5.5 to inject various classes for a JMS project and also
using the schema based spring-aop namespace due to being restricted to
1.4jvm. I am also using aspectJ 1.5.4.

The problem is that although logging seems to work fine for any classes that
use a default constructor, classes that have constructors with args; 1. dont
get logging and 2. throw an error within the DI that seems to be a
nullpointer issue, Im only guessing at this as no info is given.

What I also dont understand is that I am using the method pointcut pattern
so why is this causing a problem with the constructor?

Heres my code, Hope Im not just being dumb (though most likely!)

<bean id="sonicConfig"
        
class="com.homeserve.guidewire.plugins.messaging.edi.outbound.transport.SonicConfig">
                <constructor-arg
value="SonicBroker=tcp://hgbsmdev02.hgb.hs.int:2531;SonicUsername=Administrator;SonicPassword=Administrator"
/>
</bean>

        <bean id="aopLogging"
        
class="com.homeserve.guidewire.plugins.messaging.edi.logging.LoggingInterceptor">
        </bean>
                
        <aop:config proxy-target-class="false">
                <aop:aspect id="aopLoggingAspect" ref="aopLogging">
                
                        <aop:pointcut id="loggingPointCut" 
                                expression="execution( *
com.homeserve.guidewire.plugins.messaging.edi.outbound..*.*(..))" />
                                        
                        <aop:around method="aopLogging" 
pointcut-ref="loggingPointCut" />
                        
                </aop:aspect>
        </aop:config>

    public SonicConfig(String sonicConnectionString) throws ParseException
    {
        this.sonicConnectionString = sonicConnectionString;
        parseSonicConnectionString();
    }

public class LoggingInterceptor {
        
        public Object aopLogging(ProceedingJoinPoint pjp) throws Throwable{
                Logger log = Logger.getLogger(LoggingInterceptor.class);
                Object retValue = null;
                Object[] args = pjp.getArgs();
                try     {
                        
                        StringBuffer entering = new StringBuffer();
                        StringBuffer leaving = new StringBuffer();
                        Signature sig = pjp.getSignature();
                                String clazz = 
pjp.getSignature().getDeclaringType().getName();
                                
entering.append(clazz.substring(clazz.lastIndexOf(".")+1,
clazz.length()));
                                entering.append(".");
                                entering.append(sig.getName());
                                entering.append("(");
                                leaving.append(entering.toString());
                                for (int i = 0; i < args.length; i++) {
                                        if (i > 0) {
                                                entering.append(", ");
                                        }
                                        entering.append(args[i]);
                                }
                                entering.append(")]");
                                SourceLocation sl = pjp.getSourceLocation();
                                log.info("Entering [" + entering);
                                        
                        retValue =  pjp.proceed();

                        leaving.append(")");
                        log.info("Leaving [" + leaving + " Return value: " + 
retValue);
                                                
                }
                catch (Exception e)
                {
                        log.error(e);
                }
                return retValue;
        }
}

Thanks 
Yetti
-- 
View this message in context: 
http://aspectj.2085585.n4.nabble.com/DI-Constructor-issue-tp2241500p2241500.html
Sent from the AspectJ - users mailing list archive at Nabble.com.
_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to