Let's talk again about Liferay REST services and let's see how to change the HTTP method these services are exposed; each REST service is in fact mapped to a specific HTTP method, GET or POST.
All Java methods (from the remote services layer) that begin with the prefix get
, has
or is
are assumed to be read-only and automatically mapped to the GET method; all other methods are exposed with the POST method instead.
But sometimes it can happen to have read-only Java methods that start with a different prefix (e.g. count
) and Liferay exposes them with the POST method. Change the HTTP method, however, is very simple: just use the JSONWebService
annotation already seen, on the Java method involved:
@JSONWebService(method = "GET")
public boolean countSomething(…)
But there's more, because Liferay does not check by default the HTTP method the REST services are invoked and so you can invoke them in any way, without any control; you can force Liferay to work in strict mode, using the correct HTTP method, just setting the following property:
jsonws.web.service.strict.http.method=true
Finally let's remember that you can disable even only specific HTTP methods, setting the following property:
jsonws.web.service.invalid.http.methods=DELETE,POST,PUT