From “Hello World” to Real World : Building web apps with Spring OSGi Craig Walls The Spring Experience 2007 December 12, 2007.

Slides:



Advertisements
Similar presentations
OpusCollege and Spring-DM. OSGi based web applications – three strategies OSGi container embedded in another container: OSGi Bridge Server (OBS)  e.g.
Advertisements

Introduce OSGi BlueDavy
CPSC 875 John D. McGregor Architecture evolution.
Component Models and Technologies Case Study: OSGI.
OSGi Remote Services with SCA using Apache Tuscany Raymond Feng
OSGi as a Framework for Building a Product Line: Experience and Best Practices Ruwan Linton & Afkham Azeez
Why OSGi matters for Enterprise Java Infrastructures
OSGi: Open Services Gateway Initiative Richard Chapman 5 Sept
Pragmatic Application Building: Step by Step Jay Sissom Principal Systems Analyst Indiana University
Spring Dynamic Modules. Startlocation: Documentation: /1.2.1/reference/html/
The Spring Framework: A brief introduction to Inversion of Control James Brundege
Struts 2.0 an Overview ( )
UNIT-V The MVC architecture and Struts Framework.
Agenda Introduction to the Guidewire platform
An Introduction to OSGi: Creating Highly Modular Java Systems Simon Archer, IBM 15 November 2010.
Introduction to the Spring Framework By: Nigusse A. Duguma Kansas State university Department of Computer Science Nov 20, 2007.
OSGi.
Spring Overview, Application demo -Midhila Paineni 09/23/2011 Spring Overview, Application demo9/8/20151.
1/151/15 ENT Metamodel Implementation & Applications ENT metamodel, prototype implementation Component substitutability checking, ENT based component comparison.
Introduction to the Atlas Platform Mobile & Pervasive Computing Laboratory Department of Computer and Information Sciences and Engineering University of.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics NPRG044: OSGi framework Michal Malohlava & Pavel Parízek
Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
AN OVERVIEW OF SERVLET TECHNOLOGY SERVER SETUP AND CONFIGURATION WEB APPLICATION STRUCTURE BASIC SERVLET EXAMPLE Java Servlets - Compiled By Nitin Pai.
Service-Oriented Component Model April 18,2007.
JBoss at Work JAW Motors Application Chapter 1-3 Jeff Schmitt October 9, 2006.
OSGi & UPnP Technology 2009 Summer Ya-Lin Huang. 2 Outline What is OSGi Technology Introduction Alliance Specifications Key Benefits OSGi Framework Service.
Review: OSGi – a component framework for Java Bundle OSGi Framework Bundle Java Runtime Environment (JRE) Operating System (OS) Hardware “Dynamic Modules.
Opus College - overview. OpusCollege - background First project: ICT Capacity Building Mozambican Higher Education Institutions Partners: RUG Groningen,
Comparing JavaBeans and OSGi Towards an Integration of Two Complementary Component Models HUMBERTO CERVANTES JEAN-MARIE FAVRE 09/02.
OSGi Enablement for Tuscany Raymond Feng. Overview.
CPSC 875 John D. McGregor What do you do first?/ Architecture evolution.
Tu sca ny 1 Extending The Tuscany Java SCA Runtime 21 August 2006.
OSGi in action BlueDavy
In Pieces Breaking down monolithic applications with Spring-DM and OSGi.
Migrating Desktop The graphical framework for running grid applications Bartek Palak Poznan Supercomputing and Networking Center The.
OSGi Service Platform Open Service Gateway initiative.
Webservice versioning using osgi Allard Buijze, Jettro Coenradie.
Introduction to Web Dimitar Nenchev Ivan Nakov
Open Service Gateway Initiative (OSGi) Reporter : 林學灝 侯承育 1.
Sameera Jayasoma 18 th July, 2009 Senior Software Engineer Introduction to OSGi The Dynamic Module System for Java.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Spring Remoting Simplifying.
CPSC 875 John D. McGregor Architecture evolution.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Spring MVC Views Rendering custom views.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Spring MVC Essentials Getting started.
Spring and DWR Frameworks for Rich Web Enterprise Application Thomas Wiradikusuma Presentation to the 20 th.
Getting Started with the Open Services Gateway Initiative (OSGi) CNT 5517 Dr. Sumi Helal, Ph.D. Professor Computer & Information Science & Engineering.
1 Spring Framework April, 2012 Lam Ho Lam To. © 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 2 1.Spring Overview 2.Framework.
Plug-in Architectures Presented by Truc Nguyen. What’s a plug-in? “a type of program that tightly integrates with a larger application to add a special.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Data Access with Spring.
Modern Programming Language. Web Container & Web Applications Web applications are server side applications The most essential requirement.
Impala A dynamic module framework for Java web development Phil Zoio Realsolve Solutions Devoxx 12 December, 2008.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Introduction to OSGi +ActorFrame Surya Bahadur Kathayat
CPSC 875 John D. McGregor C22 - Architecture evolution.
Possible Solution of Interworking between oneM2M and OSGi
Leveraging ColdSpring to build a robust Flex applications Chris Scott, Cynergy Systems.
GlassFish OSGi - A Modular Runtime for Hybrid Applications
J2EE Lecture 6: Spring – IoC and Dependency Injection
Web Programming Developing Web Applications including Servlets, and Web Services using NetBeans 6.5 with GlassFish.V3.
OSGi: The Lifecycle Layer. The Extender Pattern
Web Services-JAX-RPC JAX-RPC enables a Web Service endpoint to be developed using either a Java Servlet or Enterprise JavaBeans (EJB) component model.
Overall Architecture and Component Model
Sakai WebApp Structure
ESIS Consulting LLC (C) ESIS Consulting LLC. All rights reserved
Objectives In this lesson you will learn about: Need for servlets
CS3220 Web and Internet Programming Introduction to Java Servlets
Aspect Oriented Programming
WebSphere & EJB’s Experiences, Deployment & Best Practices
Plug-In Architecture Pattern
Presentation transcript:

From “Hello World” to Real World : Building web apps with Spring OSGi Craig Walls The Spring Experience 2007 December 12, 2007

Who are you? By show of hands... By show of hands... – Java 6? Java 5? 1.4? 1.3? 1.2 or earlier? – Spring 2.5? Spring 2.0? 1.2 or earlier? – Other languages? C#? Groovy? Ruby? Erlang? Scala? Favorite sessions this week? Favorite sessions this week? What do you hope to get from this session? What do you hope to get from this session?

Who am I? Software developer for over 13 years Software developer for over 13 years Worked in telecom, finance, retail, education, and software Worked in telecom, finance, retail, education, and software Developed in Java, C#, Groovy, Ruby, C, C++, C#,...(and more) Developed in Java, C#, Groovy, Ruby, C, C++, C#,...(and more) Spring fanatic Spring fanatic Author of Spring in Action and XDoclet in Action Author of Spring in Action and XDoclet in Action

Agenda A brief intro to OSGi A brief intro to OSGi Springifying OSGi Springifying OSGi The end of the WAR The end of the WAR

Have you ever used OSGi? Good chance that you have! Good chance that you have! – Eclipse – WebSphere 6.1 – BMW

The Spring piece of the puzzle Loose coupling through dependency injection and AOP Loose coupling through dependency injection and AOP Promotes POJO-based development Promotes POJO-based development Rich framework of services and abstractions Rich framework of services and abstractions

What about OSGi? Coarse-grained component model Coarse-grained component model Bundle-level deployment Bundle-level deployment May expose services May expose services Not entirely POJO-friendly Not entirely POJO-friendly

Spring and OSGi together Even more loosely-coupled components Even more loosely-coupled components Dynamic Dependency Injection Dynamic Dependency Injection

Getting started: Where to get it Spring Dynamic Modules for OSGi (aka, Spring-OSGi or Spring-DM) Spring Dynamic Modules for OSGi (aka, Spring-OSGi or Spring-DM) – Containers Containers – Equinox, Knopflerfish, Felix, Concierge Meta-container Meta-container – PaxRunner

Spring-DM: Key elements OSGi extender bundle OSGi extender bundle – Automatically creates Spring context for Spring-enabled bundles Transparent publishing of POJOs as services Transparent publishing of POJOs as services Transparent consumption of services in Spring context Transparent consumption of services in Spring context

Getting started: Simple example The obligatory “Hello World” bundle The obligatory “Hello World” bundle Without Spring Without Spring With Spring With Spring As service/consumer bundles As service/consumer bundles

Simple Hello World: No Spring Bundle activator Bundle activator – Effectively the “main” class package com.habuma.hello; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; public class HelloWorld implements BundleActivator { public void start(BundleContext ctx) throws Exception { System.out.println("Hello World!"); } public void stop(BundleContext ctx) throws Exception { System.out.println("Goodbye World!"); } package com.habuma.hello; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; public class HelloWorld implements BundleActivator { public void start(BundleContext ctx) throws Exception { System.out.println("Hello World!"); } public void stop(BundleContext ctx) throws Exception { System.out.println("Goodbye World!"); }

Simple Hello World: Manifest In META-INF/MANIFEST.MF In META-INF/MANIFEST.MF Manifest-Version: 1.0 Bundle-Name: HelloWorld Bundle-Activator: com.habuma.hello.HelloWorld Bundle-SymbolicName: HelloWorld Bundle-Version: Import-Package: org.osgi.framework Manifest-Version: 1.0 Bundle-Name: HelloWorld Bundle-Activator: com.habuma.hello.HelloWorld Bundle-SymbolicName: HelloWorld Bundle-Version: Import-Package: org.osgi.framework

Hello World with Spring-DM Main class can be a POJO: Main class can be a POJO: package com.habuma.hello; public class HelloWorld { public void start() throws Exception { System.out.println("Hello World!"); } public void stop() throws Exception { System.out.println("Goodbye World!"); } package com.habuma.hello; public class HelloWorld { public void start() throws Exception { System.out.println("Hello World!"); } public void stop() throws Exception { System.out.println("Goodbye World!"); }

Hello World with Spring-DM (2) Declared in Spring Declared in Spring – Configured in META-INF/spring/helloworld.xml – Triggered by init-method/destroy-method <beans xmlns=" xmlns:xsi=" xsi:schemaLocation=" <bean id="helloWorld" class="com.habuma.hello.HelloWorld" init-method="start" destroy-method="stop" /> <beans xmlns=" xmlns:xsi=" xsi:schemaLocation=" <bean id="helloWorld" class="com.habuma.hello.HelloWorld" init-method="start" destroy-method="stop" />

Hello World with Spring-DM (3) Nothing special in the manifest... Nothing special in the manifest... But, MANIFEST.MF could specify Spring config location: But, MANIFEST.MF could specify Spring config location: Manifest-Version: 1.0 Bundle-Name: HelloSpringWorld Bundle-SymbolicName: HelloSpringWorld Bundle-Version: Import-Package: org.osgi.framework Manifest-Version: 1.0 Bundle-Name: HelloSpringWorld Bundle-SymbolicName: HelloSpringWorld Bundle-Version: Import-Package: org.osgi.framework Spring-Context: config/HelloWorld.xml

Hello World Service Still implemented as a POJO: Still implemented as a POJO: package com.habuma.hello.service; public class HelloServiceImpl implements HelloService { public String sayHello() { return "Hello World! I'm a service!"; } public String sayGoodbye() { return "I gotta go. See ya later!"; } package com.habuma.hello.service; public class HelloServiceImpl implements HelloService { public String sayHello() { return "Hello World! I'm a service!"; } public String sayGoodbye() { return "I gotta go. See ya later!"; }

Hello World Service (2) Wired in Spring Wired in Spring – As a bean – Exposed as service using – Exposed as service using <beans xmlns=" xmlns:xsi=" xmlns:osgi=" xsi:schemaLocation=" <bean id="helloService" class="com.habuma.hello.service.HelloServiceImpl" /> <osgi:service ref="helloService" interface="com.habuma.hello.service.HelloService" /> <beans xmlns=" xmlns:xsi=" xmlns:osgi=" xsi:schemaLocation=" <bean id="helloService" class="com.habuma.hello.service.HelloServiceImpl" /> <osgi:service ref="helloService" interface="com.habuma.hello.service.HelloService" />

Hello World Service (3) Still nothing special in the manifest... Still nothing special in the manifest... – Except that it exports the service's package Manifest-Version: 1.0 Bundle-Name: HelloSpringService Bundle-SymbolicName: HelloSpringService Bundle-Version: Export-Package: com.habuma.hello.service Import-Package: org.osgi.framework Manifest-Version: 1.0 Bundle-Name: HelloSpringService Bundle-SymbolicName: HelloSpringService Bundle-Version: Export-Package: com.habuma.hello.service Import-Package: org.osgi.framework

Hello World Consumer Implemented as a POJO Implemented as a POJO package com.habuma.hello; import com.habuma.hello.service.HelloService; public class HelloWorld { public void start() throws Exception { System.out.println(helloService.sayHello()); } public void stop() throws Exception { System.out.println(helloService.sayGoodbye()); } // injected private HelloService helloService; public void setHelloService(HelloService helloService) { this.helloService = helloService; } package com.habuma.hello; import com.habuma.hello.service.HelloService; public class HelloWorld { public void start() throws Exception { System.out.println(helloService.sayHello()); } public void stop() throws Exception { System.out.println(helloService.sayGoodbye()); } // injected private HelloService helloService; public void setHelloService(HelloService helloService) { this.helloService = helloService; }

Hello World Consumer (2) Wired in Spring Wired in Spring <beans xmlns=" xmlns:xsi=" xmlns:osgi=" xsi:schemaLocation=" <bean id="helloWorld" class="com.habuma.hello.HelloWorld" init-method="start" destroy-method="stop">... <beans xmlns=" xmlns:xsi=" xmlns:osgi=" xsi:schemaLocation=" <bean id="helloWorld" class="com.habuma.hello.HelloWorld" init-method="start" destroy-method="stop">...

Hello World Consumer (3) Hello service is wired in through Hello service is wired in through – Notice that only an interface is specified <osgi:reference id="helloService" interface="com.habuma.hello.service.HelloService" /> <osgi:reference id="helloService" interface="com.habuma.hello.service.HelloService" />

Hello World Consumer (4) Still not much special in the manifest Still not much special in the manifest – Except import of the service package Manifest-Version: 1.0 Bundle-Name: HelloSpringConsumer Bundle-SymbolicName: HelloSpringConsumer Bundle-Version: Import-Package: org.osgi.framework,com.habuma.hello.service Manifest-Version: 1.0 Bundle-Name: HelloSpringConsumer Bundle-SymbolicName: HelloSpringConsumer Bundle-Version: Import-Package: org.osgi.framework,com.habuma.hello.service

What Spring-DM needs Spring-DM itself Spring-DM itself – Extender bundle – Core bundle – I/O support bundle Spring Framework Spring Framework – spring-core.jar – spring-beans.jar – spring-aop.jar Supporting libraries Supporting libraries – AOP Alliance – cglib-nodep (for proxying classes) – commons-logging (SLF4J recommended) – Log4J (or some logging implementation) – backport-util (when running on JDK 1.4)

Embedded Jetty HTTP service Equinox Jetty bundle Equinox Jetty bundle Equinox HTTP service servlet bundle Equinox HTTP service servlet bundle javax.servlet bundle javax.servlet bundle Jetty Jetty Commons Logging Commons Logging Eclipse OSGi services Eclipse OSGi services

PaxRunner Starts OSGi container of your choice Starts OSGi container of your choice – Felix by default – Also supports Knopflerfish, Concierge, and Equinox Can automatically load bundles Can automatically load bundles – From file or HTTP URLs – Or from Maven repository

A typical Java web app

A typical OSGi application

OSGi app with Spring-DM

Domain bundle Basic domain POJOs Basic domain POJOs No services, no imports, no Spring-DM required No services, no imports, no Spring-DM required Manifest exports domain package Manifest exports domain package Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: SpitterDomain Bundle-SymbolicName: com.habuma.SpitterDomain Bundle-Version: Export-Package: com.habuma.spitter.domain Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: SpitterDomain Bundle-SymbolicName: com.habuma.SpitterDomain Bundle-Version: Export-Package: com.habuma.spitter.domain

Persistence layer bundle Manifest exports DAO package Manifest exports DAO package – So that consumers can see interfaces Imports Domain package Imports Domain package Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: SpitterMemoryPersistence Bundle-SymbolicName: com.habuma.SpitterMemoryPersistence Bundle-Version: Import-Package: com.habuma.spitter.domain Export-Package: com.habuma.spitter.persistence Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: SpitterMemoryPersistence Bundle-SymbolicName: com.habuma.SpitterMemoryPersistence Bundle-Version: Import-Package: com.habuma.spitter.domain Export-Package: com.habuma.spitter.persistence

Persistence layer bundle (2) Spring-DM exports DAO beans as OSGi services Spring-DM exports DAO beans as OSGi services <beans xmlns:osgi=" xmlns=" xmlns:xsi=" xsi:schemaLocation=" <bean id="spittleDao" class="com.habuma.spitter.persistence.InMemorySpittleDao" /> <osgi:service id="spittleDaoService" ref="spittleDao" interface="com.habuma.spitter.persistence.SpittleDao" /> <beans xmlns:osgi=" xmlns=" xmlns:xsi=" xsi:schemaLocation=" <bean id="spittleDao" class="com.habuma.spitter.persistence.InMemorySpittleDao" /> <osgi:service id="spittleDaoService" ref="spittleDao" interface="com.habuma.spitter.persistence.SpittleDao" />

Service layer bundle Manifest imports DAO and Domain packages Manifest imports DAO and Domain packages Exports Service package Exports Service package Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: SpitterService Bundle-SymbolicName: com.habuma.SpitterService Bundle-Version: Import-Package: com.habuma.spitter.domain, com.habuma.spitter.persistence Export-Package: com.habuma.spitter.service Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: SpitterService Bundle-SymbolicName: com.habuma.SpitterService Bundle-Version: Import-Package: com.habuma.spitter.domain, com.habuma.spitter.persistence Export-Package: com.habuma.spitter.service

Service layer bundle (2) References DAO service References DAO service Exports service POJO as OSGi service Exports service POJO as OSGi service <beans xmlns:osgi=" xmlns=" xmlns:xsi=" xsi:schemaLocation=" <osgi:reference id="spittleDao" interface="com.habuma.spitter.persistence.SpittleDao" /> <osgi:service id="spitterServiceService" ref="spitterService" interface="com.habuma.spitter.service.SpitterService" /> <beans xmlns:osgi=" xmlns=" xmlns:xsi=" xsi:schemaLocation=" <osgi:reference id="spittleDao" interface="com.habuma.spitter.persistence.SpittleDao" /> <osgi:service id="spitterServiceService" ref="spitterService" interface="com.habuma.spitter.service.SpitterService" />

Presentation layer options Deploy presentation layer as another OSGi bundle Deploy presentation layer as another OSGi bundle – No application server required – Servlet/JSP support embedded in OSGi as a service Deploy presentation layer as a WAR file in a web container Deploy presentation layer as a WAR file in a web container – OSGi container embedded in web application – All other layer bundles deployed in embedded OSGi container

Presentation layer bundle Now here's the tricky part... Now here's the tricky part... – No WAR file – No WEB-INF/web.xml How do you register the servlet(s)? How do you register the servlet(s)? – With a ServiceTracker

Service tracker Register servlets programmatically Register servlets programmatically TODO: INSERT SERVICE TRACKER CODE HERE