Announcement Announcement Module
Collapse
No announcement yet.
How to get intercepted method name from my controller Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get intercepted method name from my controller

    Hi,

    I am new to springframework. I need to intercept my controller methods and based on the mathod name need to validate the user if he is eligible to see that page allow him or redirect him to another page.

    Using BeanNameAutoProxyCreator i am able to intercept my MainController Class but i am unable to identify the methodname.

    In my MethodInterceptor Invoke method
    I am getting the methodname as handleRequest

    invocation.getMethod().getDeclaringClass() + "::" + invocation.getMethod().getName()

    org.springframework.web.servlet.mvc.Controller::ha ndleRequest

    Please advice me how to get the methodname
    (eg) I need to get 'programIntroHandler' but my method interceptor is giving handleRequest....
    -------------------------------------------------------------------------------------
    My configuration is as follows

    <bean id="mainController" class="com.mwc.subscription.web.MainController">
    <property name="methodNameResolver" ref="mainControllerResolver"/>
    </bean>

    <bean id="mainControllerResolver" class="org.springframework.web.servlet.mvc.multiac tion.PropertiesMethodNameResolver">
    <property name="mappings">
    <props>
    <prop key="/default.htm">programIntroHandler</prop>
    <prop key="/lesson*/intro.htm">lessonIntroHandler</prop>
    </props>
    </property>
    </bean>

    <bean id="memberAccessAdvice" class="com.mwc.subscription.web.MemberAccessAdvice "/>
    <bean id="memberAccessAdvisor" class="org.springframework.aop.support.RegexpMetho dPointcutAdvisor">
    <property name="advice">
    <ref local="memberAccessAdvice"/>
    </property>
    <property name="pattern">
    <value>.*</value>
    </property>
    </bean>


    <bean id="beanNameProxyCreator" class="org.springframework.aop.framework.autoproxy .BeanNameAutoProxyCreator">
    <property name="beanNames">
    <list>
    <idref local="mainController"/>
    </list>
    </property>
    <property name="interceptorNames">
    <list><idref local="memberAccessAdvisor"/></list>
    </property>
    </bean>

  • #2
    In the way you had configured you your advice will be called on each externall call on the methods of com.mwc.subscription.web.MainController. The first call you will get will be on the method handleRequest and that's why you get the results you had described. Now you are expecting to get also a call on the method 'programIntroHandler' but this will not happen. Why ? Because the call is an internall call from your superclass and this call will not be adviced. This (internal calls not being adviced) is a known tradeoff done in the AOP implementation of Spring.
    I think that they way you want to implement the authorisation on the page is better addressed in some other way. Check out the Web part of the forum and if you do not find a soluton post a question related to the authorisation overthere. For example you can use another strategy for your controller implementation and use UserRoleAuthorisationInterceptor or write your own interceptor with the same logic you had in mind for com.mwc.subscription.web.MemberAccessAdvice.

    Comment

    Working...
    X