Build Liferay web service with optional parameter

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?

--------------Solutions-------------

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:

  1. Move your general pre-logic code of getList() to getList(String param1) method.
  2. Add filter for param1 in getList(String param1) to handle case when parameter is not null / empty.
  3. Call getList(null) from getList().

While you can call getList(String param1) directly when you require to pass additional parameter.

Original method:

public String getList(){
return getList(null);
}

Overriden method:

public String getList(String param1){

if(param1 != null){
// logic for param1
}

// rest of your general code
}

Category:java Time:2018-11-05 Views:1

Related post

  • Building a web service with Perl 2012-01-31

    I need to build a server-side application (tiny web service) for testing proposes. What are some CPAN modules and Perl libraries for implementing such task? --------------Solutions------------- There are a lot of possibilities CGI - if you like to do

  • Building a web service: what options do I have? 2010-12-07

    I'm looking to build my first web service and I would like to be pointed in the right direction right from the start. Here are the interactions that must take place: First, a smartphone or computer will send a chunk of data to my web service. The web

  • consume wcf web service with List parameter by ksoap2 2011-04-30

    there is wcf web service, EnforceType is an enum type: [OperationContract] string TestList(List<EnforceType> enforceType); how to consume this wcf web service by ksoap2? Thanks for any help. --------------Solutions------------- this links helpe

  • How to build WCF REST services with .NET 3.5 and Visual Studio 2010? 2010-10-10

    I'm about to build some RESTful web services using WCF and .NET 3.5 in VS2010. I've not done this before so am looking for some pointers as to the easiest approach. For deployment reasons I cannot use .NET 4 but must stick with .NET 3.5 SP1. It seems

  • Calling a WebMethod from a web reference with optional parameters in C# 2011-10-28

    I have created a dummy web service with 2 optional parameters using the .Net Webservices, however in the real product we are going to have a lot more optional parameters(think: filters for a query). The problem is that it is not possible to leave out

  • Connect to .Net Web Service with iPhone SDK 2009-09-18

    I need to use a web service to be able to sync my iphone app with my Asp.Net website. Data needs to be sent both ways. I haven't started building the web service nor the client yet so before I start, what's the best way to do it? Using SOAP, REST? I

  • Calling .net web service with complex parameters 2009-09-21

    I have seen many examples of json web services with WCF in asp.net that accept one in-parameter. I need my service method to accept many parameters and return a list like this; This is my Service.svc: public class Car { public string Title; public in

  • Flex Builder Import Web service errors in autogen code 2009-10-08

    I'm trying to import a web service with the Flex builder feature (Data > Import Web Service). The process proceeds as expected and the classes are generated based on the web service description. The code is generated with compile errors in it thou

  • Web Services with Android - why no support for WSDL? 2010-06-09

    I'm creating a Client/Server application with Android (Client) and WCF (Web Service). From reading quite alot of discussions, I'm under the impression that there is no tool available to create the web service client in android automatically from a WS

  • web service with glassfish v3 2010-07-08

    I am using JSF 2.0, Spring, Hibernate and GlassFish v3 server and I need to make webservice and I am totally new to webservice can anyone suggest what kind of webservice I should go for... --------------Solutions------------- This question is very va

  • Web Service: Single String Parameter Or Complex Type Parameters 2010-08-16

    Is it more or less acceptable (i.e. standard) to create a publicly-exposed web service with these method signatures: ThisMethodDoesSomething(ComplexType param) ThisMethodDoesSomethingElse(AnotherComplexType param) Or this: ThisMethodDoesSomethingAndS

  • Create a web service with XML response 2010-10-04

    What is the easiest way to create a web service with XML response? Use WCF to create the web service? (seems really complicated) If i want to use WCF to create my web service, where do I start? --------------Solutions------------- In your case, I wou

  • Why use a web service with ajax over a static page method? 2010-12-03

    I'm building an aspx page that uses jquery ajax to post values, which are processed by a code behind page, and passed back via Json. I've created a webservice to do this but am I better using a static method on the page to do this? What are the pros

  • how to write a web service with soap 2011-02-27

    I have a web service (client-server) written in java. With help of that user can upload a file and generate another output file. Now I want to do the same thing with soap(i mean server - server).But I have no idea how can I do that. Can someone help

  • How to expose a web method with Func parameter? 2011-04-25

    I wonder if I could expose a web method with Func parameter! [WebMethod] public List<Entity> ReadEntities(Func<Entity, bool> predicate) { using (var entities = new GwEntities()) return entities.Entities.Where(predicate).ToList(); } When I

  • I get these errors trying to build a web service client in Ruby 2011-06-14

    I am trying to build a web service client in Ruby. When I try to invoke the following soap4r ruby script to generate web service client code: wsdl2ruby.rb --wsdl *[web_service_url]* --type client I get the following error: ignored attr: {http://www.w

  • Web service with large result 2011-07-04

    We're building a web service and anticipate that there could be substantial data being returned. How will ASP.Net and IIS 6 handle this? What kind of things can we do to make this less resource intensive? For example, we currently have a serializable

  • How do you consume a SOAP web service with Java? 2011-08-16

    I am required to consume a SOAP web service with a Java program I am writing. I have a basic test .NET service on my server in a .asmx file. There are a bunch of complicated examples that I found on Google but can someone provide a short explination

  • Publishing a web service with Bonjour 2011-09-13

    The scenario I am building a hybrid app, using Phonegap. I have an SQLite database (students) with a table(namelist) containing list of names inside the project. From JavaScript, I can't execute an SQL query. The need On a button click event in the U

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 0.577 (s). 13 q(s)