SlideShare uma empresa Scribd logo
1 de 18
Baixar para ler offline
<Insert Picture Here>




Writing Plugged-In Java EE Apps
Jason Lee
July 9, 2012
Who Am I?
     • Principal MTS for Oracle Corporation (by way of Sun
       Microsystems)
     • Member of GlassFish team
             – RESTful Management APIs
             – Administration Console
     • JSF user/developer
     • Live in Oklahoma City, OK




Oracle Confidential                                          2
Introduction
     • Plugins are not a new concept
             – Means of providing extensibility or decomposing and decoupling
               functionality
             – The concept has been around for years
                 • NetBeans/Eclipse/IDEA
                 • Wordpress
                 • Hudson
     • The what and why are easy. The how is the hard part.
             – How do I get access to the plugin code?
             – How do I identify the plugins deployed with the system
             – How do I expose core system functionality to the plugins




Oracle Confidential                                                       3
Introduction – cont.
     • Some background
             – GlassFish 3.x Administration Console
                • Core application does very little
                • All actual functionality delivered as plugins
                • Based on proprietary technologies
                    – HK2/OSGi
                    – JSFTemplating
             – For GlassFish 4.x, the basic stack had to change
                • Reevaluate whole system
                • Investigate HK2/OSGi, CDI, existing systems, etc.
                • Design a system based on modern technologies, preferably
                  standards




Oracle Confidential                                                     4
Problem #1 – Class Loading
     • The hard part
             – Where do I put the jar files?
             – How do I load them?
     • Three (probably of many) choices
             – Repackaging
             – Manual ClassLoading
             – OSGi




Oracle Confidential                            5
Problem #1 - Class Loading - Repackaging
     • Simple and portable
             – Guaranteed to support every Java EE technology supported
               in .war files
     • Ant-/Maven-/etc-based
             – Base distribution war
             – Collection of plugins
             – War rebuilt to include plugin jars
     • Liferay uses this. Works well.
     • Redeploys/upgrades take a bit more time/work




Oracle Confidential                                                       6
Problem #1 - Class Loading - Repackaging
     #!/bin/bash
     DIST=$1
     if [ "$DIST" == "" ] ; then
          echo "You must specify the distribution .war"
          exit 1
     fi
     BASE=`echo $DIST | sed -e 's/.war//'`
     rm -rf work
     mkdir work
     cd work


     jar xf ../$DIST
     cp ../plugins/*jar WEB-INF/lib


     jar cf ../$BASE-repackaged.war *


     cd ..
     rm -rf work


Oracle Confidential                                       7
Problem #1 - Class Loading – Manual ClassLoading

     • Filesystem-based
        – Much like Wordpress
            • wordpress/wp-content/plugins/*
        – ~/.plugins
     • War is deployed unchanged
     • Fairly portable, in theory
        – Demo works on GlassFish
        – Currently breaks on JBoss
        – Should be easily solvable
     • Demo - Plummer



Oracle Confidential                                  8
Problem #1 - Class Loading – Manual ClassLoading
     public class PluginLoader implements Extension {
         // ...
         public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd,
             BeanManager beanManager) {
             for (PluginFinder pluginFinder : getPluginFinders()) {
                  try {
                      for (Class<?> clazz : pluginFinder.getClasses()) {
                          final AnnotatedType<?> annotatedType = beanManager.createAnnotatedType(clazz);
                          logger.log(Level.INFO, "Adding AnnotatedType for {0}", annotatedType.toString());
                          bbd.addAnnotatedType(annotatedType);
                      }
                  } catch (Exception ex) {
                      Logger.getLogger(PluginLoader.class.getName()).log(Level.SEVERE, null, ex);
                  }
             }
         }
         // ...
     }


Oracle Confidential                                                                                           9
Problem #1 – Class Loading - OSGi
     • Well-defined and understood solution
     • Web Application Bundles not quite what we need
             – Requires repackaging
     • Container must support OSGi
     • Deployment will likely vary between containers




Oracle Confidential                                     10
Problem #1 – Class Loading - OSGi
     public class PluginActivator implements BundleActivator {
         @Override
         public void start(BundleContext context) throws Exception {
             ServiceTracker tracker = new ServiceTracker(context, PluginTracker.class.getName(), null);
             tracker.open();
             PluginTracker pt = (PluginTracker)tracker.getService();
             if (pt != null) {
                 pt.registerPluginBundle(context.getBundle());
             }
             tracker.close();
         }


         @Override
         public void stop(BundleContext context) throws Exception {
         }
     }




Oracle Confidential                                                                                       11
Problem #1 – Class Loading - OSGi
     public class PluginTrackerImpl implements PluginTracker {
         @Override
         public void registerPluginBundle(Bundle bundle) {
             if (bundle.getEntry("META-INF/beans.xml") != null) {
                 Enumeration<URL> e = bundle.findEntries("/", "*.class", true);
                 while (e.hasMoreElements()) {
                     String className = e.nextElement().getPath().substring(1).replace("/", ".");
                     className = className.substring(0, className.length()-6);
                     classes.add(className);
                 }
             }
         }


         public Set<String> getClasses() {
             return classes;
         }
     }




Oracle Confidential                                                                                 12
Problem #1 – Class Loading - OSGi
     public class PlummerActivator implements BundleActivator {
         @Override
         public void start(BundleContext context) throws Exception {
             context.registerService(PluginTracker.class.getName(), PluginTrackerImpl.instance(),
               new Properties());
         }


         @Override
         public void stop(BundleContext context) throws Exception {
             context.ungetService(context.getServiceReference(PluginTracker.class.getName()));
         }
     }




Oracle Confidential                                                                                 13
Problem #2 – Application Design
     • Largely application-specific
     • General strategies and techniques can be defined
     • Once plugins are loaded, how are they integrated into
       the application?
             – Java EE to the rescue
                • JSF
                • CDI
                • REST




Oracle Confidential                                            14
JSF Extensibility
     • Views decomposed into fragments
     • Custom component used to insert fragments
        – pl:viewFragment
     • Current solution is Mojarra-specific
        – MyFaces solution needed
        – Can also be implemented in Swing/JavaFX




Oracle Confidential                                 15
CDI – The Real Work Horse
     • CDI Events
        – Pub/Sub
        – Loose coupling
        – Multiple Receivers
     • Programmatic Bean Lookup
        – Instance<Foo>
        – Iterate over over instances




Oracle Confidential                     16
JAX-RS Resources
     • Plugins can provide REST resources
     • Configure using Application rather than a package
        – javax.ws.rs.core.Application
             –   <servlet>
                      <servlet-name>Jersey Web Application</servlet-name>
                      <servlet-class>
                        com.sun.jersey.spi.container.servlet.ServletContainer
                      </servlet-class>
                      <init-param>
                        <param-name>javax.ws.rs.Application</param-name>
                        <param-value>
                        org.glassfish.plummer.kernel.rest.RestApplication
                        </param-value>
                      </init-param>
                 </servlet>




Oracle Confidential                                                             17
JAX-RS Resources – Part 2
     • Use CDI to find JAX-RS resources
        – Use a marker interface, e.g. RestResource
        – Look up BeanManager in JNDI
           • BeanManager beanManager = (BeanManager)
                      initialContext.lookup("java:comp/BeanManager");
             – Ask CDI for the RestResource instances
                • beanManager.getBeans(RestResource.class);
             – Return set of Classes
                • Application.getClasses()




Oracle Confidential                                                     18

Mais conteúdo relacionado

Mais procurados

PHP Oracle Web Applications by Kuassi Mensah
PHP Oracle Web Applications by Kuassi MensahPHP Oracle Web Applications by Kuassi Mensah
PHP Oracle Web Applications by Kuassi MensahPHP Barcelona Conference
 
MySQL Group Replication - Ready For Production? (2018-04)
MySQL Group Replication - Ready For Production? (2018-04)MySQL Group Replication - Ready For Production? (2018-04)
MySQL Group Replication - Ready For Production? (2018-04)Kenny Gryp
 
MySQL Database Architectures - 2020-10
MySQL Database Architectures -  2020-10MySQL Database Architectures -  2020-10
MySQL Database Architectures - 2020-10Kenny Gryp
 
Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix
Provisioning with OSGi Subsystems and Repository using Apache Aries and FelixProvisioning with OSGi Subsystems and Repository using Apache Aries and Felix
Provisioning with OSGi Subsystems and Repository using Apache Aries and FelixDavid Bosschaert
 
Discuss about java 9 with latest features
Discuss about java 9 with latest featuresDiscuss about java 9 with latest features
Discuss about java 9 with latest featuresNexSoftsys
 
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3 Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3 Skills Matter
 
MySQL Group Replication
MySQL Group ReplicationMySQL Group Replication
MySQL Group ReplicationKenny Gryp
 
MySQL InnoDB Cluster / ReplicaSet - Tutorial
MySQL InnoDB Cluster / ReplicaSet - TutorialMySQL InnoDB Cluster / ReplicaSet - Tutorial
MySQL InnoDB Cluster / ReplicaSet - TutorialKenny Gryp
 
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11Kenny Gryp
 
자바 성능 강의
자바 성능 강의자바 성능 강의
자바 성능 강의Terry Cho
 
Java MySQL Connector & Connection Pool Features & Optimization
Java MySQL Connector & Connection Pool Features & OptimizationJava MySQL Connector & Connection Pool Features & Optimization
Java MySQL Connector & Connection Pool Features & OptimizationKenny Gryp
 
A Walking Tour of (almost) all of Springdom
A Walking Tour of (almost) all of Springdom A Walking Tour of (almost) all of Springdom
A Walking Tour of (almost) all of Springdom Joshua Long
 
Weblogic Administration Managed Server migration
Weblogic Administration Managed Server migrationWeblogic Administration Managed Server migration
Weblogic Administration Managed Server migrationRakesh Gujjarlapudi
 
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
MySQL Database Architectures - InnoDB ReplicaSet & ClusterMySQL Database Architectures - InnoDB ReplicaSet & Cluster
MySQL Database Architectures - InnoDB ReplicaSet & ClusterKenny Gryp
 
MySQL docker with demo by Ramana Yeruva
MySQL docker with demo by Ramana YeruvaMySQL docker with demo by Ramana Yeruva
MySQL docker with demo by Ramana YeruvaMysql User Camp
 
Oracle 11g R2 RAC implementation and concept
Oracle 11g R2 RAC implementation and conceptOracle 11g R2 RAC implementation and concept
Oracle 11g R2 RAC implementation and conceptSantosh Kangane
 
What’s New in Oracle Database 12c for PHP
What’s New in Oracle Database 12c for PHPWhat’s New in Oracle Database 12c for PHP
What’s New in Oracle Database 12c for PHPChristopher Jones
 
openark-kit: MySQL utilities for everyday use
openark-kit: MySQL utilities for everyday useopenark-kit: MySQL utilities for everyday use
openark-kit: MySQL utilities for everyday useShlomi Noach
 

Mais procurados (20)

PHP Oracle Web Applications by Kuassi Mensah
PHP Oracle Web Applications by Kuassi MensahPHP Oracle Web Applications by Kuassi Mensah
PHP Oracle Web Applications by Kuassi Mensah
 
MySQL Group Replication - Ready For Production? (2018-04)
MySQL Group Replication - Ready For Production? (2018-04)MySQL Group Replication - Ready For Production? (2018-04)
MySQL Group Replication - Ready For Production? (2018-04)
 
MySQL Database Architectures - 2020-10
MySQL Database Architectures -  2020-10MySQL Database Architectures -  2020-10
MySQL Database Architectures - 2020-10
 
Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix
Provisioning with OSGi Subsystems and Repository using Apache Aries and FelixProvisioning with OSGi Subsystems and Repository using Apache Aries and Felix
Provisioning with OSGi Subsystems and Repository using Apache Aries and Felix
 
MySQL JSON Functions
MySQL JSON FunctionsMySQL JSON Functions
MySQL JSON Functions
 
Discuss about java 9 with latest features
Discuss about java 9 with latest featuresDiscuss about java 9 with latest features
Discuss about java 9 with latest features
 
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3 Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
 
MySQL Group Replication
MySQL Group ReplicationMySQL Group Replication
MySQL Group Replication
 
MySQL InnoDB Cluster / ReplicaSet - Tutorial
MySQL InnoDB Cluster / ReplicaSet - TutorialMySQL InnoDB Cluster / ReplicaSet - Tutorial
MySQL InnoDB Cluster / ReplicaSet - Tutorial
 
Oracle Cloud As Services
Oracle Cloud As ServicesOracle Cloud As Services
Oracle Cloud As Services
 
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
 
자바 성능 강의
자바 성능 강의자바 성능 강의
자바 성능 강의
 
Java MySQL Connector & Connection Pool Features & Optimization
Java MySQL Connector & Connection Pool Features & OptimizationJava MySQL Connector & Connection Pool Features & Optimization
Java MySQL Connector & Connection Pool Features & Optimization
 
A Walking Tour of (almost) all of Springdom
A Walking Tour of (almost) all of Springdom A Walking Tour of (almost) all of Springdom
A Walking Tour of (almost) all of Springdom
 
Weblogic Administration Managed Server migration
Weblogic Administration Managed Server migrationWeblogic Administration Managed Server migration
Weblogic Administration Managed Server migration
 
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
MySQL Database Architectures - InnoDB ReplicaSet & ClusterMySQL Database Architectures - InnoDB ReplicaSet & Cluster
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
 
MySQL docker with demo by Ramana Yeruva
MySQL docker with demo by Ramana YeruvaMySQL docker with demo by Ramana Yeruva
MySQL docker with demo by Ramana Yeruva
 
Oracle 11g R2 RAC implementation and concept
Oracle 11g R2 RAC implementation and conceptOracle 11g R2 RAC implementation and concept
Oracle 11g R2 RAC implementation and concept
 
What’s New in Oracle Database 12c for PHP
What’s New in Oracle Database 12c for PHPWhat’s New in Oracle Database 12c for PHP
What’s New in Oracle Database 12c for PHP
 
openark-kit: MySQL utilities for everyday use
openark-kit: MySQL utilities for everyday useopenark-kit: MySQL utilities for everyday use
openark-kit: MySQL utilities for everyday use
 

Destaque

Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika AldabaLightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldabaux singapore
 
The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...Brian Solis
 
Open Source Creativity
Open Source CreativityOpen Source Creativity
Open Source CreativitySara Cannon
 
Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)maditabalnco
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsBarry Feldman
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome EconomyHelge Tennø
 

Destaque (7)

Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika AldabaLightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
 
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job? Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
 
The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...
 
Open Source Creativity
Open Source CreativityOpen Source Creativity
Open Source Creativity
 
Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post Formats
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome Economy
 

Semelhante a Writing Plugged-in Java EE Apps: Jason Lee

Java Future S Ritter
Java Future S RitterJava Future S Ritter
Java Future S Rittercatherinewall
 
In the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: GradleIn the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: GradleSkills Matter
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules uploadRyan Cuprak
 
The Diabolical Developer's Guide to Surviving Java 9
The Diabolical Developer's Guide to Surviving Java 9The Diabolical Developer's Guide to Surviving Java 9
The Diabolical Developer's Guide to Surviving Java 9jClarity
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang YoonJesang Yoon
 
GlassFish REST Administration Backend
GlassFish REST Administration BackendGlassFish REST Administration Backend
GlassFish REST Administration BackendArun Gupta
 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012Arun Gupta
 
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...Jesse Gallagher
 
Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...
Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...
Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...Sigma Software
 
JavaOne 2016: Life after Modularity
JavaOne 2016: Life after ModularityJavaOne 2016: Life after Modularity
JavaOne 2016: Life after ModularityDanHeidinga
 
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...JAXLondon2014
 
Testing the Enterprise layers, with Arquillian
Testing the Enterprise layers, with ArquillianTesting the Enterprise layers, with Arquillian
Testing the Enterprise layers, with ArquillianVirtual JBoss User Group
 
Content Storage With Apache Jackrabbit
Content Storage With Apache JackrabbitContent Storage With Apache Jackrabbit
Content Storage With Apache JackrabbitJukka Zitting
 
Leaner microservices with Java 10
Leaner microservices with Java 10Leaner microservices with Java 10
Leaner microservices with Java 10Arto Santala
 
CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011Alexander Klimetschek
 
Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Tomek Kaczanowski
 
Perils Of Url Class Loader
Perils Of Url Class LoaderPerils Of Url Class Loader
Perils Of Url Class LoaderKaniska Mandal
 
Eclipse Concierge - an OSGi R5 framework for IoT applications
Eclipse Concierge - an OSGi R5 framework for IoT applicationsEclipse Concierge - an OSGi R5 framework for IoT applications
Eclipse Concierge - an OSGi R5 framework for IoT applicationsjochen.hiller
 

Semelhante a Writing Plugged-in Java EE Apps: Jason Lee (20)

Gradle
GradleGradle
Gradle
 
Java Future S Ritter
Java Future S RitterJava Future S Ritter
Java Future S Ritter
 
In the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: GradleIn the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: Gradle
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
 
The Diabolical Developer's Guide to Surviving Java 9
The Diabolical Developer's Guide to Surviving Java 9The Diabolical Developer's Guide to Surviving Java 9
The Diabolical Developer's Guide to Surviving Java 9
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoon
 
GlassFish REST Administration Backend
GlassFish REST Administration BackendGlassFish REST Administration Backend
GlassFish REST Administration Backend
 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012
 
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
CollabSphere 2021 - DEV114 - The Nuts and Bolts of CI/CD With a Large XPages ...
 
Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...
Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...
Android App Architecture with modern libs in practice. Our way in R.I.D., Ser...
 
JavaOne 2016: Life after Modularity
JavaOne 2016: Life after ModularityJavaOne 2016: Life after Modularity
JavaOne 2016: Life after Modularity
 
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
 
Testing the Enterprise layers, with Arquillian
Testing the Enterprise layers, with ArquillianTesting the Enterprise layers, with Arquillian
Testing the Enterprise layers, with Arquillian
 
Content Storage With Apache Jackrabbit
Content Storage With Apache JackrabbitContent Storage With Apache Jackrabbit
Content Storage With Apache Jackrabbit
 
Leaner microservices with Java 10
Leaner microservices with Java 10Leaner microservices with Java 10
Leaner microservices with Java 10
 
CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011CQ5 QueryBuilder - .adaptTo(Berlin) 2011
CQ5 QueryBuilder - .adaptTo(Berlin) 2011
 
Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010
 
Perils Of Url Class Loader
Perils Of Url Class LoaderPerils Of Url Class Loader
Perils Of Url Class Loader
 
Java 9 Features
Java 9 FeaturesJava 9 Features
Java 9 Features
 
Eclipse Concierge - an OSGi R5 framework for IoT applications
Eclipse Concierge - an OSGi R5 framework for IoT applicationsEclipse Concierge - an OSGi R5 framework for IoT applications
Eclipse Concierge - an OSGi R5 framework for IoT applications
 

Último

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 productivityPrincipled Technologies
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
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 StreamsRoshan Dwivedi
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
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 RobisonAnna Loughnan Colquhoun
 
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 businesspanagenda
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Último (20)

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
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Writing Plugged-in Java EE Apps: Jason Lee

  • 1. <Insert Picture Here> Writing Plugged-In Java EE Apps Jason Lee July 9, 2012
  • 2. Who Am I? • Principal MTS for Oracle Corporation (by way of Sun Microsystems) • Member of GlassFish team – RESTful Management APIs – Administration Console • JSF user/developer • Live in Oklahoma City, OK Oracle Confidential 2
  • 3. Introduction • Plugins are not a new concept – Means of providing extensibility or decomposing and decoupling functionality – The concept has been around for years • NetBeans/Eclipse/IDEA • Wordpress • Hudson • The what and why are easy. The how is the hard part. – How do I get access to the plugin code? – How do I identify the plugins deployed with the system – How do I expose core system functionality to the plugins Oracle Confidential 3
  • 4. Introduction – cont. • Some background – GlassFish 3.x Administration Console • Core application does very little • All actual functionality delivered as plugins • Based on proprietary technologies – HK2/OSGi – JSFTemplating – For GlassFish 4.x, the basic stack had to change • Reevaluate whole system • Investigate HK2/OSGi, CDI, existing systems, etc. • Design a system based on modern technologies, preferably standards Oracle Confidential 4
  • 5. Problem #1 – Class Loading • The hard part – Where do I put the jar files? – How do I load them? • Three (probably of many) choices – Repackaging – Manual ClassLoading – OSGi Oracle Confidential 5
  • 6. Problem #1 - Class Loading - Repackaging • Simple and portable – Guaranteed to support every Java EE technology supported in .war files • Ant-/Maven-/etc-based – Base distribution war – Collection of plugins – War rebuilt to include plugin jars • Liferay uses this. Works well. • Redeploys/upgrades take a bit more time/work Oracle Confidential 6
  • 7. Problem #1 - Class Loading - Repackaging #!/bin/bash DIST=$1 if [ "$DIST" == "" ] ; then echo "You must specify the distribution .war" exit 1 fi BASE=`echo $DIST | sed -e 's/.war//'` rm -rf work mkdir work cd work jar xf ../$DIST cp ../plugins/*jar WEB-INF/lib jar cf ../$BASE-repackaged.war * cd .. rm -rf work Oracle Confidential 7
  • 8. Problem #1 - Class Loading – Manual ClassLoading • Filesystem-based – Much like Wordpress • wordpress/wp-content/plugins/* – ~/.plugins • War is deployed unchanged • Fairly portable, in theory – Demo works on GlassFish – Currently breaks on JBoss – Should be easily solvable • Demo - Plummer Oracle Confidential 8
  • 9. Problem #1 - Class Loading – Manual ClassLoading public class PluginLoader implements Extension { // ... public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd, BeanManager beanManager) { for (PluginFinder pluginFinder : getPluginFinders()) { try { for (Class<?> clazz : pluginFinder.getClasses()) { final AnnotatedType<?> annotatedType = beanManager.createAnnotatedType(clazz); logger.log(Level.INFO, "Adding AnnotatedType for {0}", annotatedType.toString()); bbd.addAnnotatedType(annotatedType); } } catch (Exception ex) { Logger.getLogger(PluginLoader.class.getName()).log(Level.SEVERE, null, ex); } } } // ... } Oracle Confidential 9
  • 10. Problem #1 – Class Loading - OSGi • Well-defined and understood solution • Web Application Bundles not quite what we need – Requires repackaging • Container must support OSGi • Deployment will likely vary between containers Oracle Confidential 10
  • 11. Problem #1 – Class Loading - OSGi public class PluginActivator implements BundleActivator { @Override public void start(BundleContext context) throws Exception { ServiceTracker tracker = new ServiceTracker(context, PluginTracker.class.getName(), null); tracker.open(); PluginTracker pt = (PluginTracker)tracker.getService(); if (pt != null) { pt.registerPluginBundle(context.getBundle()); } tracker.close(); } @Override public void stop(BundleContext context) throws Exception { } } Oracle Confidential 11
  • 12. Problem #1 – Class Loading - OSGi public class PluginTrackerImpl implements PluginTracker { @Override public void registerPluginBundle(Bundle bundle) { if (bundle.getEntry("META-INF/beans.xml") != null) { Enumeration<URL> e = bundle.findEntries("/", "*.class", true); while (e.hasMoreElements()) { String className = e.nextElement().getPath().substring(1).replace("/", "."); className = className.substring(0, className.length()-6); classes.add(className); } } } public Set<String> getClasses() { return classes; } } Oracle Confidential 12
  • 13. Problem #1 – Class Loading - OSGi public class PlummerActivator implements BundleActivator { @Override public void start(BundleContext context) throws Exception { context.registerService(PluginTracker.class.getName(), PluginTrackerImpl.instance(), new Properties()); } @Override public void stop(BundleContext context) throws Exception { context.ungetService(context.getServiceReference(PluginTracker.class.getName())); } } Oracle Confidential 13
  • 14. Problem #2 – Application Design • Largely application-specific • General strategies and techniques can be defined • Once plugins are loaded, how are they integrated into the application? – Java EE to the rescue • JSF • CDI • REST Oracle Confidential 14
  • 15. JSF Extensibility • Views decomposed into fragments • Custom component used to insert fragments – pl:viewFragment • Current solution is Mojarra-specific – MyFaces solution needed – Can also be implemented in Swing/JavaFX Oracle Confidential 15
  • 16. CDI – The Real Work Horse • CDI Events – Pub/Sub – Loose coupling – Multiple Receivers • Programmatic Bean Lookup – Instance<Foo> – Iterate over over instances Oracle Confidential 16
  • 17. JAX-RS Resources • Plugins can provide REST resources • Configure using Application rather than a package – javax.ws.rs.core.Application – <servlet> <servlet-name>Jersey Web Application</servlet-name> <servlet-class> com.sun.jersey.spi.container.servlet.ServletContainer </servlet-class> <init-param> <param-name>javax.ws.rs.Application</param-name> <param-value> org.glassfish.plummer.kernel.rest.RestApplication </param-value> </init-param> </servlet> Oracle Confidential 17
  • 18. JAX-RS Resources – Part 2 • Use CDI to find JAX-RS resources – Use a marker interface, e.g. RestResource – Look up BeanManager in JNDI • BeanManager beanManager = (BeanManager) initialContext.lookup("java:comp/BeanManager"); – Ask CDI for the RestResource instances • beanManager.getBeans(RestResource.class); – Return set of Classes • Application.getClasses() Oracle Confidential 18