Creating Liferay webservice project

In this tutorial I will show step-by-step how to create a Liferay plugin project. This plugin project is all about creating webservice in liferay.

Prerequisites

Liferay Developer Studio 1.4, Liferay 6
1. Start the Liferay Developer Studio 1.4 and select File -> New -> Other. In the wizard select Liferay -> Liferay Project. Click on Next.

2. In the next step input the Project Name – “NewPlugin”; Display Name will automatically be populated.

Make sure that Liferay Plugins SDK and Liferay Portal Runtime are correct in Configuration section.

Select Plugin Type as Portlet. Click on Next.

3. In the next screen select Liferay MVC for ‘Select portlet framework’. Click on Finish.

4. After neccessary things are generated you will see the project name as “NewPlugin-portlet”. This “-portlet” is automatically apended to the given project name.

5. Now we will create Liferay Service. Do right-click on the NewPlugin-portlet project and go to New -> Other. Select Liferay -> Liferay Service Builder. Click on Next.

6. Type mandatory fields Package path: and Namespace:. You may or may not “Include sample entity in new file”. Click on Finish.

7. Now open the service.xml from docroot->WEB-INF->service.xml. If you have checked “Include sample entity in new file” then you do not need to create any entity in service.xml file otherwise you may write the entity as shown below:

creating webservice in liferay

8. Now go to the Overview tab of service.xml file and click on Build Services.

9. Once the service building is over you will see there are several packages, classes etc. generated under docroot/WEB-INF/src

Please note that this service building process is only once. Next time whatever changes will be made we will build the WSDD every time.

10. Now open the NewEntityServiceSoap.java class. You will see this is blank class. So whatever business logic you want to write you have to write here. You can also use the liferay’s several util classes.

Here I will show one example how to call liferay’s util class. Suppose you want to retrieve all the user groups available in liferay. So here is the logic.

creating webservice in liferay

Liferay has some limits on SOAP like liferay cannot return list of objects ao we have to return array of objects; we cannot also return the object of type UserGroup so we have to return object type of UserGroupSoap.

11. Now build WSDD in service.xml file on Overview tab.

12. You will see aother two files ending with .wsdd created under in.sblog.service.http.

13. Now we need to test the service. So start the tomcat server if it has not been started already. Once the tomcat server started successfully drag the NewPlugin-portlet project and drop on the tomcat server. Other way you can deploy the service – do right-click on the NewPlugin-portlet project and go to Liferay->SDK->deploy.

Once deployed you will see in the server console “1 portlet for NewPlugin-portlet is available for use”.

14. Now go to the server console and expand the server tree. Do right-click on NewPlugin-portlet and click on “Test Liferay Webservices”. In the “Web Service Selection” wizanr select “Plugin_sblogin_NewEntityService”. Click “OK”.

15. You will see Web Services Explorer opens in the Studio. Now click on “getAllUserGroups”  in Navigator pane and clock on Go on Actions pane.

16. You will get the results in the status pane. You can also see the source view by clicking on “Source”.

The URL for wsdl will be http://localhost:8080/NewPlugin-portlet/secure/axis/Plugin_sblogin_NewEntityService?wsdl

The tutorial Accessing Liferay webservice remotely I will show you how to call this webservice from java code.

Thanks for your patience. Please do not forget to leave a comment.

Soumitra

Software Professional, I am passionate to work on web/enterprise application. For more information please go to about me. You can follow on Twitter. You can be a friend on Facebook or Google Plus or Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.