SlideShare a Scribd company logo
1 of 55
OSGi Overview
Portlets as Modules
Services as Modules
Extending Liferay DXP
What
Why
How
Why OSGi
Benefits of OSGi
• Reduced complexity
• Reuse
• Easy deployment
• Dyanmic updates
What is OSGi
What is OSGi
OSGi (Open Service Gateway Initiative) is a Java framework for
developing and deploying modular software programs and
libraries. Each bundle is a tightly coupled, dynamically loadable
collection of classes, jars, and configuration files that explicitly
declare their external dependencies (if any).
How OSGi Works
Application / Bundles
Operating System
Hardware
JVM
Modules
Life cycle
Service Registry
Services
Security
How OSGi Works
How OSGi Works
• Bundle
• Bundle fragments
• Bundle context
Sample Config. of bundle
Manifest-Version: 1.0
Bundle-Name: SimpleTestBundle
Bundle-Activator: SimpleTestActivator
Bundle-SymbolicName: SimpleTestBundle
Bundle-Version: 1.0.0
Import-Package: org.azilen.framework;
version=”1.3.1”
How OSGi Works
• Bundles - static entities
• Services - dynamics in OSGi
– Can appear, disappear at runtime according to a
condition
• Service
– Object, registered by a bundle
• BundleContext.registerService(iface,
implementation, properties);
OSGi in Liferay
• Blade
– JAVA Package manager
– jpm install -f
https://releases.liferay.com/tools/blade-
cli/latest/blade.jar
• Liferay workspace with Blade
– blade init [WORKSPACE_NAME]
OSGi in Liferay
OSGi Overview
Portlets as Modules
Services as Modules
Extending Liferay DXP
Portlets as Modules
Modules as Portlets
MVC Portlet
Customize Portlet Configuration
Portlet Provider Template
MVC Portlet
• Create portlet structure using blade
– blade create -t mvc-portlet -p
com.azilen.app.mvcportlet -c
SampleMvcPortlet sample-mvc-portlet-
project
MVC Portlet
MVC Action Command
@Component(
immediate = true,
property = {
"javax.portlet.name=com_azilen_liferay_portlet_SampleMVCPortlet",
"mvc.command.name=actionCommand1",
"mvc.command.name=actionCommand2"
},
service = MVCActionCommand.class
)
public class DemoMVCActionCommand extends BaseMVCActionCommand {
@Override
protected void doProcessAction(ActionRequest req,
ActionResponse res) throws Exception {
}
}
MVC Portlet
@Component(
immediate = true,
property = {
"javax.portlet.name=com_azilen_liferay_portlet_SampleMVCPortlet",
"mvc.command.name=renderCommand1",
"mvc.command.name=renderCommand2"
},
service = MVCRenderCommand.class
)
public class DemoRenderCommand implements MVCRenderCommand {
@Override
public String render(RenderRequest req, RenderResponse res)
throws PortletException {
}
}
MVC Render Command
MVC Portlet
MVC Resource Command
@Component(
immediate = true,
property = {
"javax.portlet.name=com_azilen_liferay_portlet_SampleMVCPortlet",
"mvc.command.name=ajax1",
},
service = MVCResourceCommand.class
)
public class DemoMVCResourceCommand extends BaseMVCResourceCommand {
@Override
protected void doServeResource(ResourceRequest res, ResourceResponse
res) throws Exception {
}
}
Customize Portlet Configuration
Create an interface to represent your config.
@Meta.OCD(id = "com.azilen.liferay.config.ChartConfig")
public interface ChartConfig {
public static final String FIELD_CHART_TITLE =
"chartTitle";
@Meta.AD(required = false)
public String getChartTitle();
}
Customize Portlet Configuration
Implement your configuration action class and
add a reference to your configuration
@Component(
configurationPid = "com.azilen.liferay.config.ChartConfig",
configurationPolicy = ConfigurationPolicy.OPTIONAL,
immediate = true,
property = {
"javax.portlet.name=com_azilen_liferay_portlet_DemoConfigurationScreen
Portlet"
},
service = ConfigurationAction.class
)
public class ChartConfigAction extends DefaultConfigurationAction {
}
Customize Portlet Configuration
• Implement the user interface for configuring
your application
• -metatype: * in project bnd.bnd file
– generate an XML configuration file
Portlet Provider Template
• Provide mechanism to customize existing
entity behavior.
– Portlet should be added in hidden category.
• Create a Java class
– Extend BasePortletProvider class
– Implement the appropriate portlet provider
interface
– e.g.
AddPortletProvider,ViewPortletProvider,
BrowsePortletProvider.
Portlet Provider Template
• Naming conventions
– Make sure that class name has suffix
PortletProvider
• To override the default portlet with a custom
portlet
– Assign your portlet a higher service ranking.
– Add in @Component declaration
• property=
{"service.ranking:Integer=Integer.MAX
_VALUE"}
Portlet Provider Template
Specify the methods you’d like to implement
@Component(
property = {
"mod-
el.class.name=com.liferay.document.library.kernel.model.DLF
ileEntry",
"service.ranking:Integer=" + Integer.MAX_VALUE
},
service = AddPortletProvider.class
)
public class ProviderTemplateAddPortletProvider
extends BasePortletProvider
implements AddPortletProvider {
}
OSGi Overview
Portlets as Modules
Services as Modules
Extending Liferay DXP
Services as modules
Using Service Builder
Creating Service Wrappers
OSGi Services
Using Service Builder
• To create service builder modules :
– blade create -t service-builder [-p
packageName] projectName
e.g.
blade create -t service-builder -p
com.azilen.service.book book
– Above command will create two modules :
book-api and book-service.
• To run service builder:
– blade gw buildService
Using Service Builder
• Things Unchanged:
– service.xml
– Custom SQL
– Dynamic Query
– Finder methods
– Model Hints
– Adding new methods into EntityServiceImpl, EntityLocalServiceImpl,
EntityImpl
Using Service Builder
• Using service objects in portlet
– @Reference
– OSGi Injection
public class BookPortlet extends MVCPortlet {
private BookLocalService bookLocalService;
@Reference
public void setBookLocalService(BookLocalService bookLocalService) {
this.bookLocalService = bookLocalService;
}
…
}
Creating Service Wrappers
• Override Liferay’s OOTB services
• Service wrapper hooks in LR 6.2.
• To create service wrapper module :
– blade create -t service-wrapper [-p
packageName] [-c className]
[-s serviceWrapperToExtend] projectName
– e.g.
blade create -t service-wrapper
-p com.azilen.serviceoverride
-c CustomUserLocalService -s
com.liferay.portal.kernel.service.UserLocalServ
iceWrapper service-override
Creating Service Wrappers
@Component(
immediate = true,
property = {
},
service = ServiceWrapper.class
)
public class CustomUserLocalService extends UserLocalServiceWrapper {
private static final Log _log =
LogFactoryUtil.getLog(CustomUserLocalService.class);
public CustomUserLocalService() {
super(null);
}
}
Creating Service Wrappers
• Override methods as required.
@Override
public int authenticateByEmailAddress(long companyId, String emailAddress,
String password, Map<String, String[]> headerMap, Map<String,
String[]> parameterMap, Map<String, Object> resultsMap)
throws PortalException {
// Custom logic
_log.info("Custom Implementation of authenticateByEmailAddress()");
// Calling Liferay's default implementation of service
return super.authenticateByEmailAddress(companyId, emailAddress,
password, headerMap, parameterMap, resultsMap);
}
OSGi services
• OSGi Services can be registered with Activator
public class CalcServiceActivator implements BundleActivator {
private ServiceRegistration<CalcService> reg;
@Override
public void start(BundleContext bundleContext) throws Exception {
reg = bundleContext.registerService(CalcService.class, new
CalcServiceImpl(), null);
}
@Override
public void stop(BundleContext bundleContext) throws Exception {
reg.unregister();
}
}
OSGi services
• Injecting OSGi Services in portlets
• Null check before using service object
public class CalcPortlet extends MVCPortlet {
private CalcService _calcService;
@Reference
public void setCalcService(CalcService calcService) {
this._calcService = calcService;
}
…
}
OSGi Overview
Portlets as Modules
Services as Modules
Extending Liferay DXP
Extending Liferay DXP
Fragments
• Extension of host module
• Uses same classloader as host module
• Extending out of box modules based on
requirements
• Earlier versions used Hook plugins
• Create a Liferay fragment
– blade create -t fragment [-h
hostBundleName] [-H hostBundleVersion]
projectName
Customize Existing JSP
Override Language properties
Add Servlet Filter
Add Custom event
Customize Existing JSP
• Override Liferay Login module
– blade create -t fragment -h
com.liferay.login.web -H 1.0.7 login-
fragment-module
• Find host module symbolic name and version
– Connect to gogo shell using
• telnet localhost 11311
– 219 ACTIVE com.liferay.login.web_1.0.7
Customizing existing JSP
• copy jsp from Liferay-
src/modules/apps/foundation/login/login-
web/src/main/resources/META-
INF/resources/login.jsp
and paste it in login-fragment-
src/main/resources/META-INF/resources/.
Override Language Properties
• Want to change Login portlet authentication
failed message
– authentication-failed key
• blade create -t mvc-portlet -p
com.azilen.fragment.language -c
CustomLanguageComponent language-
fragment-module
Override Language Properties
@Component(
property = { "language.id=en_US" },
service = ResourceBundle.class
)
public class CustomLanguageComponent extends ResourceBundle {
ResourceBundle bundle = ResourceBundle.getBundle("content.Language",
UTF8Control.INSTANCE);
@Override
protected Object handleGetObject(String key) {
return bundle.getObject(key);
}
@Override
public Enumeration<String> getKeys() {
return bundle.getKeys();
}
}
Override Language Properties
• Create Language_en.properties under
/language-fragment-
module/src/main/resources/content
• Add authentication-failed language key with
custom message.
– authentication-failed=Authentication
failed. Make sure you entered correct
username and password.
Add Servlet Filter
• Used for intercepting http request
• Extend BaseFilter class
• e.g. Intercept every request and print log
Add Servlet Filter
@Component(
immediate = true,
property = {
"dispatcher=REQUEST", "dispatcher=FORWARD",
"servlet-context-name=",
"servlet-filter-name=Custom Filter",
"url-pattern=/*"
},
service = Filter.class
)
public class CustomFilter extends BaseFilter {
private static final Log _log = LogFactoryUtil.getLog(CustomFilter.class);
@Override
protected void processFilter(HttpServletRequest request,
HttpServletResponse response, FilterChain filterChain)
throws Exception {
_log.info("Intercepted request : " + request);
filterChain.doFilter(request, response);
}
}
Add Custom Event
• com.liferay.portal.kernel.events.Lif
ecycleAction is one of the extension points
that can be leveraged by service template
• Create a new module using “service” template
– e.g., blade create –t service –p
com.azilen.training.lifecycle.loginpost
action –c CustomLoginPostAction –s
com.liferay.portal.kernel.events.Lifecy
cleAction login-post-action
Add Custom Event@Component(
property = {
"key=login.events.post"
},
service = LifecycleAction.class
)
public class CustomLoginPostAction implements LifecycleAction {
private static final Log _log =
LogFactoryUtil.getLog(CustomLoginPostAction.class);
@Override
public void processLifecycleEvent(LifecycleEvent lifecycleEvent)
throws ActionException {
HttpServletRequest request = lifecycleEvent.getRequest();
User user = null;
try {
user = PortalUtil.getUser(request);
} catch (PortalException e) {
_log.error(e);
}
…
}
}
Add Custom Event
• Apart from this lifecycle event, there are many
other such portal lifecycle events supported
like:
login.events.post,
logout.events.post,
logout.events.pre,
global.shutdown.events,
global.startup.events,
application.shutdown.events,
application.startup.events
OSGi Overview
Portlets as Modules
Services as Modules
Extending Liferay DXP
Thank You
Q&A
@AzilenTech #AzilenTechMeetup
www.azilen.com/kb/liferay-dxp/

More Related Content

What's hot

Project Presentation on Advance Java
Project Presentation on Advance JavaProject Presentation on Advance Java
Project Presentation on Advance Java
Vikas Goyal
 
108 advancedjava
108 advancedjava108 advancedjava
108 advancedjava
Anil Kumar
 

What's hot (20)

Benefits of OSGi in Practise
Benefits of OSGi in PractiseBenefits of OSGi in Practise
Benefits of OSGi in Practise
 
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application DevelopmentOSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
 
OSGi and Java EE in GlassFish - Tech Days 2010 India
OSGi and Java EE in GlassFish - Tech Days 2010 IndiaOSGi and Java EE in GlassFish - Tech Days 2010 India
OSGi and Java EE in GlassFish - Tech Days 2010 India
 
Project Presentation on Advance Java
Project Presentation on Advance JavaProject Presentation on Advance Java
Project Presentation on Advance Java
 
Open Services Gateway Initiative (OSGI)
Open Services Gateway Initiative (OSGI)Open Services Gateway Initiative (OSGI)
Open Services Gateway Initiative (OSGI)
 
Java Modularity with OSGi
Java Modularity with OSGiJava Modularity with OSGi
Java Modularity with OSGi
 
Java & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate FrameworkJava & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate Framework
 
Java modularity: life after Java 9
Java modularity: life after Java 9Java modularity: life after Java 9
Java modularity: life after Java 9
 
Liferay portals in real projects
Liferay portals  in real projectsLiferay portals  in real projects
Liferay portals in real projects
 
Advance java Online Training in Hyderabad
Advance java Online Training in HyderabadAdvance java Online Training in Hyderabad
Advance java Online Training in Hyderabad
 
108 advancedjava
108 advancedjava108 advancedjava
108 advancedjava
 
MyFaces CODI and JBoss Seam3 become Apache DeltaSpike
MyFaces CODI and JBoss Seam3 become Apache DeltaSpikeMyFaces CODI and JBoss Seam3 become Apache DeltaSpike
MyFaces CODI and JBoss Seam3 become Apache DeltaSpike
 
Getting Started with Java EE 7
Getting Started with Java EE 7Getting Started with Java EE 7
Getting Started with Java EE 7
 
Practical OSGi
Practical OSGiPractical OSGi
Practical OSGi
 
Workshop Framework(J2EE/OSGi/RCP)
Workshop Framework(J2EE/OSGi/RCP)Workshop Framework(J2EE/OSGi/RCP)
Workshop Framework(J2EE/OSGi/RCP)
 
Glassfish An Introduction
Glassfish An IntroductionGlassfish An Introduction
Glassfish An Introduction
 
Desiging for Modularity with Java 9
Desiging for Modularity with Java 9Desiging for Modularity with Java 9
Desiging for Modularity with Java 9
 
GlassFish v3 - Architecture
GlassFish v3 - ArchitectureGlassFish v3 - Architecture
GlassFish v3 - Architecture
 
Modularization in java 8
Modularization in java 8Modularization in java 8
Modularization in java 8
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 

Similar to Liferay (DXP) 7 Tech Meetup for Developers

WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 
Gwt and rpc use 2007 1
Gwt and rpc use 2007 1Gwt and rpc use 2007 1
Gwt and rpc use 2007 1
Sam Muhanguzi
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
WO Community
 
ZZ BC#7 asp.net mvc practice and guideline by NineMvp
ZZ BC#7 asp.net mvc practice and guideline by NineMvpZZ BC#7 asp.net mvc practice and guideline by NineMvp
ZZ BC#7 asp.net mvc practice and guideline by NineMvp
Chalermpon Areepong
 

Similar to Liferay (DXP) 7 Tech Meetup for Developers (20)

WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
jclouds overview
jclouds overviewjclouds overview
jclouds overview
 
Connect + Docker + AWS = Bitbucket Pipelines
Connect + Docker + AWS = Bitbucket PipelinesConnect + Docker + AWS = Bitbucket Pipelines
Connect + Docker + AWS = Bitbucket Pipelines
 
Gwt and rpc use 2007 1
Gwt and rpc use 2007 1Gwt and rpc use 2007 1
Gwt and rpc use 2007 1
 
Dependencies, dependencies, dependencies
Dependencies, dependencies, dependenciesDependencies, dependencies, dependencies
Dependencies, dependencies, dependencies
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's Guide
 
Apache Cayenne for WO Devs
Apache Cayenne for WO DevsApache Cayenne for WO Devs
Apache Cayenne for WO Devs
 
Osgi
OsgiOsgi
Osgi
 
MVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming modelMVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming model
 
Intro lift
Intro liftIntro lift
Intro lift
 
Microservices and modularity with java
Microservices and modularity with javaMicroservices and modularity with java
Microservices and modularity with java
 
What's new in the OSGi Enterprise Release 5.0
What's new in the OSGi Enterprise Release 5.0What's new in the OSGi Enterprise Release 5.0
What's new in the OSGi Enterprise Release 5.0
 
Field injection, type safe configuration, and more new goodies in Declarative...
Field injection, type safe configuration, and more new goodies in Declarative...Field injection, type safe configuration, and more new goodies in Declarative...
Field injection, type safe configuration, and more new goodies in Declarative...
 
Groovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentationGroovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentation
 
Petro Gordiievych "From Java 9 to Java 12"
Petro Gordiievych "From Java 9 to Java 12"Petro Gordiievych "From Java 9 to Java 12"
Petro Gordiievych "From Java 9 to Java 12"
 
ZZ BC#7 asp.net mvc practice and guideline by NineMvp
ZZ BC#7 asp.net mvc practice and guideline by NineMvpZZ BC#7 asp.net mvc practice and guideline by NineMvp
ZZ BC#7 asp.net mvc practice and guideline by NineMvp
 
Knolx session
Knolx sessionKnolx session
Knolx session
 
Web Components v1
Web Components v1Web Components v1
Web Components v1
 
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
ZZ BC#7.5 asp.net mvc practice  and guideline refresh! ZZ BC#7.5 asp.net mvc practice  and guideline refresh!
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
 
Angular beans
Angular beansAngular beans
Angular beans
 

More from Azilen Technologies Pvt. Ltd.

More from Azilen Technologies Pvt. Ltd. (20)

Software Product Development for Startups.pdf
Software Product Development for Startups.pdfSoftware Product Development for Startups.pdf
Software Product Development for Startups.pdf
 
How Chatbots Empower Healthcare Ecosystem?
How Chatbots Empower Healthcare Ecosystem?How Chatbots Empower Healthcare Ecosystem?
How Chatbots Empower Healthcare Ecosystem?
 
[Step by-step guide] configure document generation functionality in ms dynami...
[Step by-step guide] configure document generation functionality in ms dynami...[Step by-step guide] configure document generation functionality in ms dynami...
[Step by-step guide] configure document generation functionality in ms dynami...
 
How to overcome operational challenges in getting consistent beacon behavior
How to overcome operational challenges in getting consistent beacon behaviorHow to overcome operational challenges in getting consistent beacon behavior
How to overcome operational challenges in getting consistent beacon behavior
 
Liferay dxp – the good, the bad and the ugly
Liferay dxp – the good, the bad and the uglyLiferay dxp – the good, the bad and the ugly
Liferay dxp – the good, the bad and the ugly
 
Realm mobile platform – explore real time data synchronization capabilities
Realm mobile platform – explore real time data synchronization capabilitiesRealm mobile platform – explore real time data synchronization capabilities
Realm mobile platform – explore real time data synchronization capabilities
 
A step by step guide to develop temperature sensor io t application using ibm...
A step by step guide to develop temperature sensor io t application using ibm...A step by step guide to develop temperature sensor io t application using ibm...
A step by step guide to develop temperature sensor io t application using ibm...
 
How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...
How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...
How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...
 
Register Virtual Device and analyze the device data
Register Virtual Device and analyze the device dataRegister Virtual Device and analyze the device data
Register Virtual Device and analyze the device data
 
Analytics and etl based bi solutions
Analytics and etl based bi solutionsAnalytics and etl based bi solutions
Analytics and etl based bi solutions
 
Advanced risk management &amp; mitigation system
Advanced risk management &amp; mitigation systemAdvanced risk management &amp; mitigation system
Advanced risk management &amp; mitigation system
 
Server driven user interface (sdui) – framework for i os applications!
Server driven user interface (sdui) – framework for i os applications!Server driven user interface (sdui) – framework for i os applications!
Server driven user interface (sdui) – framework for i os applications!
 
How to integrate portlet as widget in liferay to any website application
How to integrate portlet as widget in liferay to any website applicationHow to integrate portlet as widget in liferay to any website application
How to integrate portlet as widget in liferay to any website application
 
A walkthrough of recently held wwdc17
A walkthrough of recently held wwdc17A walkthrough of recently held wwdc17
A walkthrough of recently held wwdc17
 
How wearable devices are changing our lives
How wearable devices are changing our livesHow wearable devices are changing our lives
How wearable devices are changing our lives
 
iPad Application as Return Process Automation Solution for eCommerce Store
iPad Application as Return Process Automation Solution for eCommerce StoreiPad Application as Return Process Automation Solution for eCommerce Store
iPad Application as Return Process Automation Solution for eCommerce Store
 
[Part 3] automation of home appliances using raspberry pi – all set to automa...
[Part 3] automation of home appliances using raspberry pi – all set to automa...[Part 3] automation of home appliances using raspberry pi – all set to automa...
[Part 3] automation of home appliances using raspberry pi – all set to automa...
 
Rfid systems for asset management — the young technology on its winning path
Rfid systems for asset management — the young technology on its winning pathRfid systems for asset management — the young technology on its winning path
Rfid systems for asset management — the young technology on its winning path
 
[Part 2] automation of home appliances using raspberry pi – implementation of...
[Part 2] automation of home appliances using raspberry pi – implementation of...[Part 2] automation of home appliances using raspberry pi – implementation of...
[Part 2] automation of home appliances using raspberry pi – implementation of...
 
[Part 1] automation of home appliances using raspberry pi – software installa...
[Part 1] automation of home appliances using raspberry pi – software installa...[Part 1] automation of home appliances using raspberry pi – software installa...
[Part 1] automation of home appliances using raspberry pi – software installa...
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

Liferay (DXP) 7 Tech Meetup for Developers

  • 1.
  • 2. OSGi Overview Portlets as Modules Services as Modules Extending Liferay DXP
  • 5. Benefits of OSGi • Reduced complexity • Reuse • Easy deployment • Dyanmic updates
  • 7. What is OSGi OSGi (Open Service Gateway Initiative) is a Java framework for developing and deploying modular software programs and libraries. Each bundle is a tightly coupled, dynamically loadable collection of classes, jars, and configuration files that explicitly declare their external dependencies (if any).
  • 9. Application / Bundles Operating System Hardware JVM Modules Life cycle Service Registry Services Security How OSGi Works
  • 10. How OSGi Works • Bundle • Bundle fragments • Bundle context
  • 11. Sample Config. of bundle Manifest-Version: 1.0 Bundle-Name: SimpleTestBundle Bundle-Activator: SimpleTestActivator Bundle-SymbolicName: SimpleTestBundle Bundle-Version: 1.0.0 Import-Package: org.azilen.framework; version=”1.3.1”
  • 12. How OSGi Works • Bundles - static entities • Services - dynamics in OSGi – Can appear, disappear at runtime according to a condition • Service – Object, registered by a bundle • BundleContext.registerService(iface, implementation, properties);
  • 14. • Blade – JAVA Package manager – jpm install -f https://releases.liferay.com/tools/blade- cli/latest/blade.jar • Liferay workspace with Blade – blade init [WORKSPACE_NAME] OSGi in Liferay
  • 15. OSGi Overview Portlets as Modules Services as Modules Extending Liferay DXP
  • 17. Modules as Portlets MVC Portlet Customize Portlet Configuration Portlet Provider Template
  • 18. MVC Portlet • Create portlet structure using blade – blade create -t mvc-portlet -p com.azilen.app.mvcportlet -c SampleMvcPortlet sample-mvc-portlet- project
  • 19. MVC Portlet MVC Action Command @Component( immediate = true, property = { "javax.portlet.name=com_azilen_liferay_portlet_SampleMVCPortlet", "mvc.command.name=actionCommand1", "mvc.command.name=actionCommand2" }, service = MVCActionCommand.class ) public class DemoMVCActionCommand extends BaseMVCActionCommand { @Override protected void doProcessAction(ActionRequest req, ActionResponse res) throws Exception { } }
  • 20. MVC Portlet @Component( immediate = true, property = { "javax.portlet.name=com_azilen_liferay_portlet_SampleMVCPortlet", "mvc.command.name=renderCommand1", "mvc.command.name=renderCommand2" }, service = MVCRenderCommand.class ) public class DemoRenderCommand implements MVCRenderCommand { @Override public String render(RenderRequest req, RenderResponse res) throws PortletException { } } MVC Render Command
  • 21. MVC Portlet MVC Resource Command @Component( immediate = true, property = { "javax.portlet.name=com_azilen_liferay_portlet_SampleMVCPortlet", "mvc.command.name=ajax1", }, service = MVCResourceCommand.class ) public class DemoMVCResourceCommand extends BaseMVCResourceCommand { @Override protected void doServeResource(ResourceRequest res, ResourceResponse res) throws Exception { } }
  • 22. Customize Portlet Configuration Create an interface to represent your config. @Meta.OCD(id = "com.azilen.liferay.config.ChartConfig") public interface ChartConfig { public static final String FIELD_CHART_TITLE = "chartTitle"; @Meta.AD(required = false) public String getChartTitle(); }
  • 23. Customize Portlet Configuration Implement your configuration action class and add a reference to your configuration @Component( configurationPid = "com.azilen.liferay.config.ChartConfig", configurationPolicy = ConfigurationPolicy.OPTIONAL, immediate = true, property = { "javax.portlet.name=com_azilen_liferay_portlet_DemoConfigurationScreen Portlet" }, service = ConfigurationAction.class ) public class ChartConfigAction extends DefaultConfigurationAction { }
  • 24. Customize Portlet Configuration • Implement the user interface for configuring your application • -metatype: * in project bnd.bnd file – generate an XML configuration file
  • 25. Portlet Provider Template • Provide mechanism to customize existing entity behavior. – Portlet should be added in hidden category. • Create a Java class – Extend BasePortletProvider class – Implement the appropriate portlet provider interface – e.g. AddPortletProvider,ViewPortletProvider, BrowsePortletProvider.
  • 26. Portlet Provider Template • Naming conventions – Make sure that class name has suffix PortletProvider • To override the default portlet with a custom portlet – Assign your portlet a higher service ranking. – Add in @Component declaration • property= {"service.ranking:Integer=Integer.MAX _VALUE"}
  • 27. Portlet Provider Template Specify the methods you’d like to implement @Component( property = { "mod- el.class.name=com.liferay.document.library.kernel.model.DLF ileEntry", "service.ranking:Integer=" + Integer.MAX_VALUE }, service = AddPortletProvider.class ) public class ProviderTemplateAddPortletProvider extends BasePortletProvider implements AddPortletProvider { }
  • 28. OSGi Overview Portlets as Modules Services as Modules Extending Liferay DXP
  • 30. Using Service Builder Creating Service Wrappers OSGi Services
  • 31. Using Service Builder • To create service builder modules : – blade create -t service-builder [-p packageName] projectName e.g. blade create -t service-builder -p com.azilen.service.book book – Above command will create two modules : book-api and book-service. • To run service builder: – blade gw buildService
  • 33. • Things Unchanged: – service.xml – Custom SQL – Dynamic Query – Finder methods – Model Hints – Adding new methods into EntityServiceImpl, EntityLocalServiceImpl, EntityImpl
  • 34. Using Service Builder • Using service objects in portlet – @Reference – OSGi Injection public class BookPortlet extends MVCPortlet { private BookLocalService bookLocalService; @Reference public void setBookLocalService(BookLocalService bookLocalService) { this.bookLocalService = bookLocalService; } … }
  • 35. Creating Service Wrappers • Override Liferay’s OOTB services • Service wrapper hooks in LR 6.2. • To create service wrapper module : – blade create -t service-wrapper [-p packageName] [-c className] [-s serviceWrapperToExtend] projectName – e.g. blade create -t service-wrapper -p com.azilen.serviceoverride -c CustomUserLocalService -s com.liferay.portal.kernel.service.UserLocalServ iceWrapper service-override
  • 36. Creating Service Wrappers @Component( immediate = true, property = { }, service = ServiceWrapper.class ) public class CustomUserLocalService extends UserLocalServiceWrapper { private static final Log _log = LogFactoryUtil.getLog(CustomUserLocalService.class); public CustomUserLocalService() { super(null); } }
  • 37. Creating Service Wrappers • Override methods as required. @Override public int authenticateByEmailAddress(long companyId, String emailAddress, String password, Map<String, String[]> headerMap, Map<String, String[]> parameterMap, Map<String, Object> resultsMap) throws PortalException { // Custom logic _log.info("Custom Implementation of authenticateByEmailAddress()"); // Calling Liferay's default implementation of service return super.authenticateByEmailAddress(companyId, emailAddress, password, headerMap, parameterMap, resultsMap); }
  • 38. OSGi services • OSGi Services can be registered with Activator public class CalcServiceActivator implements BundleActivator { private ServiceRegistration<CalcService> reg; @Override public void start(BundleContext bundleContext) throws Exception { reg = bundleContext.registerService(CalcService.class, new CalcServiceImpl(), null); } @Override public void stop(BundleContext bundleContext) throws Exception { reg.unregister(); } }
  • 39. OSGi services • Injecting OSGi Services in portlets • Null check before using service object public class CalcPortlet extends MVCPortlet { private CalcService _calcService; @Reference public void setCalcService(CalcService calcService) { this._calcService = calcService; } … }
  • 40. OSGi Overview Portlets as Modules Services as Modules Extending Liferay DXP
  • 42. Fragments • Extension of host module • Uses same classloader as host module • Extending out of box modules based on requirements • Earlier versions used Hook plugins • Create a Liferay fragment – blade create -t fragment [-h hostBundleName] [-H hostBundleVersion] projectName
  • 43. Customize Existing JSP Override Language properties Add Servlet Filter Add Custom event
  • 44. Customize Existing JSP • Override Liferay Login module – blade create -t fragment -h com.liferay.login.web -H 1.0.7 login- fragment-module • Find host module symbolic name and version – Connect to gogo shell using • telnet localhost 11311 – 219 ACTIVE com.liferay.login.web_1.0.7
  • 45. Customizing existing JSP • copy jsp from Liferay- src/modules/apps/foundation/login/login- web/src/main/resources/META- INF/resources/login.jsp and paste it in login-fragment- src/main/resources/META-INF/resources/.
  • 46. Override Language Properties • Want to change Login portlet authentication failed message – authentication-failed key • blade create -t mvc-portlet -p com.azilen.fragment.language -c CustomLanguageComponent language- fragment-module
  • 47. Override Language Properties @Component( property = { "language.id=en_US" }, service = ResourceBundle.class ) public class CustomLanguageComponent extends ResourceBundle { ResourceBundle bundle = ResourceBundle.getBundle("content.Language", UTF8Control.INSTANCE); @Override protected Object handleGetObject(String key) { return bundle.getObject(key); } @Override public Enumeration<String> getKeys() { return bundle.getKeys(); } }
  • 48. Override Language Properties • Create Language_en.properties under /language-fragment- module/src/main/resources/content • Add authentication-failed language key with custom message. – authentication-failed=Authentication failed. Make sure you entered correct username and password.
  • 49. Add Servlet Filter • Used for intercepting http request • Extend BaseFilter class • e.g. Intercept every request and print log
  • 50. Add Servlet Filter @Component( immediate = true, property = { "dispatcher=REQUEST", "dispatcher=FORWARD", "servlet-context-name=", "servlet-filter-name=Custom Filter", "url-pattern=/*" }, service = Filter.class ) public class CustomFilter extends BaseFilter { private static final Log _log = LogFactoryUtil.getLog(CustomFilter.class); @Override protected void processFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws Exception { _log.info("Intercepted request : " + request); filterChain.doFilter(request, response); } }
  • 51. Add Custom Event • com.liferay.portal.kernel.events.Lif ecycleAction is one of the extension points that can be leveraged by service template • Create a new module using “service” template – e.g., blade create –t service –p com.azilen.training.lifecycle.loginpost action –c CustomLoginPostAction –s com.liferay.portal.kernel.events.Lifecy cleAction login-post-action
  • 52. Add Custom Event@Component( property = { "key=login.events.post" }, service = LifecycleAction.class ) public class CustomLoginPostAction implements LifecycleAction { private static final Log _log = LogFactoryUtil.getLog(CustomLoginPostAction.class); @Override public void processLifecycleEvent(LifecycleEvent lifecycleEvent) throws ActionException { HttpServletRequest request = lifecycleEvent.getRequest(); User user = null; try { user = PortalUtil.getUser(request); } catch (PortalException e) { _log.error(e); } … } }
  • 53. Add Custom Event • Apart from this lifecycle event, there are many other such portal lifecycle events supported like: login.events.post, logout.events.post, logout.events.pre, global.shutdown.events, global.startup.events, application.shutdown.events, application.startup.events
  • 54. OSGi Overview Portlets as Modules Services as Modules Extending Liferay DXP

Editor's Notes

  1. Why - Benefits of OSGi What - What is OSGi How - Architecture of OSGi
  2. Similar concept as Service wrapper hook in LR 6.2 Used to override Liferay’s OOTB remote and local services.
  3. Add Summary