Liferay DXP provides many features that help users accomplish their tasks. Sometimes, however, you may find it necessary to customize a built-in feature. It’s easy to find an area you want to customize, but it may seem like a daunting task to figure out how to customize it. Liferay DXP was developed for easy customization, meaning there are many extension points you can use to add your own flavor.
There’s a process you can follow that makes finding an extension point a breeze.
- Locate the bundle (module) that provides the functionality you want to change.
- Find the components available in the module.
- Discover the extension points for the chosen component.
In this tutorial, you’ll learn how to find an extension point. You’ll step through a simple example that locates an extension point for importing LDAP users. This will require the use of Liferay DXP’s Application Manager and Felix Gogo Shell.
You must first think of words that describe the application behavior you want to change. With the right keywords, you can easily track down the desired module and its component. Consider the example for importing LDAP users. Some candidate keywords for finding the component are import, user, and LDAP.
The easiest way to discover the module responsible for a particular feature in Liferay DXP is to use the Application Manager. The Application Manager lists app suites and their included modules/components in an easy-to-use interface. It even lists third party apps! You’ll use your keywords to target the applicable component.
Open the App Manager by navigating to Control Panel → Apps → App Manager. The top level lists app suites, independent apps, and independent modules.
Navigate the app suites, apps, and modules, or use Search to find components that might provide your desired extension point. Remember to check for your keywords in element names and descriptions. The keyword LDAP resides under the Liferay Foundation app suite; select it.
Select the LDAP application from the app listing.
The LDAP application only has one module, but typically, applications have more than one module to inspect. Select the Liferay Portal Security LDAP module.
Search through the components, applying your keywords as a guide. Copy the component name you think best fits the functionality you want to customize; you’ll inspect it later using the Gogo shell.
Next, you’ll begin using the Gogo shell to inspect the component for extension points.
Once you have the component that relates to the functionality you want to extend, you can use the Gogo shell’s Service Component Runtime (SCR) commands to inspect it. You can execute SCR commands using Liferay Blade CLI or in Gogo shell via telnet. This tutorial assumes you’re using the Gogo shell via telnet.
Execute the following command:
For the LDAP example component you copied previously, the command would look like this:
The output includes a lot of information. For this exercise, you’re interested in the services the component references. These are extension points. For example, here’s the reference for the service that imports LDAP users:
... Reference: LdapUserImporter Interface Name: com.liferay.portal.security.ldap.exportimport.LDAPUserImporter Cardinality: 1..1 Policy: static Policy option: reluctant Reference Scope: bundle ...
LDAPUserImporter is the extension point needed to customize the process of
importing users with LDAP! If none of the references satisfy what you’re looking
for, search other components from the App Manager.
If you plan on overriding the referenced service, you’ll need to understand the
reference’s policy and policy option. If the policy is
static and the policy
reluctant, binding a new higher ranking service in place of a bound
service requires reactivating the component or changing the target. For
information on the other policies and policy options, visit the
OSGi specification, in
particular, sections 112.3.5 and 112.3.6. If you want to learn how to
override a component’s service reference, visit the following
Important Not all Extension points in Liferay DXP are available as referenced services. Referenced services are common extension points when using Declarative Services (DS), but there are extension points not exposed this way. If your project does not use the DS component framework, you’d need to look for the API that describes its service consumption from the OSGi registry. Here’s a brief list of other potential extension points in Liferay DXP:
- Instances of
- Uses of Liferay’s
- Uses of Liferay’s
- Any other component framework or whiteboard implementation (e.g., HTTP, JAX-RS) that supports tracking services; Blueprint, Apache Dependency Manager, etc. could also introduce extension points.
There you have it! You successfully formulated keywords that described the functionality you wanted to customize, used those keywords in the App Manager to target the applicable module component, and used the Gogo shell to inspect the component for extension points.