0

I have the following class as my point cut

   public class GenricExceptionMapper implements ExceptionMapper<Exception> {

Logger logger = Logger.getLogger(GenricExceptionMapper.class);
public Response toResponse(Exception exception) {
    logger.error(exception.getStackTrace());
    logger.info("Exception Thrown");
    String res="500 - Internal Server Error";
    exception.printStackTrace();
    logger.debug("Sending Http Response :"+res);
    return Response.status(500).entity(res).build();
}

}

and the following advice defined for it...

 @Aspect
 public class ExceptionMapperAspect {
Logger logger = Logger.getLogger(ExceptionMapperAspect.class);

//@Context HttpServletRequest servletRequest;

@AfterReturning( pointcut="execution(* toResponse(..))")
public void logExceptionAspect()
{
    //logger.info("statsKey in request object "+servletRequest.getAttribute("statsKey"));
}

when I try to run this I get the following exception error message..

**

Unable to find type arguments of interface javax.ws.rs.ext.ExceptionMapper

** The error is being thrown by this class http://grepcode.com/file/repo1.maven.org/maven2/org.jboss.resteasy/resteasy-jaxrs/2.2.2.GA/org/jboss/resteasy/util/Types.java#Types.getActualTypeArgumentsOfAnInterface%28java.lang.Class%2Cjava.lang.Class%29

part of RESTEasy code.

Is this because 'Spring AOP cannot advice pointcut class which implements a template interface'? Any ideas? How does Spring AOP create proxy objects for classes which implement parameterized interfaces?...does it use CGLIB or JDK Proxy?

CodePredator
  • 415
  • 2
  • 6
  • 14
  • I know this one is old, but still listed as unanswered. Would you please accept and upvote my answer if it seems appropriate? Thanks. – kriegaex Jun 09 '14 at 12:05

1 Answers1

0

I think your problem is somewhere else. I googled your exception

Unable to find type arguments of interface

and found it in connection with JBoss RESTEasy. Try to comment out parts of your class or aspect code until you find the culprit.

BTW, your implementation of toResponse returns a raw type. Make that Response<Exception> in order to be more type-safe and avoid the warnings.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
  • Hmmn....I forgot to mention,this error is being thrown by one of the classes of RESTEasy and not Spring AOP. – CodePredator Aug 31 '12 at 15:57
  • So what exactly is your problem now? I can help if it is aspect-related. Otherwise I am not an expert in app servers, containers etc., but I will try to help if I understand your real problem. – kriegaex Aug 31 '12 at 16:02
  • Ah, you just edited your question. Well, as I said, I think it is not aspect-related. What happens if you remove the advice? Does the error go away? And is your advice really a no-op? – kriegaex Aug 31 '12 at 16:08
  • Problem is when I have aspect-advice defined for a RESTEasy Exception Mapper..it gives me this Run-time exception while initializing the spring context.This is what I know. – CodePredator Aug 31 '12 at 16:08
  • In your question the advice does nothing, it is commented out. What exactly does the advice really do? I think your bug must be in the advice code, not in the advice as such. – kriegaex Aug 31 '12 at 16:11
  • Ok..the advice has to do some statistics collection...but as of now I have added just a logger to indicate that it has entered the logExceptionAspect()...I'm sure its not a problem with the code in advice.. – CodePredator Aug 31 '12 at 16:16
  • What happens if your advice does nothing, i.e. not use a logger? – kriegaex Aug 31 '12 at 16:17
  • And one more question: Have you corrected the return type of `toResponse` to `Response` as I suggested in my initial answer? – kriegaex Aug 31 '12 at 16:29
  • Response is not the return type of toResponse...Response class is not parameterized.....have a look at it [here](http://grepcode.com/file/repo1.maven.org/maven2/org.jboss.resteasy/jaxrs-api/2.2.1.GA/javax/ws/rs/core/Response.java#Response) – CodePredator Sep 07 '12 at 11:41
  • You are absolutely right. When I tried to reproduce your situation I did not want to download any Java EE stuff or find the right JAR, so I faked the interface in my test project. And my little version of the interface had `Response` as its return type. Sorry for that. Later I did not look at the interface anymore, only at the rest of the code, and forgot that I did not have the original, thinking I had reproduced it correctly. – kriegaex Sep 07 '12 at 19:30
  • Anyway, you did not react to my question, there still is no full stack trace. And sorry, one week response time is just too long if you really need help. It takes too much time to switch back into the topic after such a long time, I am out of here. – kriegaex Sep 07 '12 at 19:32