You can find Liferay’s services by searching for them in the Javadocs: http://docs.liferay.com/portal/6.2/javadocs/. Below, we’ll show you how to search for portal services and portlet services.
Let’s start by finding a portal service.
Finding Liferay Portal Services
Liferay’s Javadocs are easy to browse and well-organized. Here’s how to find the Organization services:
In your browser, open up the Javadocs: http://docs.liferay.com/portal/6.2/javadocs/
Under Portal Services, click on the link for the
com.liferay.portal.servicepackage, since the services for the Organization entity belong to the Portal scope.
Find and click on the
*ServiceUtilclass (in this case,
OrganizationLocalServiceUtil) in the Class Summary table or the Classes list at the bottom of the page.
That was easy! What if you want to find portlet services?
Finding Liferay Plugin Services
Searching for one of Liferay’s built-in plugin services is also easy. Instead of clicking the link for the service package of the portal, click the link for the service package of the portlet. The portlet service packages use the naming convention
[portlet-name] is replaced with the actual name of the portlet.
Here’s how you find services for a user’s blogs statistics:
In your browser, open the Javadocs: http://docs.liferay.com/portal/6.2/javadocs/
Under Portlet Services, click on the link for the
com.liferay.portlet.blogs.servicepackage in the Packages frame, since the services are a part of the Blogs portlet.
Find and click on the
*ServiceUtilclass (in this case
BlogsStatsUserLocalServiceUtil) in the Class Summary table or the Classes list.
Now you’re ready to invoke Liferay services. To invoke Liferay services remotely, your Liferay instance must be configured to allow remote web service access. Please see the Understanding Liferay’s Service Security Model tutorial for details.
Invoking Liferay Services Locally
Every Liferay service provides a local interface to clients running in the same JVM as Liferay Portal. Many local services (
*LocalServiceUtil classes) are called by remote services (
*ServiceUtil classes). The remote classes mask the complexity of the local service implementations and include permission checks. The core Liferay services that are provided as part of Liferay Portal were generated by the same Service Builder tool that you can use in your applications. You can invoke a remote Liferay service by calling the appropriate
*ServiceUtil class. The following JSP code snippet demonstrates how to get a list of the most recent bloggers from an organization. Note that only a local service, not a remote service, is available for
<%@ page import="com.liferay.portlet.blogs.service.BlogsStatsUserLocalServiceUtil" %> <%@ page import="com.liferay.portlet.blogs.util.comparator.StatsUserLastPostDateComparator" %> ... <%@ List statsUsers = BlogsStatsUserLocalServiceUtil.getOrganizationStatsUsers( organizationId, 0, max, new StatsUserLastPostDateComparator()); %>
This JSP code invokes the static method
getOrganizationStatsUsers() from the
In addition to any services you create using Service Builder, your applications can access a variety of services built into Liferay. These include the following services:
UserService: for accessing, adding, authenticating, deleting, and updating users.
OrganizationService: for accessing, adding, deleting, and updating organizations.
GroupService: for accessing, adding, deleting, and updating groups.
CompanyService: for accessing, adding, checking, and updating companies.
ImageService: for accessing images.
LayoutService: for accessing, adding, deleting, exporting, importing, and updating layouts.
PermissionService: for checking permissions.
UserGroupService: for accessing, adding, deleting, and updating user groups.
RoleService: for accessing, adding, unassigning, checking, deleting, and updating roles.
Invoking Liferay Services Remotely
Many default Liferay services are available as web services. Liferay exposes its web services via SOAP and JSON web services. If you’re running Liferay locally on port 8080, visit the following URL to browse Liferay’s default SOAP web services:
To browse Liferay’s default JSON web services, visit this URL:
By default, the context path is set to
/ which means that core Liferay services are listed. You can select a different content path to view the services of a Liferay plugin. E.g., set the context path to
/calendar-portlet to view the services of Liferay’s Calendar portlet.
Click on the name of a service method to view details about it. The full package path to the service’s
*Impl class is displayed along with the method’s parameters, return type, and possible exceptions. There’s also a form that you can use to enter values for the method’s parameters and actually invoke the service. Note that you must be logged in a user that has permission to invoke the service for your service invocation to succeed.
The web interface for JSON web services is very handy for development and testing. However, Liferay web services are designed to be invoked by client applications. Liferay’s web services APIs can be accessed by many different kinds of clients, including non-portlet and even non-Java clients. For information on how to develop client applications that can access Liferay’s JSON web services, please see the Working With JSON Web Services tutorial. For information on how to develop client applications that access Liferay’s SOAP web services, please see the Working With SOAP Web Services tutorial. To learn how to create remote web services for your own application, please refer to the Creating Remote Services tutorial.
For more information on Liferay services, see the Liferay Portal CE Javadocs at http://docs.liferay.com/portal/6.2/javadocs/ or the Liferay Portal EE Javadocs included in the Liferay Portal EE Documentation
.zip file that you can download from the Customer Portal on http://www.liferay.com.