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.

MyFaces CODI and JBoss Seam3 become Apache DeltaSpike


Published on

These slides show how to use type-safe mechanisms provided by MyFaces CODI for developing JSF applications which are more type-safe and easier to maintain as well as common pitfalls. Beyond that there is an basic overview of Apache DeltaSpike.

Published in: Technology
  • Be the first to comment

MyFaces CODI and JBoss Seam3 become Apache DeltaSpike

  2. 2. Apache MyFaces CODI is …• … a portable CDI extension (no CDI implementation)• … compatible with Java-EE5+• … tested on most major servers• … easy to use and extensible• … very fast and stable• … one "part" of Apache DeltaSpike• … one of few popular CDI extensions• … optimized for large applications• … developed by an open community
  3. 3. History of MyFaces CODI• Apache MyFaces Orchestra introduced interesting concepts in combination with Spring• 12-2009 CDI 1.0• 2-2010 MyFaces ExtCDI (aka CODI) started• 11-2010 first stable release (6 modules)• 7-2011 release of v1.0.0 (formal step - CODI was very stable already)
  4. 4. Setup MyFaces CODI for Servlet Containers• Add the CDI implementation of your choice• Add MyFaces CODI to the project – With Maven • Add the modules (or the all-in-one bundle) to the POM – Without Maven • Download the current version of CODI • Add the modules (or the all-in-one bundle) to the Classpath of the project• Start using it!
  5. 5. Webapp Setup by Example with Maven - 1• The easy way: Add the all-in-one bundle for the version of JSF you are using (1.2.x or 2.x) Example for JSF 2.x <dependency> <groupId>org.apache.myfaces.extensions.cdi.bundles</groupId> <artifactId>myfaces-extcdi-bundle-jsf20</artifactId> <version>1.0.5</version> <scope>compile</scope> </dependency>
  6. 6. Webapp Setup by Example with Maven - 2• An alternative: Generate a template project mvn archetype:generate -DarchetypeCatalog= Example for JSF 2.x
  7. 7. Webapp Setup by Example without Maven• Download the binary distribution which contains all modules: -> e.g.: or the all-in-one bundle: -> e.g.: myfaces-extcdi-bundle-jsf20/1.0.5/ myfaces-extcdi-bundle-jsf20-1.0.5.jar• Add the JAR(s) of your choice to /WEB-INF/lib
  8. 8. MyFaces CODI Modules - Overview - 1• Core• JSF Module (for 1.2 and 2.x)• JPA Module• BV Module• I18N-Message Module• Scripting Module
  9. 9. MyFaces CODI Modules - Overview - 2• Trinidad Support Module (for 1.x and 2.x)• Java-EE5 Support Module• Bundles (+ OSGi Bundles)• Test Modules• Alternative Config and Impl Modules
  10. 10. MyFaces CODI – TOP 10 (unordered)• Type-safe and extensible Project-Stages• Conditional bean activation• Scopes• Type-safe View-Config and Navigation Workshop• Type-safe CODI-Config examples• View-Controller• Extensibility (Security, Interceptors, Factories, …)• Advanced I18n• Transactional beans without EJBs• Configurable JPA DataSource
  11. 11. Symbols DS … Same concept used for DeltaSpike DS … Similar concept used for DeltaSpike DS … Concept planned for DeltaSpike
  12. 12. Type-safe and extensible Project-Stages DS• … with Java-EE6 – Only available in JSF – Not type-safe – Not extensible• … with MyFaces CODI – Available for all CDI based applications – Type-safe – Extensible
  13. 13. Project-Stages Configuration by Example• Configuration – Not in the deployable archive (e.g. web.xml) – Via build- or container-configuration – Useful e.g. in combination with maven profiles• Example with Jetty (+ Maven3) <configuration> <systemProperties> <systemProperty> <name>faces.PROJECT_STAGE</name> <value>Development</value> </systemProperty> </systemProperties> </configuration>
  14. 14. Conditional Bean Activation DS• … with Java-EE6 – Not out-of-the-box (Manually via a CDI-Extension and ProcessAnnotatedType#veto)• … with MyFaces CODI – @ProjectStageActivated (supports also custom project-stages) – @ExpressionActivated (+ customizable expression syntax)
  15. 15. @ProjectStageActivated by Example@Alternative //+ config in beans.xml@ProjectStageActivated(ProjectStage.Production.class)public class ProductionCodiCoreConfig extends CodiCoreConfig{ @Override public boolean isConfigurationLoggingEnabled() { return false; }}
  16. 16. Scopes• … with std. CDI and JSF (JSF Scopes not integrated ) – Request-, Session-, Application-Scope – View-, Flash-, Custom-, None-Scope (JSF) – Conversation-, Dependent, Singleton-Scope (CDI)• … with MyFaces CODI – Autom. converts JSF beans to CDI beans DS – Window-, (Grouped-)Conversation-, ViewAccess-, Rest-Scope (for CDI + JSF) – Transaction-Scope (for CDI) Different types of conversations
  17. 17. CODI Scopes by Example - Window-Scope• Without MyFaces CODI – e.g.: @SessionScoped public class MyBean implements Serializable { //… } -> multiple Browser-Tabs use the same instances• With MyFaces CODI – e.g.: @WindowScoped public class MyBean implements Serializable { //… }
  18. 18. Destroy MyFaces CODI Conversations• Close a conversation @Inject private Conversation conversation; this.conversation.close();• Use the Window-Context @Inject private WindowContext windowContext; this.windowContext.close(); //and #close*
  19. 19. Type-safe View-Config• … with std. JSF – Not available• … with MyFaces CODI DS – Type-safe navigation – View-Controller, Security,… – Meta-data inheritance – Custom meta-data – Checked target regions
  20. 20. Type-safe View-Config by Example – 1• Allow to – host meta-data for pages – structure pages – navigate in a type-safe way – inherit meta-data• Inline usage at page-beans is possible• Example for index.xhtml @Page public class Index implements ViewConfig {}
  21. 21. Type-safe View-Config by Example – 2• POST-Requests <h:commandButton … action="#{}"/> public Class<? extends ViewConfig> next() { //Pages extends ViewConfig, Index implements Pages return Pages.Index.class; }• GET-Requests <h:link ... outcome="#{myPageController.nextPage}"/> public Class<? extends Pages> getNextPage() { //Pages extends ViewConfig, Index implements Pages return Pages.Index.class; }
  22. 22. Type-safe View-Config - Advanced• – View-Controller Annotations – Integration with @Secured – Default Error-View – Easy manual navigation via ViewNavigationHandler – Observe a pre-navigation event (navigation target can be changed) – Custom Meta-data –…
  25. 25. Migration to Java-EE6+ Application Server• General steps for all servers: – Java-EE dependencies are provided by the server (-> don’t deploy them) – Remove the CDI listener (web.xml)
  26. 26. Migration to Oracle GlassFish 3.1.x• Java-EE6 reference implementation• CDI Implementation: JBoss Weld• Use version 3.1.2+ if possible (at least v3.1.1)• Needed changes: – Std. changes for Java-EE6+ – See BDA hints esp. for GlassFish < v3.1.2
  27. 27. Migration to IBM WebSphere 8• First WAS version which implements Java-EE6• CDI Implementation: OpenWebBeans (with BDA)• Use version• Needed changes: – Std. changes for Java-EE6+ – See BDA hints (OpenWebBeans is used in BDA mode)
  28. 28. Migration to JBoss-AS7• JBoss Application Server (implemented from scratch)• Since 7.1 Java-EE6 full profile• CDI Implementation: JBoss Weld• Needed changes: – Std. changes for Java-EE6+ – See BDA hints
  29. 29. Migration to Oracle Weblogic 12c (R1)• First WLS version which implements Java-EE6• CDI Implementation: JBoss Weld 1.1.3_SP1• Needed changes: – Std. changes for Java-EE6+ – See BDA hints – Use the all-in-one bundle of MyFaces CODI 1.0.5+
  30. 30. Migration to Apache TomEE v1• TomEE is based on a std. Tomcat – Java-EE6 Web-Profile CDI, EJB, JPA, JSF, JSP, JSTL, JTA, Servlet, JavaMail, Bean Validation – TomEE+ adds JAX-RS, JAX-WS, JMS, Connectors• CDI Implementation: Apache OpenWebBeans• Needed changes: – Std. changes for Java-EE6+ -> That’s it
  31. 31. Using MyFaces CODI with …• A list of tested servers and frameworks:
  32. 32. Common Pitfalls – Bootstrapping order• Java-EE6 servers usually start CDI before JSF• Not all servers have a deterministic order• Sometimes it depends on the version – e.g.: Jetty6 vs Jetty7 (vs Jetty8)• Exception: IllegalStateException: no […]BeanManagerProvider in place! Please ensure that you configured the CDI implementation of your choice properly. If your setup is correct, please clear all caches and compiled artifacts. If there is still a problem, try one of the controlled bootstrapping add-ons for the CDI implementation you are using.• Solutions: – The exception provides the details already – Another exception occurred before -> fix it
  33. 33. Common Pitfalls – Cross-BDAs issues• Bean deployment archives The implementation depends on the interpretation of the specification• Spec. issues: CDI-18, CDI-112 – A strict implementation restricts various artifacts to the same bean archive – A misinterpretation or bug can break applications easily E.g.: @Alternative annotated beans are only valid for the same archive -> breaks a lot of use-cases -> OWB (standalone) ignores this rule by default• Implementation issues: – Several versions of Weld < v1.1.4 are broken e.g. regarding @Specialize WELD-912, WELD-974,…
  34. 34. Common Pitfalls – BDAs (of CDI 1.0) - 1• Exceptions – Enabled interceptor class SecurityInterceptor is neither annotated @Interceptor nor registered through a portable extension – No bean found for type: [CODI class] – Unsatisfied dependencies for type [CODI class]• Solutions (steps): step until it works 1. Use the all-in-one package of MyFaces CODI Follow it step by 2. Copy the content of beans.xml to the beans.xml of the application 3. The version of the CDI implementation is utterly broken -> upgrade it
  35. 35. Common Pitfalls – BDAs (of CDI 1.0) - 2• Exceptions – Interceptor class: SecurityInterceptor is already defined• Solutions: – Ensure that jar files aren’t duplicated in the deployed archive (e.g. different versions,…) – Clear IDE and server caches (if it happens during the development process)
  36. 36. Common Pitfalls – Old Versions• Try to use the newest version of the application-server of your choice from the very beginning• It isn‘t just about small tweaks. Some old versions are utterly broken• If an old version can’t be avoided, upgrade the CDI implementation (if possible)
  37. 37. Common Pitfalls – ContextNotActive• Top 3 reasons 1. Invalid usage (e.g. JSF specific context used in a Servlet-Filter, Batch-Job,…) 2. Configuration issue 3. Implementation issue (of the context)
  38. 38. … closes the gaps!APACHE DELTASPIKE
  39. 39. History of DeltaSpike• 12-2011 accepted to join the Apache Incubator• 2-2012 first release (0.1-incubating)
  40. 40. ASF Mentors• David Blevins• Gerhard Petracek• Jim Jagielski• Mark Struberg• Matt Benson• Matthias Wessendorf
  41. 41. Initial Committers - 1• Andy Gibson• Antoine Sabot-Durand• Arne Limburg• Brian Leathem• Cody Lerum• David Blevins• George Gastaldi• Gerhard Petracek
  42. 42. Initial Committers - 2• Jakob Korherr• Jason Porter• John Ament• Jozef Hartinger• Ken Finnigan• Marius Bogoevici• Mark Struberg• Matthias Wessendorf
  43. 43. Initial Committers - 3• Pete Muir• Pete Royle• Rick Hightower• Shane Bryzak• Stuart Douglas• //some joined short afterwards
  44. 44. DeltaSpike Modules• 0.1-incubating – Core (new)• 0.2-incubating – Core (improved) – Security (new)
  45. 45. DeltaSpike closes the gaps between …• … Java-EE and the needs of real-world applications• … different CDI communities
  46. 46. History of Apache DeltaSpike Java-EE with CDI Java-EE Other Seam2 Seam3without CDI Extensions Spring DeltaSpike Framework MyFaces MyFaces CODI Orchestra + CDI implementation
  47. 47. MyFaces CODI to DeltaSpike Migration• Discussions are started with the original feature/concept• Everybody is welcome to provide a refinement or counter-proposal• If there is no better solution and there are no major objections, a feature will be added• The community tries to merge everything which is completely portable
  48. 48. Apache DeltaSpike.Next• Simple answer: There is no fixed master plan! The future depends on the community -> get involved!
  50. 50. FINAL Q & A
  51. 51. Links•••••••••