Announcement Announcement Module
Collapse
No announcement yet.
How to redirect properly in RESTful Spring MVC controller? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to redirect properly in RESTful Spring MVC controller?

    I'm trying to implement a simple REST WS. When I'm trying to send PUT request to the handler of my controller all works fine

    Code:
        @RequestMapping(method = PUT,
                        consumes = "application/json",
                        headers = "content-type=application/json")
        public String updateCompany(@RequestBody Company company) {
            companyRepository.updateCompany(company);
            return "redirect:/api/company/" + company.getId();
        }
    Code:
        @RequestMapping(value = "/{id}", method = GET,
                        produces = "application/json")
        public @ResponseBody Company getCompany(@PathVariable("id") Integer id) {
            Company c = companyRepository.getCompany(id);
            return new CompanyToJsonWrapper(c);
        }
    I'm getting HTTP Status 405 - Request method 'PUT' not supported error. Any ideas how to fix it?

  • #2
    Could you provide us the HTTP requests and responses?
    What kind of HTTP client are you using?
    It looks like your HTTP client is sending a PUT request to the redirect location, when a GET is clearly necessary.

    This question is probably a better candidate for StackOverflow, perhaps with the "spring" and "spring-mvc" tags.

    Could you post your question there?
    The forums are moving to stackoverflow, a page explaining all this will be available there in a few days: http://spring.io/questions

    Comment

    Working...
    X