2

I have an URI https://localhost/Message/message?id=10 and it will give the message details with id=10.

I want to get the same response when I entered the URI as below (here path variable is with different case)

 https://localhost/Message/message?id=10 
 https://localhost/Message/Message?ID=10 
 https://localhost/Message/mEssage?Id=10 
 https://localhost/Message/MESSAGE?iD=10 
Shashwat
  • 2,342
  • 1
  • 17
  • 33
user3386700
  • 21
  • 1
  • 3

1 Answers1

2

For the URI/PathVariable (Message) name: Spring 4.2+ supports configuration of case-insensitive path matching. You can configure it as follows:

@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        AntPathMatcher matcher = new AntPathMatcher();
        matcher.setCaseSensitive(false);
        configurer.setPathMatcher(matcher);
    }
}

For the @RequestParam/request parameters (ID) part:

You have to do it manually - there's no support in Spring Boot for this out of the box. The base concept is that you have to implement a custom servlet filter, which standardizes the params in HttpServletRequest - e.g. you can apply to all of them String.toLowerCase() before passing them down to your @RestController, where you have all the request parameter binding defined as lower-cased values.

hovanessyan
  • 30,580
  • 6
  • 55
  • 83
  • The `WebMvcConfigurerAdapter` has been deprecated in spring 5. is there any spring 5 compatible way of doing this? – Urosh T. Oct 24 '18 at 12:19
  • @UroshT.yes - they deprecated the abstract adapter class in favour of default methods in the interface - just use the interface WebMvcConfigurer. – hovanessyan May 11 '20 at 15:18