Sunday, July 21, 2013

Accessing Liferay Web Service with Liferay Portal Client

During development, Liferay developers might want to access to Liferay information, eg, user details.
But it is not suppose to access to Liferay database directly.
thus, Liferay exposed a list Web Services for us to access through Liferay Portal Client

Liferay's services could be accessed through local API, for more details, please refer here.

Requirement:
1. Liferay Portal 6.1.1 ga2
2. Liferay Portal Client 6.1.1 ga2
3. Eclipse Juno
4. Liferay Development environment has been setup


Steps:
1. Start Liferay Portal

2. Once Liferay started, access the following url to test the Web Service availability.
    http://127.0.0.1:8080/api/axis
    If Web Service available, the page will list all the exposed Web Services and methods in each service.
Liferay available web services

3. Download Liferay Portal Client 6.1.1 ga2.

4. Add all Liferay Portal Client jar into project classpath.
Liferay Portal Client library

5. Accessing Liferay Web Service with the following codes
String userServiceUrl = "http://USERNAME:PASSWORD@localhost:8080/api/secure/axis/Portal_UserService";
UserServiceSoapServiceLocator userLocator = new UserServiceSoapServiceLocator();
UserServiceSoap userSoap = userLocator.getPortal_UserService(new URL(userServiceUrl));
UserSoap soapUserModel =  userSoap.getUserById(2);
System.out.println("email: " + userSoap.getEmailAddress());
note: @ is not allowed in the PASSWORD.

6. to access other services, check the available services list in step 3, and make modification to the above code in step 5.


Done!!

LinkWithin

Related Posts Plugin for WordPress, Blogger...