Java Reference
In-Depth Information
Figure 2.5 The web
application in action
A familiar feeling—and important differences
Even with the extra headers in the manifest, the web bundle you've written looks a lot
like a conventional Java EE WAR . In fact, it's so similar that you could probably deploy
it as a WAR in a Java EE application. What's different about it, then? A WAB is a bundle ,
and not just a normal JAR , which means it has some new behaviors.
WAR to WAB conversion
The structure of WARs and WABs is similar enough that the OSGi Enterprise Specifi-
cation supports automatic conversion of WARs to WABs at deploy time. A bundle sym-
bolic name and package imports are automatically generated. This can be convenient
when doing an initial migration from Java EE to enterprise OSGi, but in general it's
better to write web applications as WABs. This ensures the bundle has a proper, well-
known, symbolic name, and it also allows package imports to be versioned. Version-
ing package imports is always a good idea. The WAB format also provides a conve-
nient mechanism for setting the web context root.
What are the implications of being an OSG i bundle? The biggest implication is what
can't be seen—nothing outside the fancyfoods.web bundle (see figure 2.6) can see
the SayHello class, because it's not exported. This cozy privacy is exactly what you
want, because there's no reason for any code outside your bundle (except for per-
haps the web container, which can use the OSG i API ) to be messing around directly
with your servlet class. If you did want to make the SayHello class externally accessi-
ble for some reason, all that would be required is to add a package export of the
fancyfoods.web package. But you'd probably want to consider your design carefully
before doing this. Could the shared code be externalized to a utility bundle instead?
Although package privacy is a good thing, not all Java code can cope with it.
Some existing libraries, particularly ones that use reflection to load classes, may not
work properly. We'll discuss strategies for handling awkward existing libraries in
chapter 12.
Search WWH ::

Custom Search