As an example, take subdomain mapping.
This article: Managing multiple Domain and Sub Domain on Google App Engine for Same Application
recommends to resolve subdomain on Filter and assign variable to ServletRequest headers.
Then the mapping will look like this:
@RequestMapping(value = "/path", headers="subdomain=www")
public String subsiteIndexPage(Model model,HttpServletRequest request) { ... }
If we’d like to create custom @RequestMapping property, such as subdomain, eg. to create mapping like this:
@RequestMapping(value = "/some/action", subdomain = "www")
public String handlerFunction(){ ... }
we should override @RequestMapping @interface definition and override RequestMappingHandlerMapping protected methods, with our own implementation
(as stated on JIRA: “Allow custom request mapping conditions SPR-7812“).
Is it right? Can anybody provide a hint, how to achieve this functionality?
Idea 1:
As suggested on original jira thread, is to create own implementation of RequestCondition
There is an project which uses this solution available on github: https://github.com/rstoyanchev/spring-mvc-31-demo/
And related SO question: Adding custom RequestCondition's in Spring mvc 3.1
Maybe mapping like @Subdomain("www") for both Type and Method, is possible solution?
I’ve created solution based on referenced spring-mvc-31-demo
This solution uses custom @RequestCondition feature of Spring 3.1.1.RELEASE platform
USAGE
Example 1:
Example 2:
We need three files
SubdomainMapping.java
SubdomainRequestCondition.java
SubdomainRequestMappingHandlerMapping.java
Instalation
SubdomainRequestMappingHandlerMappingclassRequestMappingHandlerMappingOR
Replace the registered
RequestMappingHandlerMapping(possibly on order=0)For more wide explanation on implementing this solution, see the related github project