Give it a try. Package and deploy the bookshelf-servlet bundle to the releases repository, and then install and start it (deploy -s
) in Felix. Remember that the bookshelf-servlet
belongs to the Tier 1 Services start level (5).
Checking the logs, you will find entries for the successful creation of the iPOJO instance and the registration of the service:
2010.09.23 17:03:21 INFO -
Bundle: com.packtpub.felix.bookshelf-servlet -
[INFO] BookshelfServletImpl : Instance bookshelf.servlet from
factory BookshelfServletImpl created
2010.09.23 17:03:21 INFO -
Bundle: com.packtpub.felix.bookshelf-servlet -
[javax.servlet.Servlet, java.io.Serializable,
javax.servlet.ServletConfig] - ServiceEvent REGISTERED
If all went well, you should be able to access your new servlet at http://localhost:8080/bookshelf
.
The embedded Jetty may take a little time to start and to be ready. Look for a message that looks like Started jetty 6.1.x at port 8080
to know that Jetty is ready to accept requests.
This is a nice example of the collaboration of extenders, each having a separate concern towards a common purpose. From the bundle's point of view, all we've done is define an iPOJO component that is also an Http Servlet and configure it for injection of service instances and properties.
When the bundle is started on the framework, the iPOJO service will instantiate the component and register it as a service. At this point, the whiteboard extension will recognize it as a servlet and publish it with the Http Service.
The preceding flow diagram shows the steps of this activation sequence. They are as follows:
STARTED
event, one of the listeners is the iPOJO Extender. REGISTERED
event, one of the listeners is the Http Whiteboard. HttpServlet
.At this point, the servlet is initialized by the Http Service and made available on the embedded Jetty container.
a. The whiteboard pattern
b. The service locator pattern
c. The dependency injection
a. Invoke the registerServlet
method
b. Through the Http Service whiteboard extension and register the servlet with the bundle context
c. Through the Http Service whiteboard extension and using iPOJO to register the servlet
d. All of the above