Time for action - explicit package imports

Edit the project POM build plugins section; the maven-bundle-plugin will be configured to include additional imports that may not be used in the class-set:

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.1.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-Category>sample</Bundle-Category>
<Webapp-Context>bookshelf</Webapp-Context>
<!--
<Web-ContextPath>/bookshelf</Web-ContextPath>
-->
<Bundle-SymbolicName>${project.artifactId}
</Bundle-SymbolicName>
<Import-Package>
com.packtpub.felix.bookshelf.inventory.api,*
</Import-Package>
</instructions>

Notice the last imported package (*); it will be replaced by the other packages detected by the bundle plugin during the manifest file generation.

Have a go hero implementing the remaining pages

You get the gist of it, right? How about you implement the remaining pages? Here are the ones remaining from the initial scope:

Search with authors

A searchAuthors.action.jsp page takes an optional author parameter as search criterion. If none is passed, then it displays the search form:

Search with authors

When the form is submitted, the page performs the search against the bookshelf service and displays the results:

Search with authors

Add book

Also design an addBook.jsp form for submitting a request to add a new book to the bookshelf along with the addBook.action.jsp page to perform the add action and display a page confirming its success.

Add book

The confirmation results page re-uses the book details embedded JSP bit:

Add book

Have a go hero- extending the application

This obviously doesn't cover all the features the bookshelf service provides, especially if you had extended its interface earlier!

There are quite a few more additions that can be made to this:

  • Improve the search pages, say, instead of a search by author only, make it search on all criteria, including only those that were set when invoking the service method
  • Add edit and delete icons to the book row entries

This concludes this case study. If you've followed it carefully, then you've mostly not encountered any problems and have learned a lot on the way. You'd have learned more if you did encounter some issues!

The next chapter looks at some of the common issues and proposes some means to investigate their root cause and resolve them.

How about a quick quiz to jog your memory?

Pop Quiz

  1. Which service interface would you use to register a set of JSP pages from a web application bundle?

    a. Web Container

    b. Web Context

    c. Service Reference

  2. How do you get access to a service from within a JSP?

    a. Use the BundleContext provided at construction

    b. Use the servlet context, retrieving the osgi-bundlecontext attribute

    c. Use injection

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.198.59