0

I have some Sprint controller Mapping like below.

@GetMapping("/hello/{name}/age")
    private String hello(@PathVariable(value = "name", required = true) String name){
        //...
    }

   @GetMapping("/hello/{name}")
    private String hello(@PathVariable(value = "name", required = true) String name){
        //...
    }

    @GetMapping("/name")
    private ResponseEntity<?> queryPerson(@RequestParam(value = "query", required = false) String query) {
        // ...
    }

But there is a client expetection to handle the below case

when client sends /hello/john/age, I should return age related pojo but when client calls /hello//age I have to return 400 with invalid user name as error.

Since im my code I already have other mapping hello/{name} so it is calling this API and trying to find username='age' and returing 404.

Here I am suppossed to 400 when user calls /hello//age, so how to handle this in spring?

1 Answer 1

1

There will be no chance to create a 400.

Tomcat is collapsing the double slashes:

http://mail-archives.apache.org/mod_mbox/tomcat-users/201912.mbox/%[email protected]%3E

Sign up to request clarification or add additional context in comments.

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.