Hi,
This is a follow-on to my query a couple of days ago about using pointcuts
defined in an external file. I guess I was a bit premature in posting. It
had been a few months since I had looked at my problems and I should have
taken the time to review. So, sorry for the noise.
Ok, so here's where I'm at. I'm thinking this is a bug, but it could be a
misunderstanding on my part. I have written a small test program that
simulates what I'm trying to do. I have the following aspect:
package com.foo.aspects;
import com.foo.test.Request;
import com.foo.test.Response;
public abstract aspect AbstractServletLogger {
public abstract pointcut loggedGetOperations2 ();
void around () : loggedGetOperations2 () {
Object [] args = thisJoinPoint.getArgs();
Request request = (Request)args[0];
Response response = (Response)args[1];
System.out.println("[AbstractServletLoggerTrace, request]: " +
request.getRequest ());
System.out.println("[AbstractServletLoggerTrace, response]: " +
response.getResponse());
proceed ();
}
}
Here is the aop.xml:
<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
<aspects>
<concrete-aspect name="com.foo.aspects.ServletLoggerInstance"
extends="com.foo.aspects.AbstractServletLogger">
<pointcut name="loggedGetOperations2"
expression="execution (void com.foo.test.TraceTest.doGet(
com.foo.test.Request, com.foo.test.Response))" />
</concrete-aspect>
</aspects>
<weaver options="-verbose -debug">
<dump within="com.foo.test.*"/>
</weaver>
</aspectj>
Here is the main set of code which I'm instrumenting:
package com.foo.test;
public class TraceTest {
public void doGet (Request request, Response response) {
if (request == null) {
System.err.println("Request is NULL");
}
if (response == null) {
System.err.println("Response is NULL");
}
System.out.println ("Request: " + request.getRequest() + ",
Response: " + response.getResponse());
}
public static void main(String[] args) {
Request request = new Request ("This is the request");
Response response = new Response ("This is the response");
TraceTest t = new TraceTest ();
t.doGet(request, response);
}
}
// Simulates the HttpServletRequest class
package com.foo.test;
public class Request {
private String request;
public Request (String request) {
this.request = request;
}
public String getRequest () {
return this.request;
}
}
// Simulates the HttpServletResponse class
package com.foo.test;
public class Response {
private String response;
public Response (String response) {
this.response = response;
}
public String getResponse () {
return this.response;
}
}
And here is what I'm getting:
[EMAIL PROTECTED] info AspectJ Weaver Version 1.5.3 built on Wednesday
Nov 22, 2006 at 11:18:15 GMT
[EMAIL PROTECTED] info register classloader
[EMAIL PROTECTED]
[EMAIL PROTECTED] info using configuration
/C:/dev/workspace/AOPTest/bin/META-INF/aop.xml
[EMAIL PROTECTED] info define aspect
com.foo.aspects.ServletLoggerInstance
[EMAIL PROTECTED] debug weaving 'com.foo.aspects.ServletLoggerInstance
'
[EMAIL PROTECTED] debug generating class '
com.foo.aspects.ServletLoggerInstance'
[EMAIL PROTECTED] debug weaving 'com.foo.test.TraceTest'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.runtime.reflect.Factory'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.lang.reflect.SourceLocation'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.runtime.reflect.MethodSignatureImpl'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.lang.reflect.MethodSignature'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.runtime.reflect.CodeSignatureImpl'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.runtime.reflect.MemberSignatureImpl'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.runtime.reflect.SignatureImpl'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.runtime.reflect.ConstructorSignatureImpl'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.lang.reflect.ConstructorSignature'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.runtime.reflect.UnlockSignatureImpl'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.lang.reflect.UnlockSignature'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.runtime.reflect.LockSignatureImpl'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.lang.reflect.LockSignature'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.runtime.reflect.AdviceSignatureImpl'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.lang.reflect.AdviceSignature'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.runtime.reflect.CatchClauseSignatureImpl'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.lang.reflect.CatchClauseSignature'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.runtime.reflect.FieldSignatureImpl'
[AbstractServletLoggerTrace, request]: This is the request
[AbstractServletLoggerTrace, response]: This is the response
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.lang.reflect.FieldSignature'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.runtime.reflect.InitializerSignatureImpl'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.lang.reflect.InitializerSignature'
[EMAIL PROTECTED] debug weaving 'com.foo.test.Request'
[EMAIL PROTECTED] debug weaving 'com.foo.test.Response'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.runtime.reflect.SignatureImpl$Cache'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.runtime.reflect.JoinPointImpl$StaticPartImpl'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.runtime.reflect.SourceLocationImpl'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.runtime.reflect.JoinPointImpl'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.lang.NoAspectBoundException'
[EMAIL PROTECTED] debug cannot weave '
org.aspectj.runtime.internal.AroundClosure'
Exception in thread "main" java.lang.NullPointerException
at
com.foo.aspects.AbstractServletLogger.ajc$around$com_foo_aspects_AbstractServletLogger$1$c8fd8333proceed
(AbstractServletLogger.aj:1)
at com.foo.test.TraceTest.doGet_aroundBody1$advice(TraceTest.java:119)
at com.foo.test.TraceTest.doGet(TraceTest.java:1)
at com.foo.test.TraceTest.main(TraceTest.java:21)
When I do the same thing but put the pointcut in the aspect (and change it
from an abstract aspect to a concrete aspect in the code), it works fine,
e.g. here is an example of the concrete aspect code:
package com.foo.aspects;
import com.foo.test.Request;
import com.foo.test.Response;
public aspect ServletLogger {
public pointcut loggedGetOperations2 () : execution (void
com.foo.test.TraceTest.doGet(Request, Response));
void around () : loggedGetOperations2 () {
Object [] args = thisJoinPoint.getArgs();
Request request = (Request)args[0];
Response response = (Response)args[1];
System.out.println("[Trace, request]: " + request.getRequest ());
System.out.println("[Trace, response]: " + response.getResponse());
proceed ();
}
}
Can anyone tell me how to proceed? Thanks for any replies.
Cheers,
Craig
_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users