Java Reference
In-Depth Information
Fancy Foods
business logic
Fancy
Foods
API
JNDI
Figure 2.15 The Fancy
Foods web bundle ac-
cesses the offer aggre-
gator service using
JNDI. It has no direct de-
pendency on the choco-
late or cheese
department services.
Fancy Foods web
the classes, and injects any references. Often, tens of classes will be bootstrapped by
the Blueprint container in a big chain of managed dependencies. Unfortunately, the
web container also takes a lot of control over servlet lifecycles, instantiating them in
response to incoming web requests.
It's easy to see that if something is both a Blueprint bean and a servlet, the Blue-
print container and the web container could have a messy tussle over what happens
when to the poor servlet, which is caught in the middle. Getting the two to integrate
neatly hasn't been done yet—especially not in a standards-based way.
Unless you're writing an enterprise OSG i application from scratch, the web con-
tainer is unlikely to be the only place where the Blueprint injection model doesn't fit
quite right. Luckily, Blueprint has a nice integration with JNDI . Services registered by
Blueprint are all available in JNDI , and can be looked up using the interface name
(see figure 2.15).
Let's have a look at how you can use JNDI to access your Blueprint service (figure 2.15)
by writing another servlet called fancyfoods.web.SayHello JNDI and putting it into our
web bundle. You can see how the doGet method works in the following listing.
Listing 2.12
Adding special offers using JNDI to access OSGi Services
public class SayHelloJNDI extends HttpServlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
Search WWH ::




Custom Search