commit
commit

Reputation: 4807

Url in a path variable spring restful service

When I am passing email address as path variable it is throwing following error

    Console --> 2015-02-09 16:30:06,634 WARN  - GET request for "http://localhost:8181/abc/users/[email protected]" resulted in 406 (Not Acceptable); invoking error handler
Exception in thread "main" org.springframework.web.client.HttpClientErrorException: 406 Not Acceptable
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
    at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:607)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:565)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:521)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:439)
    at RestClient.main(RestClient.java:35)

I have tried lots of cases, so I finally found the problem with last domain like .com and .org which are internationalize domains. So instead of "[email protected]" if I pass "[email protected]" it will work perfectly fine.

My code is

@RequestMapping(value = "users/{emailId:.*}", method = RequestMethod.GET)
    public Object searchUser(@PathVariable("emailId") String emailId){
        logger.info("Inside search user --> emailId " + emailId);
        return userService.findUserByuserId(emailId);
}

Upvotes: 4

Views: 2048

Answers (1)

commit
commit

Reputation: 4807

I found no answer to this. I think it's an http rule we can't have domains at last in prameters and can make a request.

So work around to this is just pass a slash at the end of the url and there you go.

Like modify "http://localhost:8181/abc/users/[email protected]/" with "http://localhost:8181/abc/users/[email protected]". And thanks to spring rest architecture, it will automatically omit the last slash and you will get "[email protected]" as a parameter value.

Let me know if you guys find something else.

Upvotes: 4

Related Questions