Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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 prog...
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-...
How OSGi Works
• Bundles - static entities
• Services - dynamics in OSGi
– Can appear, disappear at runtime according to a...
OSGi in Liferay
• Blade
– JAVA Package manager
– jpm install -f
https://releases.liferay.com/tools/blade-
cli/latest/blade.jar
• Liferay w...
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
SampleMvc...
MVC Portlet
MVC Action Command
@Component(
immediate = true,
property = {
"javax.portlet.name=com_azilen_liferay_portlet_S...
MVC Portlet
@Component(
immediate = true,
property = {
"javax.portlet.name=com_azilen_liferay_portlet_SampleMVCPortlet",
"...
MVC Portlet
MVC Resource Command
@Component(
immediate = true,
property = {
"javax.portlet.name=com_azilen_liferay_portlet...
Customize Portlet Configuration
Create an interface to represent your config.
@Meta.OCD(id = "com.azilen.liferay.config.Ch...
Customize Portlet Configuration
Implement your configuration action class and
add a reference to your configuration
@Compo...
Customize Portlet Configuration
• Implement the user interface for configuring
your application
• -metatype: * in project ...
Portlet Provider Template
• Provide mechanism to customize existing
entity behavior.
– Portlet should be added in hidden c...
Portlet Provider Template
• Naming conventions
– Make sure that class name has suffix
PortletProvider
• To override the de...
Portlet Provider Template
Specify the methods you’d like to implement
@Component(
property = {
"mod-
el.class.name=com.lif...
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...
Using Service Builder
• Things Unchanged:
– service.xml
– Custom SQL
– Dynamic Query
– Finder methods
– Model Hints
– Adding new methods into En...
Using Service Builder
• Using service objects in portlet
– @Reference
– OSGi Injection
public class BookPortlet extends MV...
Creating Service Wrappers
• Override Liferay’s OOTB services
• Service wrapper hooks in LR 6.2.
• To create service wrappe...
Creating Service Wrappers
@Component(
immediate = true,
property = {
},
service = ServiceWrapper.class
)
public class Cust...
Creating Service Wrappers
• Override methods as required.
@Override
public int authenticateByEmailAddress(long companyId, ...
OSGi services
• OSGi Services can be registered with Activator
public class CalcServiceActivator implements BundleActivato...
OSGi services
• Injecting OSGi Services in portlets
• Null check before using service object
public class CalcPortlet exte...
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
requir...
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-...
Customizing existing JSP
• copy jsp from Liferay-
src/modules/apps/foundation/login/login-
web/src/main/resources/META-
IN...
Override Language Properties
• Want to change Login portlet authentication
failed message
– authentication-failed key
• bl...
Override Language Properties
@Component(
property = { "language.id=en_US" },
service = ResourceBundle.class
)
public class...
Override Language Properties
• Create Language_en.properties under
/language-fragment-
module/src/main/resources/content
•...
Add Servlet Filter
• Used for intercepting http request
• Extend BaseFilter class
• e.g. Intercept every request and print...
Add Servlet Filter
@Component(
immediate = true,
property = {
"dispatcher=REQUEST", "dispatcher=FORWARD",
"servlet-context...
Add Custom Event
• com.liferay.portal.kernel.events.Lif
ecycleAction is one of the extension points
that can be leveraged ...
Add Custom Event@Component(
property = {
"key=login.events.post"
},
service = LifecycleAction.class
)
public class CustomL...
Add Custom Event
• Apart from this lifecycle event, there are many
other such portal lifecycle events supported
like:
logi...
OSGi Overview
Portlets as Modules
Services as Modules
Extending Liferay DXP
Thank You
Q&A
@AzilenTech #AzilenTechMeetup
www.azilen.com/kb/liferay-dxp/
Liferay (DXP) 7 Tech Meetup for Developers
Upcoming SlideShare
Loading in …5
×

of

Liferay (DXP) 7 Tech Meetup for Developers Slide 1 Liferay (DXP) 7 Tech Meetup for Developers Slide 2 Liferay (DXP) 7 Tech Meetup for Developers Slide 3 Liferay (DXP) 7 Tech Meetup for Developers Slide 4 Liferay (DXP) 7 Tech Meetup for Developers Slide 5 Liferay (DXP) 7 Tech Meetup for Developers Slide 6 Liferay (DXP) 7 Tech Meetup for Developers Slide 7 Liferay (DXP) 7 Tech Meetup for Developers Slide 8 Liferay (DXP) 7 Tech Meetup for Developers Slide 9 Liferay (DXP) 7 Tech Meetup for Developers Slide 10 Liferay (DXP) 7 Tech Meetup for Developers Slide 11 Liferay (DXP) 7 Tech Meetup for Developers Slide 12 Liferay (DXP) 7 Tech Meetup for Developers Slide 13 Liferay (DXP) 7 Tech Meetup for Developers Slide 14 Liferay (DXP) 7 Tech Meetup for Developers Slide 15 Liferay (DXP) 7 Tech Meetup for Developers Slide 16 Liferay (DXP) 7 Tech Meetup for Developers Slide 17 Liferay (DXP) 7 Tech Meetup for Developers Slide 18 Liferay (DXP) 7 Tech Meetup for Developers Slide 19 Liferay (DXP) 7 Tech Meetup for Developers Slide 20 Liferay (DXP) 7 Tech Meetup for Developers Slide 21 Liferay (DXP) 7 Tech Meetup for Developers Slide 22 Liferay (DXP) 7 Tech Meetup for Developers Slide 23 Liferay (DXP) 7 Tech Meetup for Developers Slide 24 Liferay (DXP) 7 Tech Meetup for Developers Slide 25 Liferay (DXP) 7 Tech Meetup for Developers Slide 26 Liferay (DXP) 7 Tech Meetup for Developers Slide 27 Liferay (DXP) 7 Tech Meetup for Developers Slide 28 Liferay (DXP) 7 Tech Meetup for Developers Slide 29 Liferay (DXP) 7 Tech Meetup for Developers Slide 30 Liferay (DXP) 7 Tech Meetup for Developers Slide 31 Liferay (DXP) 7 Tech Meetup for Developers Slide 32 Liferay (DXP) 7 Tech Meetup for Developers Slide 33 Liferay (DXP) 7 Tech Meetup for Developers Slide 34 Liferay (DXP) 7 Tech Meetup for Developers Slide 35 Liferay (DXP) 7 Tech Meetup for Developers Slide 36 Liferay (DXP) 7 Tech Meetup for Developers Slide 37 Liferay (DXP) 7 Tech Meetup for Developers Slide 38 Liferay (DXP) 7 Tech Meetup for Developers Slide 39 Liferay (DXP) 7 Tech Meetup for Developers Slide 40 Liferay (DXP) 7 Tech Meetup for Developers Slide 41 Liferay (DXP) 7 Tech Meetup for Developers Slide 42 Liferay (DXP) 7 Tech Meetup for Developers Slide 43 Liferay (DXP) 7 Tech Meetup for Developers Slide 44 Liferay (DXP) 7 Tech Meetup for Developers Slide 45 Liferay (DXP) 7 Tech Meetup for Developers Slide 46 Liferay (DXP) 7 Tech Meetup for Developers Slide 47 Liferay (DXP) 7 Tech Meetup for Developers Slide 48 Liferay (DXP) 7 Tech Meetup for Developers Slide 49 Liferay (DXP) 7 Tech Meetup for Developers Slide 50 Liferay (DXP) 7 Tech Meetup for Developers Slide 51 Liferay (DXP) 7 Tech Meetup for Developers Slide 52 Liferay (DXP) 7 Tech Meetup for Developers Slide 53 Liferay (DXP) 7 Tech Meetup for Developers Slide 54 Liferay (DXP) 7 Tech Meetup for Developers Slide 55
Upcoming SlideShare
Overview of Liferay 7 Technology
Next
Download to read offline and view in fullscreen.

2 Likes

Share

Download to read offline

Liferay (DXP) 7 Tech Meetup for Developers

Download to read offline

An interactive Liferay (DXP) 7 Tech Meet up was codified by Azilen Technologies on 18th March, 2017 at Ahmedabad Management Association.

Those who have missed the direct confrontation can explore few of the knowledge elements here in the Presentation.

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Liferay (DXP) 7 Tech Meetup for Developers

  1. 1. OSGi Overview Portlets as Modules Services as Modules Extending Liferay DXP
  2. 2. What Why How
  3. 3. Why OSGi
  4. 4. Benefits of OSGi • Reduced complexity • Reuse • Easy deployment • Dyanmic updates
  5. 5. What is OSGi
  6. 6. 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).
  7. 7. How OSGi Works
  8. 8. Application / Bundles Operating System Hardware JVM Modules Life cycle Service Registry Services Security How OSGi Works
  9. 9. How OSGi Works • Bundle • Bundle fragments • Bundle context
  10. 10. 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”
  11. 11. 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);
  12. 12. OSGi in Liferay
  13. 13. • 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
  14. 14. OSGi Overview Portlets as Modules Services as Modules Extending Liferay DXP
  15. 15. Portlets as Modules
  16. 16. Modules as Portlets MVC Portlet Customize Portlet Configuration Portlet Provider Template
  17. 17. MVC Portlet • Create portlet structure using blade – blade create -t mvc-portlet -p com.azilen.app.mvcportlet -c SampleMvcPortlet sample-mvc-portlet- project
  18. 18. 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 { } }
  19. 19. 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
  20. 20. 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 { } }
  21. 21. 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(); }
  22. 22. 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 { }
  23. 23. Customize Portlet Configuration • Implement the user interface for configuring your application • -metatype: * in project bnd.bnd file – generate an XML configuration file
  24. 24. 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.
  25. 25. 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"}
  26. 26. 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 { }
  27. 27. OSGi Overview Portlets as Modules Services as Modules Extending Liferay DXP
  28. 28. Services as modules
  29. 29. Using Service Builder Creating Service Wrappers OSGi Services
  30. 30. 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
  31. 31. Using Service Builder
  32. 32. • Things Unchanged: – service.xml – Custom SQL – Dynamic Query – Finder methods – Model Hints – Adding new methods into EntityServiceImpl, EntityLocalServiceImpl, EntityImpl
  33. 33. 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; } … }
  34. 34. 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
  35. 35. 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); } }
  36. 36. 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); }
  37. 37. 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(); } }
  38. 38. 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; } … }
  39. 39. OSGi Overview Portlets as Modules Services as Modules Extending Liferay DXP
  40. 40. Extending Liferay DXP
  41. 41. 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
  42. 42. Customize Existing JSP Override Language properties Add Servlet Filter Add Custom event
  43. 43. 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
  44. 44. 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/.
  45. 45. 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
  46. 46. 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(); } }
  47. 47. 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.
  48. 48. Add Servlet Filter • Used for intercepting http request • Extend BaseFilter class • e.g. Intercept every request and print log
  49. 49. 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); } }
  50. 50. 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
  51. 51. 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); } … } }
  52. 52. 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
  53. 53. OSGi Overview Portlets as Modules Services as Modules Extending Liferay DXP
  54. 54. Thank You Q&A @AzilenTech #AzilenTechMeetup www.azilen.com/kb/liferay-dxp/
  • Gudimetla

    Jul. 3, 2018
  • wikimix1

    Apr. 10, 2017

An interactive Liferay (DXP) 7 Tech Meet up was codified by Azilen Technologies on 18th March, 2017 at Ahmedabad Management Association. Those who have missed the direct confrontation can explore few of the knowledge elements here in the Presentation.

Views

Total views

1,824

On Slideshare

0

From embeds

0

Number of embeds

430

Actions

Downloads

63

Shares

0

Comments

0

Likes

2

×