Skip to Content
author's profile photo Former Member
Former Member

unable to perform POST request on OCC REST controller

Hi, I implemented my own REST controller in my occ extension, but I unfortunately the POST method doesn't work. I receive the following error message:

Response Header:

 HTTP 405 Method Not Allowed
 Content-Type: application/json
 Content-Length: 136
 Server: Apache-Coyote/1.1
 Date: Wed, 14 Jan 2015 09:30:49 GMT

Response Body:

   "errors" : [
       "message" : "Request method 'GET' not supported",
       "type" : "HttpRequestMethodNotSupportedError"

The REST Controller looks like the following:

 @RequestMapping(value = "/{baseSiteId}")
 public class ProductController extends BaseController{
     @Resource(name = "defaultIDB2BProductFacade")
     private IDB2BProductFacade iProductFacade;
     private static final Logger LOG = Logger.getLogger(ProductController.class);
     @RequestMapping(value = "/products", method = RequestMethod.POST)
     public String insertProduct(@RequestParam(required = true) final String code) {
         return "test" + code;
     @RequestMapping(value = "/products/get/{code}", method = RequestMethod.GET)
     public ProductDTO getProductByCode(@PathVariable final String code) {
         if (LOG.isDebugEnabled()) {
             LOG.debug("getProductByCode: code=" + code);
         return iProductFacade.getProduct(code);

My REST call settings:

url: http://localhost:9001/rest/v2/powertools/products Request Body: Param Key: code, Param Value: fefeefef

For my surprise the get method in REST controller is working...


Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 14, 2015 at 11:14 AM

    Hi Raghavendra,

    I already use the advanced rest client plugin in chrome, but I still receive the same error message even I specified that I want to do a POST request... Should I configure some filters to be able to perform a post request?

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 14, 2015 at 10:50 AM

    Hi Dominik,

    As per the error and your code you are trying to access rest call in post method with a get method accessor, please change your rest call accessor to POST method, which will work.

    For trying this, you can rest tools like advanced rest client on chrome or rest client with ui dependencies.

    Else change the method type from RequestMethod.POST to RequestMethod.GET then it will work.



    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.