spring mvc get mapping controller method from interceptor -


now have controller this

@requestmapping("/content/delete.json") @security(auth = authtype.required) public modelandview deleteindex(user user, @requestparam("id") long id) {  } 

now trying controller mapping method interceptor , getting annotation of method.

method method = restrequesturlutil.getinvokedmethod(handler, request); security security = method.getannotation(security.class); if(security.getauth() == authtype.required) {     validate here } 

are there classes restrequesturlutil in spring?

thanks in advance :)

edit:

web.xml

<servlet>     <servlet-name>rest</servlet-name>     <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class>         <init-param>             <param-name>contextconfiglocation</param-name>             <param-value>                 /web-inf/rest-servlet.xml,                 /web-inf/interceptor-servlet.xml             </param-value>     </init-param>     <load-on-startup>1</load-on-startup> </servlet>  <servlet-mapping>     <servlet-name>rest</servlet-name>     <url-pattern>/</url-pattern> </servlet-mapping> 

interceptor-server.xml

<mvc:interceptors>     <mvc:interceptor>     <mvc:mapping path="/**" />     <bean class="com.test.web.interceptors.securityinterceptor" init-method="init">      ...     </bean> </mvc:interceptor> 

the annotation on controller's method can inspected in interceptor means of handlermethod object framework should pass handler object.

if (handler instanceof handlermethod) {     handlermethod method = (handlermethod) handler;     if (method.getmethod().isannotationpresent(security.class)) {        //do processing     } } 

however, according spring documentation in handlermethod javadoc, handlermethod class introduced in spring 3.1. seems that, in versions prior 3.1, handler object controller instance, makes fetching annotation of invoked controller method difficult.

you can either upgrade 3.1. , fetch annotation handlermethod object or attempt parse requestmapping annotations on controller methods , attempt determine method invoked comparing requestmappings request uri.

if upgrade not option, alternative use aop instead of mvc interceptor.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -