on 01-14-2015 10:42 AM
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
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.