2

I have a springboot rest controller:

@RestController
public class UserController {
    @Autowired UserRepository userRepository;

    @RequestMapping(value = "/account/{userid:.+}", method = RequestMethod.GET)
    public HttpEntity<Account> getAccountByUserId(@PathVariable String userid) {
        if(userid == null) {
            return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
        }
        Account user = userRepository.findOneByUserid(userid.toLowerCase());
        if(user == null) {
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }
        return new ResponseEntity<>(user, HttpStatus.OK);
    }
}

Note the @PathVariable definition is slightly weird because Spring MVC @PathVariable with dot (.) is getting truncated.

This call works perfectly and i receive a 200 status code with lovely json: http://.../account/scarlett.j@myplace.com

However this call http://.../account/scarlett.j@myplace.com.au returns status code 406 and debug logs show the message "org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation"

Why and how do i fix it? Thanks.

Community
  • 1
  • 1
Richard
  • 353
  • 1
  • 2
  • 15
  • 1
    My guess is that Spring's content negotiation is kicking in on the .au - easy way to test would be to turn off content negotiation and see if you still get the error. – rhinds May 18 '15 at 18:19

0 Answers0