cancel
Showing results for 
Search instead for 
Did you mean: 

unable to perform POST request on OCC REST controller

Former Member
0 Kudos

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:

 @Controller
 @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)
     @ResponseBody
     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...

Greetz

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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?

raghavendra_desu
Contributor
0 Kudos

As per the error, you are trying to send a get method type only. Error 405 is specific to this problem only, no need to configure any special filters. Have you tried the second solution, Else change the method type from RequestMethod.POST to RequestMethod.GET then it will work.

Former Member
0 Kudos

Most probably you have the configuration: intercept-url pattern="/**" requires-channel="https" and you are accessing with http://localhost:9001. That means, you will get redirected from http:// localhost:9001 to https://localhost:9002, but the original method with which you've done the call is not passed in the redirect, hence the GET method working, and not the POST one. Either enable http, or access occ with https.

Answers (1)

Answers (1)

raghavendra_desu
Contributor
0 Kudos

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.

Regards,

Raghavendra.