Service
Architecture on Liferay Project - Multiple service.xml file
Top of Form
12/20/12 8:35 AM
The best place to learn Liferay Architecture is the Liferay source code
itself. When it comes to creating services in Liferay Usually people create one
monolithic service.xml in docroot/WEB-INF folder. Well... that is not the right
approach if the number of custom services you intend to develop is large. In
one of my projects that I am currently working on, I have 10s of services. The
best approach is to create one package structure for each service for e.g.
com.mslc.projectname.conceptualnameofservice and create a service.xml file in
this package. Different services will have different package structure. You can
very well build these services exactly as same as you build services in WEB-INF
folder; more conviniently if you have Liferay IDE. Take a look at Liferay
source code and scan through the service.xml files they have create in
portal-impl/src folder under package structures like com.liferay.portal,
com.liferay.portlet.blogs, com.liferay.portlet.journal etc.
So far so good. But then when you run build-wsdd target in order to
generate the service-config.wsdd file in order to expose your service as web
service, then you run into problems. By default the build-wsdd target looks for
service.xml file in docroot/WEB-INF folder. As mentioned above, the service.xml
file can be created in their respective package structure so we do not have
service.xml file in docroot/WEB-INF which is expected by build-wsdd. So what do
we do ? Here is the solution
1.open
sdk/build-common-plugin file
2.search for target
build-wsdd
3.you will find one
argument called wsdd.input.file in the line which looks like this:
I. <argvalue="wsdd.input.file=docroot/WEB-INF/service.xml"/>
4.Change the value to
${service.input.file} . This is how
the line will look like after changes
Save the file and run build-wsdd on respective service.xml file. It
works like a charm - it generates service-config.wsdd in WEB-INF folder
perfectly for each service you build the wsdd for.
How to expose Finder methods from service to LocalServiceUtil in liferay portal
In liferay portal if we want to find records from table then we need finder methods. To create finder method we need to specify the finder tag in the service.xml file.
Assume that we have a database table named customer having fields like name, city, age etc. We want to find all the customers belonging to a particular city.
Following are the steps to create finder method for the above requirement-
1. In the service.xml file add the following line after database columns declarations,