Nilesh Agrawal
Nilesh Agrawal

Reputation: 3042

How to know which methods are invoked in java?

Is there any way to know which methods are getting invoked in Java during run time. Actually I am trying to detect those methods which are getting invoked and according to those methods that are invoked use Java Reflection APIS to invoke another method from another classes. In this way I want to divert the execution to my methods first and then call those running methods.

e.g

//Method Invoked_Method = "get the invoked method here "

   if(Invoked_Method.equals("somemethodName"){
   //invoke Another method ..
   }

Although its a security breach, but I am working in team for security products. So have to experiment this.

Upvotes: 2

Views: 335

Answers (2)

ATG
ATG

Reputation: 1707

You may want to consider AOP: http://aopalliance.sourceforge.net/

This allows you to intercept method calls that match a particular expression and enhance or change the default behaviour of the method.

If you're already using them, the Spring and Guice frameworks provide ways to leverage AOP relatively easily.

Upvotes: 2

Genocide_Hoax
Genocide_Hoax

Reputation: 853

I suppose what you are saying is you need to trace the callstack at runtime. I found a thread regarding this. Check this out

Upvotes: 0

Related Questions