Announcement Announcement Module
Collapse
No announcement yet.
calling internal methods is not working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • calling internal methods is not working

    Hi,

    I am using springframework and i am trying to define some pointcut which doesn't work!!
    my Advice is not called....

    I have the following pointcut:
    <aop: pointcut id="testPointCut" expression="execution(* RetrieveDeviceInfoDL.doService(java.lang.Object))" />


    RetrieveDeviceInfoDL.java:
    Code:
    class RetrieveDeviceInfoDL extends ExternalSystemDataLayerBase {
           protected Object doService(Object input) throws ApplicationException
    	{
                     //....
                 }
    }
    ExternalSystemDataLayerBase.java:
    Code:
    public abstract class ExternalSystemDataLayerBase implements ExternalSystemDataLayer {
    	public final Object getData(DataObject input)
    	{
    		Object responseObject = doService(convertToExternal(input));
    		return responseObject;
    	}
    }
    ExternalSystemDataLayer.java:
    Code:
    public interface ExternalSystemDataLayer extends DataLayer
    {
    	public Object getData(DataObject aInputData);
    }

    This is NOT working!!!

    however,
    if i change the pointcut to the following (a thing that i DO NOT want!!) it works:
    <aop: pointcut id="testPointCut" expression="execution(* ExternalSystemDataLayerBase.getData(java.lang.Obje ct))" />


    Any ideas?
    is there a problem to define a pointcut on a methid that is called "internally" from within the same instance?

    Please advice/help ASAP.

  • #2
    Keep in mind:
    Spring AOP is Proxy based (uses Java Dynamic Proxies) which in your case means that when you retrieve an instance of ExternalSystemDataLayer (interface) what you actually get back is a Proxy which wraps your inheritance structure.
    So when you are getting ExternalSystemDataLayer from the ApplicationContext you get Proxy and all the calls to your methods are proxied , however internally (inside of Proxy) you are calling a method which is not proxied.
    Spring AOP does not do any code weaving. If you really want to achieve that level of granularity use AspectJ or other AOP frameworks (i.e., JBoss AOP) which do code weaving (load or compile time)

    Hope it explains.

    Comment


    • #3
      As explained in chapter 6.5.3 of the reference guide spring aop is a proxy based implementation of aop. Which means only public calls INTO the object (external method calls) can be intercepted.

      You have 2 issues here
      1. Internal method call
      2. protected method call.

      If you want to intercept internal method calls you need to use AspectJ (for instance) and loadtime or compile time weaving.

      Comment


      • #4
        1. Internal method call
        True
        2. protected method call.
        Not True

        That was a surprise for me as well (just tested it). Protected method was intercepted when called on the Proxy.
        Now, the caviat is that in my test it is a CGLIB proxy which means that I am not implementing any interfaces. Obviously if I did, then I would have to cast my Proxy to the Interface, thus would have no access to any methods other then public methods defined in my Interface.

        Comment


        • #5
          In the situation mentioned above those 2 situations are correct. He implements interfaces thus JDK Dynamic Proxies are used. I was talking about HIS specific situation.

          Comment


          • #6
            I agree,
            I actually didn't realize that myself until tested it, but it does make perfect sense.
            Cheers

            Comment


            • #7
              It does for a class proxy because a public/protected/default access method can still be called externally (be it from within the same package but it still is possible).

              Comment


              • #8
                Thanks guys
                that was helpful

                Comment

                Working...
                X