Skip to Content
0
Former Member
Jan 14, 2015 at 10:42 AM

unable to perform POST request on OCC REST controller

697 Views

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