Introduction
Liferay has implemented its core services in way you can extend them easily using service wrapper module. Liferay created wrapper classes for all its services and we can override services for customization with the help of Service Wrapper.
Prerequisites
- Java
- Liferay portal 7/7.x
Environment Requirement
- JDK 8
- Eclipse
- MySQL
Service wrapper in Liferay 7
Assuming you’ve already created a Liferay-workspace project
1) One of following way, you can create service wrapper module in Liferay
Using Blade CLI
blade create -t service-wrapper -v 7.0 [-p packageName] [-c className] [-s serviceWrapperClass] projectName
Using maven
mvn archetype:generate \
-DarchetypeGroupId=com.liferay \
-DarchetypeArtifactId=com.liferay.project.templates.service.wrapper \
-DartifactId=[projectName] \
-Dpackage=[packageName] \
-DclassName=[className] \
-DserviceWrapperClass=[serviceWrapperClass] \
-DliferayVersion=7.0
Using eclipse IDE
- Go to liferay workspace project → modules → new
- Select other → Liferay → Liferay Module Project and Click on “Next”
- Enter project name
- Select “Project Template Name” as “service-wrapper” and Click on “Next”
- Enter “Component Class Name” → Enter “Package name”
- Select “Service Name” as your implementation and click on “Finish”
2) Please refer below example of service wrapper for UserLocalServiceWrapper
// CustomUserLocalServiceWrapper.java //
package com.ignek.portal.user.service.wrapper;
@Component(
immediate = true,
property = {
},
service = ServiceWrapper.class
)
public class CustomUserLocalServiceWrapper extends UserLocalServiceWrapper {
private Log log = LogFactoryUtil.getLog(this.getClass().getName());
public CustomUserLocalServiceWrapper() {
super(null);
}
@Override
public int authenticateByEmailAddress(long companyId, String emailAddress, String password,
Map headerMap, Map parameterMap, Map resultsMap)
throws PortalException {
log.info("Customizing Authentication by email Address");
return super.authenticateByEmailAddress(companyId, emailAddress, password, headerMap, parameterMap, resultsMap);
}
}
3) Fragment is ready, you can deploy it in Liferay server. When you Login into Liferay, this service wrapper’s method will be called and you will see logs terminal(cmd)