8

I need to map interceptor for all methods in annotated controller with @RequestMapping(value = "/client")

In mapping I have

<mvc:interceptor>
   <mvc:mapping path="/app/client/*"/>
   <bean class="com.cci.isa.web.CIPClientHandleInterceptor" />
</mvc:interceptor>

This interceptor called perfectly for urls like:
1. http://host/app/client/clientUpdateForm?clientId=305

But doesn't called for urls like:
2. http://host/app/client/clientUpdateForm/clientId_305 (with slash after method name)

How get it called for second variant?

Thanks a lot.

1
  • If you are using @RequestMapping annotation then I can't see why you are also specifying a mvc:interceptor. Just use <mvc:annotation-driven />... Commented Aug 5, 2011 at 10:42

5 Answers 5

6

This question is too old, but maybe this helps somebody.

You should try removing /app, I think it's not necessary and perhaps this is causing the problem.

<mvc:mapping path="/client/**"/>
Sign up to request clarification or add additional context in comments.

Comments

2

I think this will achieve what you would like:

<mvc:mapping path="/app/client/**/*"/>

The '/**' suggests any number of directories. When this is used in conjunction with '/*', you have something that looks at an arbitrary folder depth, with an arbitrary file name.

2 Comments

No, interceptor doesn't called.<br/> I tried use next combinations of path:<br/> /app/client/**/*<br/> /app/client/**<br/> /app/client/*/*<br/> No one of this variants doesn't call interceptor.
I am getting this error: Element mvc:mapping is not allowed here. Any solution for this?
1

If your controller with

@RequestMapping(value = "/client")

Try

<mvc:mapping path="/client**"/>

Comments

0

Try the above suggestion but change the annotation to

@RequestMapping(value = "/client*")

Although I would use two methods for each of the two URI patterns and pass them to the one common method to do the "stuff"...

@RequestMapping(value = "/app/client/clientUpdateFormat/{clientId}", method = RequestMethod.GET)
 public String doItOne(@PathVariable("clientId") String clientId) {
    doItCommon(clientId);

and

@RequestMapping(value = "/app/client/clientUpdateFormat", method = RequestMethod.GET)
 public String doItTwo(@RequestParam("clientId")  String clientId) {
    doItCommon(clientId);

Comments

0

My problem was, that we used custom RequestMappingHandlerMapping

<bean name="handlerMapping" 
class="utils.web.versioning.MobileVersionRewritingMappingHandler">
    <property name="order" value="0"/> 
    <property name="interceptors"> 
        <list> 
          ...
        </list> 
    </property>  
</bean>

XML or code config for CORS or any other MVC properties doesn't affect custom handler mappings. I could specify cors config for custom handler mapping, but I prefer to remove legacy config and use this to configure interceptors:

 <mvc:interceptors>
  ...
 </mvc:interceptors>

Now cors is working and I'm using XML global cors configuration.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.