I think best approach is to bind a HandlerInterceptor to the path "/api/vi/catalog".
Here is an example Interceptor returns 404 response if parameter is not set to product:
@Component
public class ProductInterceptorHandler implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (!request.getParameter("type").equalsIgnoreCase("product")){
response.setStatus(404);
// DO WHATEVER YOU WANT TO INFORM USER THAT IS INVALID
return false;
}
return true;
}
}
And you should bind it to the path inside your configuration class (in my case a SpringBootApplication that extends WebMvcConfigurerAdapter):
@SpringBootApplication
public class ASpringApplication extends WebMvcConfigurerAdapter implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(ASpringApplication.class, args);
}
@Override
public void addInterceptors(InterceptorRegistry registry){
registry.addInterceptor(new ProductInterceptorHandler()).addPathPatterns("/api/vi/catalog");
}
}
And finally a restcontroller method:
@RequestMapping(value = "/api/vi/catalog", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> searchLocationIndexed(@RequestParam("type") String type ) throws Exception {
return ResponseEntity.ok("ok");
}
http://localhost:8080/api/vi/catalog?type=productcan have method A andhttp://localhost:8080/api/vi/catalog?ty=productcan have method b`