0

I'm wondering is there any way to make a Spring AOP Proxy for the java.security.KeyStore, there are few obstacles here:

  • KeyStore does not have default constructor
  • All methods of KeyStore are final

I know that it is impossible to make a Spring AOP Proxy with the above constraints, but anyway I need to somehow count the method invocations of the KeyStore in the application. Could anybody suggest some way to bypass the Spring AOP constraints or another way?

sanastasiadis
  • 1,182
  • 1
  • 15
  • 23
erkfel
  • 1,588
  • 2
  • 17
  • 29

1 Answers1

0

If you have control of the calling code - and hopefully you do because it is your own application you are talking about - and are willing to use full AspectJ (which does not need any proxies) instead of Spring-AOP, you cann use a call() pointcut instead of being limited to Spring-AOP's execution() pointcut. The pointcut would look something like this (untested, hacked from memory):

@Pointcut("call(* java.security.KeyStore.*(..))")

If you want to extend the pointcut to subclasses, add a + after the class name:

@Pointcut("call(* java.security.KeyStore+.*(..))")

You can even intercept constructor calls if they come from code you can weave into:

@Pointcut("call(java.security.KeyStore+.new(..))")
kriegaex
  • 63,017
  • 15
  • 111
  • 202
  • thanks for the answer, it could be a solution. One more question - is that possible to intercept the calls to specific instance of the KeyStore? I have a few, but interested in only one – erkfel Oct 09 '14 at 19:07
  • Possibly. I would need more insight into your code for being able to answer that question. – kriegaex Oct 09 '14 at 19:25