Wednesday, 25 September 2013

Service Architecture on Liferay Project 



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:

    1. <arg value="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
    1. <arg value="wsdd.input.file=${service.input.file}" />
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.
Want to architect your services with Custom (Non-Liferay) database, custom transaction and custom session factory 

No comments:

Post a Comment