Search This Blog

Monday 9 December 2013

How to expose Liferay Service as a Soap Web Service

Having spend myself a reasonably good amount of time in various issues ,hereby , i have shared my understanding of -'How to expose Liferay Service as a Soap Web Service'

I used Liferay6.1.1 source and Plugin-SDK(liferay-plugins-sdk-6.1.1-xx) along with eclipse juno The base platform was Java1.7.x and MySQL5.1..x.
The deployment server was Liferay-bundled-JBoss GA3. (liferay-portal-jboss-6.1.30-ee-ga3-xx)

Assuming that you are already thru the following steps mentioned below :
Step 1: Setup liferay source project and tomcat/JBoss/etc
Step 2: Setup plugin SDK.
Step 3: Create the service project (say i gave the project-name as 'cab_portletname')
Step:4 Create a new liferay-service builder file (service.xml)

Now, you can expose the liferay-service to any of the available Entities (Entities you mentioned in the service.xml).
Lets say you created an entity named- 'CABDisplay' && namespace as -'CAB' as below:-
---------------------------------------------------------------------------
<namespace>CAB</namespace>
<entity name="CABDisplay" local-service="true"
remote-service="true">

<!-- Primary Key -->
<column name="SammNo" type="long" primary="true" />
<!-- Audit fields -->
<column name="OrganizationName" type="String" />
<column name="Field" type="String" />
</entity>
---------------------------------------------------------------------------
Step:5 Save this service.xml && run the 'CABDisplay-Portlet/build-service' task.(say 'ant clean build-service' from command-prompt ,etc)
If the build fails, please check if your service.xml for any syntax-error (also, check the console & act accordingly). On successful build, the ant task creates the files related to CABDisplay entity.
You can now refresh your project (F5) to see the generated files.

Step:6 Incase you wanna expose any of the default liferay-services generated for you entity(you can check the same in the your serviceImpl -say 'CABDisplayServiceImpl' in our case)
Now Add the CRUD and finder methods into your com.liferay.test.service.impl.CABDisplayServiceImpl as listed below:
---------------------------------------------------------------------------------------
public CABDisplay fetchMetadataBySammNo(long sammno){

return cabDisplayLocalService.fetchCABDisplay(sammno);
}
---------------------------------------------------------------------------------------
public CABDisplay createCabDisplay(long sammno){

return cabDisplayLocalService.createCABDisplay(SammNo);
}
---------------------------------------------------------------------------------------

Step:7 Now you need to run the 'CABDisplay-Portlet/build-wsdd' task to generate the webservices..(say 'ant build-wsdd' from command-prompt ,etc)
Now you can simply deploy the portlet

Step:8 Now, type the following composed url in the browser && check the respective web-services exposed along with thier wsdl - "http://host/portletname-portlet/api/axis"

In our case the url will be  - " http://localhost:8080/cab_portletname-portlet/api/axis " ,which will show you all the services exposed for this respective Portlet..

where, you can check the value of 'cab_portletname-portlet' from the following locations in case of JBoss App Server "jboss-7.1.1\standalone\deployments\" &&
 "tomcat-7.x.x\webapps\" folder in case of TOMCAT App Server.

Step:9 hence, you have successfully exposed your custom liferay-services avaliable as a web service. Now in case you wanna consuming the same-- you can simply build a client using the above wsdl and consume the same...!!! ;-)

No comments:

Post a Comment