I need to extend an existing Liferay webservice (created with Service Builder) to handle an additional optional parameter.
With Service Builder, you have to specify every parameters inside the method signature:
public String getList(String param1){ .. }
This creates a get-list
web service accepting a parameter named param1
. You have to specify every parameters when making the call or else the call will fail. If you need optional parameters, just pass an empty value and handle the missing parameter inside the code.
My problem is backward compatibility: this web service is already used by a mobile app and I cannot change the call made by the app. The additional parameter must be handled without changing the method signature.
Taking a look at BaseServiceImpl, I tried to obtain the parameter in this way:
HttpServletRequest request = com.liferay.util.axis.ServletUtil.getRequest();
String value = ParamUtil.getString(request, "param-name");
But it throws a NoClassDefException
regarding com.liferay.util.axis.ServletUtil
.
Is there a way to actually do this?
To enhance and retain backward compatibility of your code, one way is to overload
getList()
method which accepts additional parameter. You can achieve this by following:getList()
togetList(String param1)
method.param1
ingetList(String param1)
to handle case when parameter is not null / empty.getList(null)
fromgetList()
.While you can call
getList(String param1)
directly when you require to pass additional parameter.Original method:
Overriden method: