Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.
Enterprise Development 
with …
What needs to be done to run 
JEE like applications inside Karaf?
2014-­‐10-­‐23 
3 
@anierbeck 
- Karaf PMC, Apache Member 
- OPS4j Pax Web Project Lead 
- Senior IT Consultant @codecentr...
Agenda 
• Enterprise Requirements 
• OSGi with Karaf 
• Enterprise Requirements on Karaf 
• Specialties 
• Http Service 
•...
Enterprise Requirements
Enterprise Java 
EJB 3.1 CDI 
2014-­‐10-­‐23 
6 
Servlet 3 
JSF 2 
JSP 
JPA 2 
JTA 
Bean 
Validation 
JAX-WS JAX-RS 
JAXR ...
OSGi with Karaf
OSGi - a very brief introduction 
• Modular 
• OSGi Bundles: 
• High Cohesion (One classloader/bundle) 
• Low Coupling (Pa...
What is Karaf 
• Container 
• OSGi Applications 
• Ligthtweight 
• expandable to Full Enterprise support 
• Covers all maj...
Karaf - Overview 
2014-­‐10-­‐23 
10 
Config Logging Deployer 
Console Admin 
OSGi Framework - Felix / Equinox 
JMX 
Bluep...
Enterprise requirements on Karaf
Karaf 
EJB 3.1 CDI 
2014-­‐10-­‐23 
12 
Servlet 3 
JSF 2 
JSP 
JPA 2 
JTA 
Bean 
Validation 
JAX-WS JAX-RS 
JAXR 
JAXB 
JM...
Enterprise - Pax Web 
EJB 3.1 CDI 
2014-­‐10-­‐23 
13 
Servlet 3 
JSF 2 
JSP 
JPA 2 
JTA 
Bean 
Validation 
JAX-WS JAX-RS ...
Enterprise - Pax CDI 
EJB 3.1 CDI 
2014-­‐10-­‐23 
14 
Servlet 3 
JSF 2 
JSP 
JPA 2 
JTA 
Bean 
Validation 
JAX-WS JAX-RS ...
Enterprise - Aries 
EJB 3.1 CDI 
2014-­‐10-­‐23 
15 
Servlet 3 
JSF 2 
JSP 
JPA 2 
JTA 
Bean 
Validation 
JAX-WS JAX-RS 
J...
Enterprise - Tomee aka OpenEJB 
EJB 3.1 CDI 
2014-­‐10-­‐23 
16 
Servlet 3 
JSF 2 
JSP 
JPA 2 
JTA 
Bean 
Validation 
JAX-...
Enterprise - CXF 
EJB 3.1 CDI 
2014-­‐10-­‐23 
17 
Servlet 3 
JSF 2 
JSP 
JPA 2 
JTA 
Bean 
Validation 
JAX-WS 
JAX-RPC 
J...
Enterprise - ActiveMQ 
EJB 3.1 CDI 
2014-­‐10-­‐23 
18 
Servlet 3 
JSF 2 
JSP 
JPA 2 
JTA 
Bean 
Validation 
JAX-WS 
JAX-R...
Enterprise - Cellar 
EJB 3.1 CDI 
2014-­‐10-­‐23 
19 
Servlet 3 
JSF 2 
JSP 
JPA 2 
JTA 
Bean 
Validation 
JAX-WS 
JAX-RPC...
Enterprise - Karaf with features 
EJB 3.1 CDI 
2014-­‐10-­‐23 
20 
Servlet 3 
JSF 2 
JSP 
JPA 2 
JTA 
Bean 
Validation 
JA...
Specialties
JPA - Karaf 
2014-­‐10-­‐23 
22 
<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
xmlns:xsi="http://www.w3.org...
JPA - Karaf 
2014-­‐10-­‐23 
22 
<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
xmlns:xsi="http://www.w3.org...
JTA - Karaf 
2014-­‐10-­‐23 
23 
<blueprint default-activation=„eager" 
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"...
JTA - Karaf 
2014-­‐10-­‐23 
23 
<blueprint default-activation=„eager" 
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"...
Client - Karaf 
2014-­‐10-­‐23 
24 
<?xml version="1.0" encoding="UTF-8"?> 
<blueprint xmlns="http://www.osgi.org/xmlns/bl...
Demo
Persistence 
2014-­‐10-­‐23 
26
Client 
2014-­‐10-­‐23 
27
Client Shell 
2014-­‐10-­‐23 
28
Client - Shell 
2014-­‐10-­‐23 
29
Client Shell 
2014-­‐10-­‐23 
30
Client - Shell 
2014-­‐10-­‐23 
31
Http Service 
with …
HTTP Service 
2014-­‐10-­‐23 
33 
• Using an Activator: 
final HttpContext httpContext = httpService 
.createDefaultHttpCo...
Whiteboard 
• Using the whiteboard approach via Activator 
public void start(BundleContext bc) throws Exception { 
bundleC...
Whiteboard 
2014-­‐10-­‐23 
35 
• Using the whiteboard approach via Blueprint 
<blueprint default-activation="eager"> 
<re...
Servlet 3.0 - Just annotation 
2014-­‐10-­‐23 
36 
@WebServlet(urlPatterns = "/book") 
public class ViewBookServlet extend...
LOST?
Registering - Servlet 
2014-­‐10-­‐23 
38 
Pax-Web 
HTTP Service 
Service- 
Registry 
Servlet
Registering - Servlet 
2014-­‐10-­‐23 
38 
Pax-Web 
HTTP Service 
Service- 
Registry 
Servlet 
Registerd
Registering - Servlet 
2014-­‐10-­‐23 
38 
Pax-Web 
HTTP Service 
Service- 
Registry 
Servlet 
Registerd 
Registerd
Registering - Whiteboard 
2014-­‐10-­‐23 
39 
Pax-Web 
WebContainer 
Service-Tracker 
Service- 
Registry 
Servlet
Registering - Whiteboard 
2014-­‐10-­‐23 
39 
Pax-Web 
WebContainer 
Service-Tracker 
Service- 
Registry 
Servlet 
Registe...
Registering - Whiteboard 
2014-­‐10-­‐23 
39 
Pax-Web 
WebContainer 
Service-Tracker 
Service- 
Registry 
Servlet 
Registe...
Registering - Whiteboard 
2014-­‐10-­‐23 
39 
Pax-Web 
WebContainer 
Service-Tracker 
Service- 
Registry 
Servlet 
Registe...
Registering - WAR 
2014-­‐10-­‐23 
40 
Pax-Web 
WebContainer 
Pax-Web 
WAR Extender 
Service- 
Registry 
WAB-Bundle 
Servl...
Registering - WAR 
2014-­‐10-­‐23 
40 
Pax-Web 
WebContainer 
Pax-Web 
WAR Extender 
Service- 
Registry 
WAB-Bundle 
Servl...
Registering - WAR 
2014-­‐10-­‐23 
40 
Pax-Web 
WebContainer 
Pax-Web 
WAR Extender 
Service- 
Registry 
WAB-Bundle 
Servl...
Registering - WAR 
2014-­‐10-­‐23 
40 
Pax-Web 
WebContainer 
Pax-Web 
WAR Extender 
Service- 
Registry 
WAB-Bundle 
Servl...
Servlet + JPA / Service 
2014-­‐10-­‐23 
41 
Blueprint 
Extender 
Pax-Web 
WAR Extender 
JPA-Bundle 
Service- 
Registry 
J...
Servlet + JPA / Service 
2014-­‐10-­‐23 
41 
Blueprint 
Extender 
Pax-Web 
WAR Extender 
JPA-Bundle 
Service- 
Registry 
J...
Servlet + JPA / Service 
2014-­‐10-­‐23 
41 
Blueprint 
Extender 
Pax-Web 
WAR Extender 
JPA-Bundle 
Service- 
Registry 
J...
Servlet + JPA / Service 
2014-­‐10-­‐23 
41 
Blueprint 
Extender 
Pax-Web 
WAR Extender 
JPA-Bundle 
Service- 
Registry 
J...
Demo
View 
2014-­‐10-­‐23 
43
View 
2014-­‐10-­‐23 
44
Cluster 
provided by Apache Karaf Cellar
Cellar - Cluster Communication 
2014-­‐10-­‐23 
46
Cellar - Cluster Communication 
2014-­‐10-­‐23 
47 
Hazelcast
Cellar - Events 
2014-­‐10-­‐23 
48
Cellar - Distributing Bundles 
2014-­‐10-­‐23 
49 
Node A 
Node B 
Node C 
Maven Repository 
Hazelcast
Cellar - Distributing Bundles 
2014-­‐10-­‐23 
49 
Node A 
Node B 
Node C 
Maven Repository 
osgi:install mvn:groupId/arti...
Cellar - Distributing Bundles 
2014-­‐10-­‐23 
49 
Node A 
Node B 
Node C 
Maven Repository 
Hazelcast
Cellar - Distributing Bundles 
2014-­‐10-­‐23 
49 
Node A 
Node B 
Node C 
Maven Repository 
Hazelcast
Cellar - Distributing Bundles 
2014-­‐10-­‐23 
49 
Node A 
Node B 
Node C 
Maven Repository 
Hazelcast
Cellar - Distributing Bundles 
2014-­‐10-­‐23 
49 
Node A 
Node B 
Node C 
Maven Repository 
Hazelcast
Cellar - Distributing Bundles 
2014-­‐10-­‐23 
49 
Node A 
Node B 
Node C 
Maven Repository 
Hazelcast
Cellar - Distributing Bundles 
2014-­‐10-­‐23 
49 
Node A 
Node B 
Node C 
Maven Repository 
Hazelcast
Cellar - Distributing Bundles 
2014-­‐10-­‐23 
49 
Node A 
Node B 
Node C 
Maven Repository 
Hazelcast 
DEPRECATED
Cellar - Distributing Bundles 
2014-­‐10-­‐23 
49 
Node A 
Node B 
Node C 
Maven Repository 
cluster:install mvn:groupId/a...
Cellar - RMI 
2014-­‐10-­‐23 
50 
Group 1 
Node A 
Consumes OSGi-Service 
Group 2 
Node B 
Consumes OSGi-Service 
Node C 
...
Cellar - Web session failover 
2014-­‐10-­‐23 
51 
Node A 
Hazelcast 
DataBase 
Client 
Filter Servlet 
Node B 
Filter Ser...
Cellar - Web session failover 
2014-­‐10-­‐23 
51 
Node A 
Hazelcast 
DataBase 
Client 
Filter Servlet 
Node B 
Filter Ser...
Cellar - Web session failover 
2014-­‐10-­‐23 
51 
Node A 
Hazelcast 
DataBase 
Client 
Filter Servlet 
Node B 
Filter Ser...
Cellar - Web session failover 
2014-­‐10-­‐23 
51 
Node A 
Hazelcast 
DataBase 
Client 
Filter Servlet 
Node B 
Filter Ser...
Cellar - Web session failover 
2014-­‐10-­‐23 
51 
Node A 
Hazelcast 
DataBase 
Client 
Filter Servlet 
Node B 
Filter Ser...
Cellar - Web session failover 
2014-­‐10-­‐23 
51 
Node A 
Hazelcast 
DataBase 
Client 
Filter Servlet 
Node B 
Filter Ser...
Cellar - Web session failover 
2014-­‐10-­‐23 
51 
Node A 
Hazelcast 
DataBase 
Client 
Filter Servlet 
Node B 
Filter Ser...
Cellar - Web session failover 
2014-­‐10-­‐23 
51 
Node A 
Hazelcast 
DataBase 
Client 
Filter Servlet 
Node B 
Filter Ser...
Cellar - Web session failover 
2014-­‐10-­‐23 
51 
Node A 
Hazelcast 
DataBase 
Client 
Filter Servlet 
Node B 
Filter Ser...
Cellar - Web session failover 
2014-­‐10-­‐23 
51 
Node A 
Hazelcast 
DataBase 
Client 
Filter Servlet 
Node B 
Filter Ser...
Cellar - Web session failover 
2014-­‐10-­‐23 
51 
Node A 
Hazelcast 
DataBase 
Client 
Filter Servlet 
Node B 
Filter Ser...
Cellar - Web session failover 
2014-­‐10-­‐23 
51 
Node A 
Hazelcast 
DataBase 
Client 
Filter Servlet 
Node B 
Filter Ser...
Cellar - Web session failover 
2014-­‐10-­‐23 
51 
Node A 
Hazelcast 
DataBase 
Client 
Filter Servlet 
Node B 
Filter Ser...
Cluster - Demo
Presentation Layer 
2014-­‐10-­‐23 
53
web.xml - Hazelcast 
2014-­‐10-­‐23 
54 
• Hazelcast for Session Replication 
<?xml version="1.0" encoding="UTF-8"?> 
<web...
View 
2014-­‐10-­‐23 
55
View 
2014-­‐10-­‐23 
56
View 
2014-­‐10-­‐23 
57
SUMMARY
Enterprise - Karaf 
2014-­‐10-­‐23 
59 
Servlet 3 
EJB 3.1 CDI 
JSF 2 
JSP 
JPA 2 
JTA 
JAX-WS 
JAX-RPC 
JAX-RS 
JAXR 
SAA...
JEE with Karaf? 
• Adoptions needed? YES 
• Minor on Persistence - JNDI lookup 
• Minor on transaction - Blueprint JTA 
• ...
Resources 
• @anierbeck 
• notitzblog.nierbeck.de 
• https://github.com/ANierbeck/karaf-enterprise-sample 
• www.codecentr...
THANKS FOR LISTENING
Thanks to the Apache 
Community
Questions
Thanks
ApacheCon EU 2014: Enterprise Development with Apache Karaf
Nächste SlideShare
Wird geladen in …5
×

ApacheCon EU 2014: Enterprise Development with Apache Karaf

4.305 Aufrufe

Veröffentlicht am

Enterprise Development with Apache Karaf, or what needs to be done to run JEE like applications in Apache Karaf

Veröffentlicht in: Ingenieurwesen
  • Als Erste(r) kommentieren

ApacheCon EU 2014: Enterprise Development with Apache Karaf

  1. 1. Enterprise Development with …
  2. 2. What needs to be done to run JEE like applications inside Karaf?
  3. 3. 2014-­‐10-­‐23 3 @anierbeck - Karaf PMC, Apache Member - OPS4j Pax Web Project Lead - Senior IT Consultant @codecentric - co-Author of Apache Karaf Cookbook
  4. 4. Agenda • Enterprise Requirements • OSGi with Karaf • Enterprise Requirements on Karaf • Specialties • Http Service • Cellar - or how to cluster Karaf • Summary 2014-­‐10-­‐23 4
  5. 5. Enterprise Requirements
  6. 6. Enterprise Java EJB 3.1 CDI 2014-­‐10-­‐23 6 Servlet 3 JSF 2 JSP JPA 2 JTA Bean Validation JAX-WS JAX-RS JAXR JAXB JMS JAAS JASPIC JACC JSR-88 JCA JavaMail JSR-77 RMI JNDI JAX-RPC SAAJ
  7. 7. OSGi with Karaf
  8. 8. OSGi - a very brief introduction • Modular • OSGi Bundles: • High Cohesion (One classloader/bundle) • Low Coupling (Package Import/Export) • Versioning per bundle ( [1.0,2,0) ) • Service Registry 2014-­‐10-­‐23 8
  9. 9. What is Karaf • Container • OSGi Applications • Ligthtweight • expandable to Full Enterprise support • Covers all major needs • Logging • Deployment • Configuration 2014-­‐10-­‐23 9
  10. 10. Karaf - Overview 2014-­‐10-­‐23 10 Config Logging Deployer Console Admin OSGi Framework - Felix / Equinox JMX Blueprint SSH
  11. 11. Enterprise requirements on Karaf
  12. 12. Karaf EJB 3.1 CDI 2014-­‐10-­‐23 12 Servlet 3 JSF 2 JSP JPA 2 JTA Bean Validation JAX-WS JAX-RS JAXR JAXB JMS JAAS JASPIC JACC JSR-88 JCA JavaMail JSR-77 RMI JNDI JAX-RPC SAAJ
  13. 13. Enterprise - Pax Web EJB 3.1 CDI 2014-­‐10-­‐23 13 Servlet 3 JSF 2 JSP JPA 2 JTA Bean Validation JAX-WS JAX-RS JAXR JAXB JMS JAAS JASPIC JACC JSR-88 JCA JavaMail JSR-77 RMI JNDI JAX-RPC SAAJ
  14. 14. Enterprise - Pax CDI EJB 3.1 CDI 2014-­‐10-­‐23 14 Servlet 3 JSF 2 JSP JPA 2 JTA Bean Validation JAX-WS JAX-RS JAXR JAXB JMS JAAS JASPIC JACC JSR-88 JCA JavaMail JSR-77 RMI JNDI JAX-RPC SAAJ
  15. 15. Enterprise - Aries EJB 3.1 CDI 2014-­‐10-­‐23 15 Servlet 3 JSF 2 JSP JPA 2 JTA Bean Validation JAX-WS JAX-RS JAXR JAXB JMS JAAS JASPIC JACC JSR-88 JCA JavaMail JSR-77 RMI JNDI JAX-RPC SAAJ
  16. 16. Enterprise - Tomee aka OpenEJB EJB 3.1 CDI 2014-­‐10-­‐23 16 Servlet 3 JSF 2 JSP JPA 2 JTA Bean Validation JAX-WS JAX-RPC JAX-RS JAXR JAXB JMS JAAS JASPIC JACC JSR-88 JCA JavaMail JSR-77 RMI SAAJ JNDI
  17. 17. Enterprise - CXF EJB 3.1 CDI 2014-­‐10-­‐23 17 Servlet 3 JSF 2 JSP JPA 2 JTA Bean Validation JAX-WS JAX-RPC JAX-RS JAXR JAXB JMS JAAS JASPIC JACC JSR-88 JCA JavaMail JSR-77 RMI SAAJ JNDI
  18. 18. Enterprise - ActiveMQ EJB 3.1 CDI 2014-­‐10-­‐23 18 Servlet 3 JSF 2 JSP JPA 2 JTA Bean Validation JAX-WS JAX-RPC JAX-RS JAXR JAXB JMS JAAS JASPIC JACC JSR-88 JCA JavaMail JSR-77 RMI SAAJ JNDI
  19. 19. Enterprise - Cellar EJB 3.1 CDI 2014-­‐10-­‐23 19 Servlet 3 JSF 2 JSP JPA 2 JTA Bean Validation JAX-WS JAX-RPC JAX-RS JAXR JAXB JMS JAAS JASPIC JACC JSR-88 JCA JavaMail JSR-77 RMI SAAJ JNDI
  20. 20. Enterprise - Karaf with features EJB 3.1 CDI 2014-­‐10-­‐23 20 Servlet 3 JSF 2 JSP JPA 2 JTA Bean Validation JAX-WS JAX-RPC JAX-RS JAXR SAAJ JAXB JMS JAAS JASPIC JACC JSR-88 JCA JavaMail JSR-77 RMI JNDI
  21. 21. Specialties
  22. 22. JPA - Karaf 2014-­‐10-­‐23 22 <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0" > <persistence-unit name="cookbook" transaction-type="JTA"> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> <jta-data-source> osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/cookbook) </jta-data-source> <class>de.nierbeck.apachecon.persistence.entity.Book</class> <class>de.nierbeck.apachecon.persistence.entity.Recipe</class> <exclude-unlisted-classes>true</exclude-unlisted-classes> <properties> <property name="openjpa.Log" value="slf4j" /> <property name="openjpa.RuntimeUnenhancedClasses" value="supported" /> <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/> </properties> </persistence-unit> </persistence>
  23. 23. JPA - Karaf 2014-­‐10-­‐23 22 <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0" > <persistence-unit name="cookbook" transaction-type="JTA"> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> <jta-data-source> osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/cookbook) </jta-data-source> <class>de.nierbeck.apachecon.persistence.entity.Book</class> <class>de.nierbeck.apachecon.persistence.entity.Recipe</class> <exclude-unlisted-classes>true</exclude-unlisted-classes> <properties> <property name="openjpa.Log" value="slf4j" /> <property name="openjpa.RuntimeUnenhancedClasses" value="supported" /> <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/> </properties> </persistence-unit> </persistence> To have this blueprint JNDI is needed
  24. 24. JTA - Karaf 2014-­‐10-­‐23 23 <blueprint default-activation=„eager" xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0" xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0" xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> <bean id="cookBookServiceImpl" class="de.nierbeck.apachecon.persistence.dao.CookBookServiceImpl"> <jpa:context property="em" unitname="cookbook" /> <tx:transaction method="*" value="Required" /> </bean> <service id="cookBookService" ref="cookBookServiceImpl" interface="de.nierbeck.apachecon.persistence.api.CookBookService" /> </blueprint>
  25. 25. JTA - Karaf 2014-­‐10-­‐23 23 <blueprint default-activation=„eager" xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0" xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0" xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> <bean id="cookBookServiceImpl" class="de.nierbeck.apachecon.persistence.dao.CookBookServiceImpl"> <jpa:context property="em" unitname="cookbook" /> <tx:transaction method="*" value="Required" /> </bean> <service id="cookBookService" ref="cookBookServiceImpl" interface="de.nierbeck.apachecon.persistence.api.CookBookService" /> </blueprint> To have this blueprint JPA and JTA is needed
  26. 26. Client - Karaf 2014-­‐10-­‐23 24 <?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" default-activation="lazy"> <reference id="cookBookService" interface="de.nierbeck.apachecon.persistence.api.CookBookService" /> <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0"> <command> <action class="de.nierbeck.apachecon.commands.CreateBook"> <property name="bookService" ref="cookBookService" /> </action> </command> ... </command-bundle> </blueprint>
  27. 27. Demo
  28. 28. Persistence 2014-­‐10-­‐23 26
  29. 29. Client 2014-­‐10-­‐23 27
  30. 30. Client Shell 2014-­‐10-­‐23 28
  31. 31. Client - Shell 2014-­‐10-­‐23 29
  32. 32. Client Shell 2014-­‐10-­‐23 30
  33. 33. Client - Shell 2014-­‐10-­‐23 31
  34. 34. Http Service with …
  35. 35. HTTP Service 2014-­‐10-­‐23 33 • Using an Activator: final HttpContext httpContext = httpService .createDefaultHttpContext(); // register the BookServlet // first wait for the DAO-Service CookBookService cookBookService; ServiceReference<CookBookService> serviceReference = bundleContext .getServiceReference(CookBookService.class); cookBookService = bundleContext.getService(serviceReference); //now create the servlet ViewBookServlet viewBookServlet = new ViewBookServlet(); //set the DAO to the Servlet viewBookServlet.setCookBookService(cookBookService); final Dictionary<String, Object> initParams = new Hashtable<String, Object>(); try { httpService.registerServlet("/book", // alias viewBookServlet, initParams, httpContext);
  36. 36. Whiteboard • Using the whiteboard approach via Activator public void start(BundleContext bc) throws Exception { bundleContext = bc; // first wait for the DAO-Service CookBookService cookBookService; ServiceReference<CookBookService> serviceReference = bundleContext 2014-­‐10-­‐23 34 .getServiceReference(CookBookService.class); cookBookService = bundleContext.getService(serviceReference); // create new Servlet ViewBookServlet cookBookViewServlet = new ViewBookServlet(); cookBookViewServlet.setCookBookService(cookBookService); registerServiced = bundleContext.registerService(Servlet.class, cookBookViewServlet, null); }
  37. 37. Whiteboard 2014-­‐10-­‐23 35 • Using the whiteboard approach via Blueprint <blueprint default-activation="eager"> <reference id="cookBookService" interface="de.nierbeck.apachecon.persistence.api.CookBookService" /> <bean id="viewBookServlet" class="de.nierbeck.apachecon.view.ViewBookServlet" > <property name="cookBookService" ref="cookBookService"/> </bean> <service id="servletService" interface="javax.servlet.Servlet" ref="viewBookServlet" /> </blueprint>
  38. 38. Servlet 3.0 - Just annotation 2014-­‐10-­‐23 36 @WebServlet(urlPatterns = "/book") public class ViewBookServlet extends HttpServlet { /** * */ private static final long serialVersionUID = 1L; @Inject @OsgiService CookBookService cookBookService; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { ... } }
  39. 39. LOST?
  40. 40. Registering - Servlet 2014-­‐10-­‐23 38 Pax-Web HTTP Service Service- Registry Servlet
  41. 41. Registering - Servlet 2014-­‐10-­‐23 38 Pax-Web HTTP Service Service- Registry Servlet Registerd
  42. 42. Registering - Servlet 2014-­‐10-­‐23 38 Pax-Web HTTP Service Service- Registry Servlet Registerd Registerd
  43. 43. Registering - Whiteboard 2014-­‐10-­‐23 39 Pax-Web WebContainer Service-Tracker Service- Registry Servlet
  44. 44. Registering - Whiteboard 2014-­‐10-­‐23 39 Pax-Web WebContainer Service-Tracker Service- Registry Servlet Registerd
  45. 45. Registering - Whiteboard 2014-­‐10-­‐23 39 Pax-Web WebContainer Service-Tracker Service- Registry Servlet Registerd Registerd
  46. 46. Registering - Whiteboard 2014-­‐10-­‐23 39 Pax-Web WebContainer Service-Tracker Service- Registry Servlet Registerd Registerd
  47. 47. Registering - WAR 2014-­‐10-­‐23 40 Pax-Web WebContainer Pax-Web WAR Extender Service- Registry WAB-Bundle Servlet
  48. 48. Registering - WAR 2014-­‐10-­‐23 40 Pax-Web WebContainer Pax-Web WAR Extender Service- Registry WAB-Bundle Servlet Registerd
  49. 49. Registering - WAR 2014-­‐10-­‐23 40 Pax-Web WebContainer Pax-Web WAR Extender Service- Registry WAB-Bundle Servlet Registerd Registerd
  50. 50. Registering - WAR 2014-­‐10-­‐23 40 Pax-Web WebContainer Pax-Web WAR Extender Service- Registry WAB-Bundle Servlet Registerd Registerd
  51. 51. Servlet + JPA / Service 2014-­‐10-­‐23 41 Blueprint Extender Pax-Web WAR Extender JPA-Bundle Service- Registry JPA - Service WEB-Bundle Servlet
  52. 52. Servlet + JPA / Service 2014-­‐10-­‐23 41 Blueprint Extender Pax-Web WAR Extender JPA-Bundle Service- Registry JPA - Service WEB-Bundle Servlet Registerd
  53. 53. Servlet + JPA / Service 2014-­‐10-­‐23 41 Blueprint Extender Pax-Web WAR Extender JPA-Bundle Service- Registry JPA - Service WEB-Bundle Servlet Registerd Injected
  54. 54. Servlet + JPA / Service 2014-­‐10-­‐23 41 Blueprint Extender Pax-Web WAR Extender JPA-Bundle Service- Registry JPA - Service WEB-Bundle Servlet Registerd Registerd Injected
  55. 55. Demo
  56. 56. View 2014-­‐10-­‐23 43
  57. 57. View 2014-­‐10-­‐23 44
  58. 58. Cluster provided by Apache Karaf Cellar
  59. 59. Cellar - Cluster Communication 2014-­‐10-­‐23 46
  60. 60. Cellar - Cluster Communication 2014-­‐10-­‐23 47 Hazelcast
  61. 61. Cellar - Events 2014-­‐10-­‐23 48
  62. 62. Cellar - Distributing Bundles 2014-­‐10-­‐23 49 Node A Node B Node C Maven Repository Hazelcast
  63. 63. Cellar - Distributing Bundles 2014-­‐10-­‐23 49 Node A Node B Node C Maven Repository osgi:install mvn:groupId/artifactId/version Hazelcast
  64. 64. Cellar - Distributing Bundles 2014-­‐10-­‐23 49 Node A Node B Node C Maven Repository Hazelcast
  65. 65. Cellar - Distributing Bundles 2014-­‐10-­‐23 49 Node A Node B Node C Maven Repository Hazelcast
  66. 66. Cellar - Distributing Bundles 2014-­‐10-­‐23 49 Node A Node B Node C Maven Repository Hazelcast
  67. 67. Cellar - Distributing Bundles 2014-­‐10-­‐23 49 Node A Node B Node C Maven Repository Hazelcast
  68. 68. Cellar - Distributing Bundles 2014-­‐10-­‐23 49 Node A Node B Node C Maven Repository Hazelcast
  69. 69. Cellar - Distributing Bundles 2014-­‐10-­‐23 49 Node A Node B Node C Maven Repository Hazelcast
  70. 70. Cellar - Distributing Bundles 2014-­‐10-­‐23 49 Node A Node B Node C Maven Repository Hazelcast DEPRECATED
  71. 71. Cellar - Distributing Bundles 2014-­‐10-­‐23 49 Node A Node B Node C Maven Repository cluster:install mvn:groupId/artifactId/version Hazelcast DEPRECATED
  72. 72. Cellar - RMI 2014-­‐10-­‐23 50 Group 1 Node A Consumes OSGi-Service Group 2 Node B Consumes OSGi-Service Node C Consumes OSGi-Service Node A Provides OSGi-Service Node B Hazelcast Provides OSGi-Service
  73. 73. Cellar - Web session failover 2014-­‐10-­‐23 51 Node A Hazelcast DataBase Client Filter Servlet Node B Filter Servlet
  74. 74. Cellar - Web session failover 2014-­‐10-­‐23 51 Node A Hazelcast DataBase Client Filter Servlet Node B Filter Servlet
  75. 75. Cellar - Web session failover 2014-­‐10-­‐23 51 Node A Hazelcast DataBase Client Filter Servlet Node B Filter Servlet
  76. 76. Cellar - Web session failover 2014-­‐10-­‐23 51 Node A Hazelcast DataBase Client Filter Servlet Node B Filter Servlet
  77. 77. Cellar - Web session failover 2014-­‐10-­‐23 51 Node A Hazelcast DataBase Client Filter Servlet Node B Filter Servlet
  78. 78. Cellar - Web session failover 2014-­‐10-­‐23 51 Node A Hazelcast DataBase Client Filter Servlet Node B Filter Servlet
  79. 79. Cellar - Web session failover 2014-­‐10-­‐23 51 Node A Hazelcast DataBase Client Filter Servlet Node B Filter Servlet
  80. 80. Cellar - Web session failover 2014-­‐10-­‐23 51 Node A Hazelcast DataBase Client Filter Servlet Node B Filter Servlet
  81. 81. Cellar - Web session failover 2014-­‐10-­‐23 51 Node A Hazelcast DataBase Client Filter Servlet Node B Filter Servlet
  82. 82. Cellar - Web session failover 2014-­‐10-­‐23 51 Node A Hazelcast DataBase Client Filter Servlet Node B Filter Servlet
  83. 83. Cellar - Web session failover 2014-­‐10-­‐23 51 Node A Hazelcast DataBase Client Filter Servlet Node B Filter Servlet
  84. 84. Cellar - Web session failover 2014-­‐10-­‐23 51 Node A Hazelcast DataBase Client Filter Servlet Node B Filter Servlet
  85. 85. Cellar - Web session failover 2014-­‐10-­‐23 51 Node A Hazelcast DataBase Client Filter Servlet Node B Filter Servlet
  86. 86. Cluster - Demo
  87. 87. Presentation Layer 2014-­‐10-­‐23 53
  88. 88. web.xml - Hazelcast 2014-­‐10-­‐23 54 • Hazelcast for Session Replication <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <filter> <filter-name>hazelcast-filter</filter-name> <filter-class>com.hazelcast.web.WebFilter</filter-class> <!-- Name of the distributed map storing your web session objects --> <init-param> <param-name>map-name</param-name> <param-value>my-sessions</param-value> </init-param> <init-param> <param-name>sticky-session</param-name> <param-value>false</param-value> </init-param> </filter> <filter-mapping> <filter-name>hazelcast-filter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> <dispatcher>REQUEST</dispatcher> </filter-mapping> <listener> <listener-class>com.hazelcast.web.SessionListener</listener-class> </listener> </web-app>
  89. 89. View 2014-­‐10-­‐23 55
  90. 90. View 2014-­‐10-­‐23 56
  91. 91. View 2014-­‐10-­‐23 57
  92. 92. SUMMARY
  93. 93. Enterprise - Karaf 2014-­‐10-­‐23 59 Servlet 3 EJB 3.1 CDI JSF 2 JSP JPA 2 JTA JAX-WS JAX-RPC JAX-RS JAXR SAAJ JAXB JMS JNDI JAAS RMI
  94. 94. JEE with Karaf? • Adoptions needed? YES • Minor on Persistence - JNDI lookup • Minor on transaction - Blueprint JTA • Wiring of Services: • Use Blueprint • Use Servlet 3.0 with CDI - @OsgiService • Session Replication throughout cluster, it’s still standard Hazelcast 2014-­‐10-­‐23 60
  95. 95. Resources • @anierbeck • notitzblog.nierbeck.de • https://github.com/ANierbeck/karaf-enterprise-sample • www.codecentric.de • karaf.apache.org • https://ops4j1.jira.com/wiki/display/paxweb/Pax+Web • #karaf at irc.codehaus.org • https://www.packtpub.com/application-development/apache-karaf-cookbook • Pictures, mainly from flickr 2014-­‐10-­‐23 61
  96. 96. THANKS FOR LISTENING
  97. 97. Thanks to the Apache Community
  98. 98. Questions
  99. 99. Thanks

×