This book covers the OSGi world with Spring Dynamic Modules, in an easy approach with excellent material and wclever images. There are some key chapters and realistic topics are covered in this book. The theory isn't too complicated and there are a good amount of table discussions
This chapter starts off with asection called OSGi Concepts and Architecture where JVM, Java Classes and CLASSPATH are covered. After this comes, Class Loaders: Custom Class Loading in a JVM which includes an image describing Bootstrap class loader and System class loader.
After this The OSGi Bundle section is covered, with theory about OSGi itself, bundles and Manifest.mf. The manifest file is then explained, line by line.Then Class Loaders Revisted: The OSGi Way is covered, with a description of the Bootstrap class loader and System class loader. Next we use bundles instead of the classload, offering a comparison now with OSGi. Different types of services for bundles are covered too for:
The OSGi Framework goes into more detail, with information about OSGI framework layers After this really an excellent expansion for the most important layers with images like OSGi bundle life cycle and an explanation of each state. There are two pages for a table called OSGi Service Interfaces for the Service Layer
Now is the turn 5for the section OSGi Hello World Application, before you get introduced to the code, we start with an image about OSGi Hello World Application bundles and relationships which gives a good overview of the the bundles and its relationships are shown but being specific about Type Dependency and Service Dependency. A table with Prerequesites and Downloads is available, as well as configuration for Java, Apache Ant and Apache Felix.
The Java code shows an interface with its implementation and an Activator class (the author keep the things simple). The author teaches a build.xml configuration, and two OSGi Manifests are shown. Then this is all executed with Felix, where the author teaches us how install and start the bundles.
Not enough?, the author offer us other section about OSGi Bundle for the Web where now we work with our own Servlet but using a ServiceTracker how type variable, a new Activator class is available too working with ServiceTracker, well explanation for this class, again a new OSGi Bundle Manifest is available and again we start Felix
The follow section is Updating OSGi Bundles which is covered by the moment with concrete theoryChapter 2: Introducing Spring
The chapter starts with Spring Concepts and Architecture where some Java classes with InitialContext and DataSource and then the section Inversion of Control and Dependency Injection with an appreciation for Plain Old Java Objects where the following topics are discussed:
Afterwards the Spring Portfolio is introduced with a table about two pages long with an overview of many of the Spring projects
The Spring Hello Application, starts with an important image about the Spring Hello World application layers and components. Two databases are used here - MySQL and HSQL. The software required is listed with installation instructions for Spring Framework, Apache Tomcat, Mysql. An image about the Directory structure for the application is included to give you a global idea about the application distribution
The Java code starts off with The Domain Model, where two POJO classes are available. An interface with a good amount of method services is included too. Persisting the Domain Model with JPA has our two previous POJO are edited to use JPA Annotations support. Then a DAO class is introduced implementing the previous interface. We work with getJpaTemplate() support. persistence.xml and helloworld-service.xml are included then, where our most importants beans are declared. A table about Spring Open JPA Vendor Adapter Bean Properties, with many properties are explained briefly. To end this sub section instructions for Compiling the Domain model is included, where the jars required are listed and explained. along with which ant task should be used. Something very important in this helloworld-service.xml is that for LocalContainerEntityManagerFactoryBean is that it uses the property loadTimerWeaver working with SimpleLoadTimerWeaver class.
Testing Your Domain Model shows a concrete Test class based on Unit Testing and another Test class for Integration Testing.Another helloworld-service.xml (second with the same name) is included but for testing purposes based in HSQL, instructions about Running Tests are well cover, including which jars are needed are listed them and explained with ant task configuration.
Using Spring's MVC, starts with a Controller, good code, and thenCreating Views with Tiles using tiles.xml is introduced with many JSP files to fit in the attributes part of our tiles configuration. Some JSP files have included support for Ajax Calls . Spring MVC Descriptors is included too with a long web.xml configuration, where resource-ref tag is included . Now we see a complete version of helloworld-service.xml configured with MySQL. helloworld-servlet.xml is covered with important beans declared like SimpleUrlHandlerMapping, TilesConfigurer and AjaxUrlBasedViewResolver. Creating the Web Archive is included too, starting with context.xml file used for Configuring a JNDI Data Source for our Tomcat.
To end the chapter, in Deploying on the Web an SQL file is introduced with configuration for Tomcat too.A message table about What is Weawing? and Why Is It Important? ends this long powerful chapter.Chapter 3: Integrating Spring and OSGi
OSGi's Synergy with Spring lists
Following this we have a section named Layers of Integration covering:
Now we follow with the section called OSGi and Spring Hello World Application, the objective is clear, develop a OSGi'fied Spring Application. The section starts with an important image about Spring-DM Hello World application bundles and relationships, where you can see how the bundles are related (like spring.osgi, slf4j and among others) showing which are related with the WAR. The OSGi Registry is included too, with an image including the special differentiation about the Type Dependency and Service Dependency.
After this the author covers installing Spring Dynamic Modules for OSGi and Installing Eclipse Equinox. Something very valuable here is that it explains in a table Why Change From Apache Felix to Eclipse Equinox, followed with Installing Apache Tomcat (OSGi'fied) where the content of Eclipse Equinox config.ini is available. Another table message is available, about When Logging In OSGi, Why SLF4J,
Again, you get Java code for all of this - a POJO class is shown, followed by its manifest.mf, and then an interface and its DAO implementation class is available too. Both are based around four methods (find,update,save,delete). For each one its manifest.mf content is shown where you can see for both the imported and exported packages sentences. For our DAO bundle we have the osgi-context.xml, so you can see how our bean is declared and exported like a service to OSGi (working with osgi:service)
The last section in this chapter is Deploying Spring-Osgi Bundles, where we have simply an Equinox config.ini configuration followed with instructions on how install and start our bundles in order.Chapter 4: Spring Dynamic Modules for OSGi
Extenders and Fragments in Spring-DM - these two concepts are the central pieces for Spring-DM Server, and this section starts covering the Extender with two tables. The first about Spring-DM defaults triggers for creating Spring context and the second for Spring-Context OSGi Header Values. The author re lists the most important parts with deeper explanation, for example for:
Then theory for Fragments is covered, before moving onto Registering OSGi Services Through Spring-DM.
Locating OSGi Services Through Spring-DM, practically the same approach used in the previous paragraph, but working with other attributes like bean-name, filter, comparator-ref, greedy-proxy, listener, furthremore teaching us about osgi:default-timeout and osgi:default-cardinality.
We follow with OSGi Bundle Activities with Spring-DM, with code snippets for the bundle tag.Then we move onto the OSGi Fragments with Spring-DM section, and a big table about spring-osgi-extender.jar Bean Values Exposed for Fragments where you can read for each bean value a brief and concrete explanation using the headers Bean name, Type, Function and Default Value, this is well covered, same appreciation for a table called spring-osgi-web-extender.jar Bean Values Exposed for Fragments.Chapter 5: SpringSource dm Server
The chapter starts quickly with a concrete explanation about the benefits of the SpringSource dm server and how it avoids a certain set of now standard Java EE application features. SpringSource dm Server addresses issues like
In the following sections Spring, OSGi, and Java Integration weaving and its problems (cross-bundle weaving) are covered. Other problems including out-of-box OSGi, Resource Protocol and Thread Context are also well explained.
Concepts and Architecture are covered too, with a table indicating the SpringSource Application Plataform Parts e.g.:
After of this, an interesting image about SpringSource Application Plataform Architecture is presented and a subsection called Deployment Units is included which provides some detailed information about:
Another subsection is Libraries where the author provides many code snippets in relation to OSGi Manifest using Import-package, Import-Library and SS Application Platform Library Definition. An interesting table discussion about SS dm Server Import-Bundle VS OSGI's Require-Bundle is also included. In addition, two pages two pages covering the directory structure of SS dm Server
Now is the turn to see our Hello World Application, starting with an important and interesting image about SS dm Server Hello World application bundles where you can see OSGi Registry, bundles, Web Modules and PAR working together and related among them with Type Dependency and Service Dependency, then one page is dedicated to Prerequisites and Downloads following quickly about the installation instructions for SS dm Server and with configuration for the Directory structure for the application, one page about an image of all these directories
Now comes the Java code, starting with four pages for our entities working with annotations, an interesting table discussion about JPA Providers and OSGi is available too, following with our service interface and its DAO implementation, a good amount of methods declared and implemented exists, five pages for this, then now is the turn for the Controller working with annotations (two pages for this), again another table discussion about Injecting OSGi Services Using Annotations is available too, following with two pages for our JSP code, now an important part well covered is the section Application Bundles, Manifest, and Descriptors for all these bundles:
Therefore their respectives files are well covering in seventeen pages, ending the chapter with two pages for our build.xml ant configuration.Chapter 6: Versioning with OSGi and Spring
The chapter starts quickly about theBenefits and Concepts of OSGi, including a table about OSGi Headers Supporting Versioning
OSGi Package Versioning Behaviors follows, where a new service interface is added but based in a modification of a previous service. So we now have two services, where for this new service we just add two new methods and changing too its manifest.mf file, where the Export-Package now uses the version attribute followed with a code snippet about how use Import-package including the version attribute. There is an interesting and long table discussion about Import-Package and Dynamicimport-Packagefollowed by another discussion about whether to use Package Versions or Service Versions.
The section OSGi Service Versioning Behaviors is covered too where the author teaches us how edit a manifest.mf file, changing the Bundle-Version header and keeping the Bundle-SymbolicName without changes. This editing is necessary to avoid errors around the Type-Dependency Checks since we have two bundles publishing the same service. The author offer too many versions of osgi-context.xml configurations working with ranking Attribute, Service Properties (osgi:service-properties tag) and filter Attribute.
Next we have a section on OSGi Bundle Versioning Behaviors where the author offer us a manifest.mf code working now with Require-Bundle, explaining too the visibility Attribute, this section includes an important and really long table discussion covered practically in two pages about Require-Bundle and Import-package Misconceptions, really an excellent explanation, following with an interesting image about Split packages using a facade with Require-Bundle with a snippet code using visibility:=reexport
To end the chapter OSGi Fragment Versioning Behaviors is covered, with some theory, before we move onto OSGi Spring-DM and SpringSource dm Server Versioning Behaviours where:
are shown with lots of code snippets.Chapter 7: Data Access and Bundle Management Without SpringSource dm Server
The chapter starts with an introduction of JPA with Spring,and the use of the ivy dependency management tool and BND. BND is used to inspect and modify JAR files in OSGi Bundle, all these tools are needed if you don't use SS Enterprise Bundle Repository
We follow with the section Access to RDBMS many data access strategies in Java are mentioned, such as JDBC,JDO, Entity EJB and ORM. We then have Java code for a DAO class that implements an interface and works with SimpleJdbcTemplate. The code is not complicated and is easy to understand. Then we have the Spring osgi-context.xml configuration content for our Service DAO-JDBC bundle where we use osgi:reference to import javax.sql.DataSource and inject in our DAO service and export this same DAO service using osgi:service, manifest.mf configuration. To end this section an interesting table discussion about What About JPA in an OSGI Bundle? is available.
The next section is Introducing the BND Tool,gives a sample of an execution command to inspect a postgresql driver jar, with practically seven pages showing the output results, then other commands related to the creation of an OSGi Bundle for such jar is available. The author shows the manifest.mf created with its respective explanation and other files are shown for this example,.
To end this section another table discussion about Not Everything can be an OSGi Bundle, or can it? is available too, which is a very interesting discussion.
Now here comes an interesting section about Hello World Application Revisted Without the SpringSource dm server: Data Access and Apache Ivy starting practically with an image in one page about HW application bundles without SS dm Server, where you going to see a good amount of bundles related. Among them are Type Dependency and Service Dependency, OSGi Register, WAR and RDBMS.Prerequisites and Downloads gives instructions on how to install ivy and its respective configuration. There's another table discussion about Why not use apache maven? why apache ivy?.This is well covered with another image about the directory structure for the application with its respective explanation, continuing with three pages about build.xml configuration and then almost two pages for ivysettings.xml configuration content. The ivy.xml configuration is covered in almost one page and another table discussion about who determines what a bundle (jar) depends on? is covered. Finally, we follow with a interesting image covering Apache Ivy retrieval and copying process which gives an excellent appreciation for such process
The chapter ends showing the complete content for the ivi.xml file, practically in three pagesChapter 8: Web Applications Using Spring and OSGi
The chapter starts with Web Bundle Concepts covering WAR, javax.servlet and javax.servlet.resources packages. Then there's some code snippets for Import Java Servlet packages and Bundle-Classpath. The OSGiBundleXMLWebApplicationContext class si covered and used in an example. This same class is used again in another code example about OSGi Aware Servlet Using OSGiBundleXMLWebApplicationContext again in a Web.xml where the class appears in init-param tag.
We follow yet by another code example about Servlet Configuration File Accessing OSGi Resources via Spring-DM, working with the spring-osgi.xsd and therefore with osgi:reference the follow sections is about Using Different Web Containers covers Tomcat and Jetty, and an interesting table discussion about What about Oracle/Bea's, Sun's, and IBM's Web Containers? How are those used with Spring-DM?.
The author expands on Using the Jetty Web Container, covering:
for each point he mentions all bundles that are needed, following with a page about Eclipse Equinox config-ini using Jetty Web Server.
The next section is Using SSL/TLS with OSGi covering Setting Up SSL in Apache Tomcat, showing a configuration about Apache Tomcat server.xml using SSL, following with Creating a JKS Keystore based in the execution of a command and its respective output, including a table discussion about Generating a JKS Keystore with a real certificate based in a simple execution command. To end the topic related with Tomcat creation of an SSL Configuration Fragment and its respective installation is covered too - it's based on a manifest.mf configuration and Eclipse Equinox config.ini
To end the chapter, a table discussion about For the OSGi Purist: Flash Open Source Flash Server-ROJO, is includedChapter 9: Testing With Spring and OSGi
The chapter starts quickly with a sectiona about Testing with OSGi and Spring-DM which mentions about an important list about the purpose of integration testing in OSGi for example:
We follow with the section Unit and Integration Revisited: Testing OSGi Applications Without OSGi where the author mentions there are non-OSGi tests that can be performed on OSGi applications. Afterwards, to explain this, we see a Java class code about (Non-OSGi) RDBMS Integration Test for a DAO Class Based on JDBC, that extends AbstractTransactionalDataSourceSpringContextTests. We follow with the beans configurations about (Non-OSGi) helloworld-service.xml Context for Setting Up a Test RDBMS Based on JDBC where our DAO class is declared together with DriverManagerDataSource and DataSourceTransactionManager with its respective explanation for this configuration, a sql script is available too.
We follow with the section Spring-DM's Testing Framework which practically lists six steps about the Spring-DM’s in testing process and another listing about three steps for the general process for creating tests in Spring-DM.
The following section is Creating a Spring-DM Test Class which has a big table (almost one page) about Spring-DM Test Classes and Inheritance Hierarchy with the headers Test Class, Function, Subclasses,and after this Java code for Test Class Designed to Return the OSGi Environment Vendor and Version is available. An important part for this section is a listing for the Minimum Set of Bundles Needed to Be Present in ArtifactLocator (Apache Maven or Apache Ivy) to Perform the Spring-DM Test.
Many Apache Ivy configurations for download dependencies purposes for Spring-DM Test like ivy.xml and ivysettings.xml. Then build.xml configurations is shown for Executing a Spring-DM Test purposes, with six pages, including its respective explanation, followed by the output results for such testing execution.
The author offer us other sample testing, and an interesting part about about guaranteeing a bundle publishes an OSGi service correctly, where a Test class extending AbstractConfigurableBundleCreatorTests is shown in almost two pages, not complicated the code, ending the chapter with two pages about its explanation
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)