Free Sample
+ Collection

OSGi and Apache Felix 3.0 Beginner's Guide

Beginner's Guide
Walid Joseph Gédéon

Get a firm grasp on OSGi concepts with this superbly written guide to building your own applications using the Felix framework. Totally practical and with lots of handholding, it’s the perfect primer for absolute beginners.
RRP $26.99
RRP $44.99
Print + eBook

Want this title & more?

$16.99 p/month

Subscribe to PacktLib

Enjoy full and instant access to over 2000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

Book Details

ISBN 139781849511384
Paperback336 pages

About This Book

  • Build a completely operational real-life application composed of multiple bundles and a web front end using Felix
  • Get yourself acquainted with the OSGi concepts, in an easy-to-follow progressive manner
  • Learn everything needed about the Felix Framework and get familiar with Gogo, its command-line shell to start developing your OSGi applications
  • Simplify your OSGi development experience by learning about Felix iPOJO
  • A relentlessly practical beginner's guide that will walk you through making real-life OSGi applications while showing you the development tools (Maven, Eclipse, and so on) that will make the journey more enjoyable

Who This Book Is For

This book is aimed at Java developers looking to learn about writing reusable and network distributable software following the OSGi standards using the famous Felix framework. If you are a developer who wants to focus on the business logic, and abstract away from the details of how to integrate with specific systems then this book is meant for you.

If you are a Java developer new to OSGi and don't really know where to start from to actually begin developing applications, just pick up this book and discover the ease with which you can start developing powerful, modular, and extensible applications. This book uses the Felix framework 3.0 as an OSGi service platform implementation and covers its usage to a level where it makes you comfortable enough to write your own enterprise-level applications.

Table of Contents

Chapter 1: Quick Intro to Felix and OSGi
What is OSGi?
The framework layout
The shared service registry
Working with bundles
Start levels
Apache Felix and sub-projects
Chapter 2: Setting Up the Environment
Setting up the Felix framework
Time for action - downloading and installing Felix
Time for action - starting Felix
Maven2 and Felix
Chapter 3: Felix Gogo
The Tiny Shell Language
felix scope commands
gogo scope commands
Chapter 4: Let's Get Started: The Bookshelf Project
A simple Bookshelf project
OSGi, Felix, and...
Taking it step-by-step
Some conventions
Chapter 5: The Book Inventory Bundle
Set up the Book Inventory API Bundle project
Time for action - setting up the project skeleton
Time for action - creating the project POM
The Book bean interface
Time for action - creating the Book bean interface
The Book Inventory interface
Time for action - writing the BookInventory interface
Build and deploy the bundle
Time for action - building and deploying the bundle
Let's implement those interfaces
Time for action - creating the POM
Time for action - implementing a mutable book
Time for action - implementing the mock (memory-stored) Book Inventory
Writing the Bundle Activator
Time for action - add a dependency to the OSGi Core library
Time for action - creating the Activator
Time for action - declaring Bundle-Activator
Build and deploy the bundle
Chapter 6: Using the OSGi Bundle Repository
OBR, the OSGi Bundle Repository
Using the OBR scope commands
Installing the Book Inventory bundles to Felix
Time for action - install the book inventory bundles
On dependency management
Chapter 7: The Bookshelf: First Stab
The Bookshelf Service bundle
Time for action - writing the APIs
Time for action - writing BookshelfServiceImpl
Time for action - implementing the service activator
Trying the BookshelfService
Time for action - building the bundle
Time for action - installing and testing the service
Time for action - fulfilling the missing dependency
On class visibility
Chapter 8: Adding a Command-Line Interface
The Apache Felix Gogo Shell Service
Time for action - creating the Bookshelf Service TUI bundle
Implementing a Gogo Shell Service command
Implementing the book:search command
Time for action - adding the required dependencies
Time for action - writing the BookshelfServiceProxy
Time for action - implementing a bundle activator
Time for action - packaging and installing
Time for action - trying out the book:search command
Time for action - cleaning up the bookshelf-service activator
Time for action - implementing the book-add command
Updating an installed bundle
Trying the commands
Sourcing scripts
Time for action - creating a book population script
Chapter 9: Improve the Bookshelf Service with iPOJO
What is Inversion of Control?
The iPOJO Felix sub-project
Injecting iPOJOs
Let iPOJO register the inventory implementation
Time for action - creating the iPOJO metadata
The Felix iPOJO Gogo Command bundle
Migrate the bookshelf service
Time for action - removing lookups in the service implementation
Time for action - writing the bookshelf service iPOJO configuration
iPOJO using annotations
Update the text UI bundle
Time for action - updating the BookshelfServiceProxyImpl
Time for action - writing the iPOJO meta.xml
Time for action - updating the POM
Chapter 10: Improving the Logging
On logging
The OSGi Log Service
Apache Felix Log Service
Creating the log helper bundles
Time for action - creating the bookshelf-log-api bundle
Time for action creating the log helper implementation
Add logging to the bookshelf-service
Time for action updating the bundle POM
Time for action - updating the bookshelf service logging calls
Time for action - logging to BookshelfLogHelper
Trying it out
Using other Log Service implementations
Chapter 11: How About a Graphical Interface?
The OSGi HTTP Service
iPOJO and the Whiteboard Extender
Http Service implementations
Time for action - installing the Apache Felix Http Service
A simple bookshelf web application
Time for action - implementing the servlet
Time for action - declaring the parameter constants
Time for action - implementing the operations
Trying it out
Chapter 12: The Web Management Console
Getting started
Time for action - installing commons-fileupload and commons-io
Time for action - installing json
Time for action - installing and starting the Web Console
A quick overview
Apache Felix iPOJO WebConsole Plugin
Chapter 13: Improving the Graphics
OSGi Web Containers
Pax Web
Time for action - installing the Pax Web bundles
Our bookshelf-webapp
Time for action - creating the bookshelf-webapp bundle
Web application registration
Time for action - setting up the web application bundle
Time for action - specifying dependencies
Getting a service reference in JSP
Time for action - ­ writing the session bean
Time for action - using the service
A first smoke test
Implement the remaining pages
Time for action - ­ implementing the list books by category page
Time for action - explicit package imports
Chapter 14: Pitfalls and Troubleshooting
Common pitfalls
Troubleshooting tips

What You Will Learn

  • Discover the practical implementations of important OSGi concepts
  • Install , configure, and learn how to operate Felix using Gogo
  • Understand how to use Maven to build and deploy OSGi bundles
  • Create an OSGi-compliant application, brick by brick
  • Learn how to implement JSP Web Application Bundles
  • Dive deep into Felix iPOJO
  • Understand Inversion of Control design patterns
  • Get an overview of the Felix Web Management Console
  • Get cozy with troubleshooting an OSGi application using Felix


In Detail

The OSGi specification is a module system and service platform that implements a complete and dynamic component model. Wasn't that a complicated definition! So how would you really use it in practical modular applications? Let this book break down the seemingly overwhelming OSGi standards for you by explaining Apache Felix's powerful architecture in a simple and easy-to-understand manner using Apache Felix framework to get you up and running sooner than you could expect.

The OSGi standards have found a wide range of applications in the context of the Enterprise, Telecommunications, Telematics, Smart Home, E-Health, and Mobile applications, to name just a few. Apache Felix is one of the most famous implementations of the OSGi framework specification. This book introduces OSGi on the simple and extensible Felix framework and guides you from the development environment setup to the troubleshooting of potential issues, walking you through the development of an OSGi-based application and explaining relevant software design concepts.

The book starts with an introduction to the OSGi Service Platform, its parts, and its bundle structure. It then walks you through setting up the Felix framework and your development environment. It describes the Felix Framework and how to operate it using Gogo. It will teach you everything possible about the practical implementation of OSGi using the Felix Framework as a launch pad.

The book then kicks off the Bookshelf project, a case study that will be used to progressively explain the important concepts around OSGi using the Felix framework. The Bookshelf project feature trail will set the context to explain OSGi headers, the bundle activator, the bundle context, and so on.

As you implement the bookshelf step by step, you learn about OBR repositories, dependency management, and bundle version management with Felix.

Moving ahead, a few more advanced topics are covered, such as using iPOJO for dependency injection and service registration; then the book moves on to the implementation of a web-based graphical interface, first using a simple Servlet, and then building a JSP-based Web Application Bundle.

OSGi service specifications such as the Log Service, Http Service, and Web Container are explained. Finally, the book describes some of the common pitfalls during bundle development, and gives hints on troubleshooting them in Felix.


Read More