XML technologies / XSLT / Java and XSLT / Java-based web technologies / XSLT and EJB

(Excerpt from “Java und XSLT” by Eric M. Burke)

Having discussed web-tier development options, consider how it interacts with other tiers in large enterprise systems. A typical EJB (Enterprise JavaBeams) architecture includes a thin browser client, a servlet-driven web tier and EJB in the application-server tier. The following figure extends the earlier conceptual XSLT model.

Figure: XSLT and EJB architecture

Figure: XSLT and EJB architecture

This diagram is closer to the physical model of a multi-tier web application using XSLT. Arrows show a single request’s general flow from the client, usually a browser but potentially a phone or other device. The request reaches one servlet, then passes to a RequestHandler. This pattern creates numerous subclasses of RequestHandler. Each handles validation and presentation logic for a small set of related functions. One manageable strategy is to develop a subclass of RequestHandler for each page. Alternatively, create fine-grained request handlers for individual tasks, useful when many application screens invoke the same functionality.

The request handler interacts with the application server through EJB components. Usually it executes commands on session beans, which get their data from Entity beans. The EJB tier’s internal behavior is irrelevant to the web tier. When the EJB method returns, one or more data objects reach the web tier and must be converted to XML.

Conversion can be handled in several ways. Commonly, data objects contain methods producing XML fragments or complete documents. Alternatively, write an XML adapter for each data object, generating XML in the adapter rather than the object. This keeps data objects light and clean but requires extra classes. Either way, return XML as a DOM or JDOM tree rather than raw XML text. Raw text must be parsed back into memory by the XSLT processor. Returning a data structure lets the tree pass directly to the processor without extra parsing.

Another approach returns XML directly from EJB components, eliminating intermediate data objects. The section Development environments, testing and performance examines this in detail, mainly for performance. The main disadvantage is XML’s verbosity: sending large XML text files between servers is less efficient than serialized Java objects. Compression is possible but adds compression and decompression overhead.

However XML is generated, the last step in figure XSLT and EJB architecture sends XML and stylesheet to the XSLT processor for transformation. The result tree goes directly to the client and completes the request. For a browser, the stylesheet probably converts XML to HTML or XHTML. Other clients may receive data directly without transformation.

Trade-offs

Scalability motivates a multi-tier EJB architecture: each tier can run on another machine, and pooling servers for a tier can improve performance. Reliability is another motivation. If one machine fails, a redundant one continues processing. Updates can be rolled out one machine at a time to avoid long outages. Strictly regulating data-tier access through EJB improves security.

Simplicity is another motivation, even though a simple EJB application is much more complex than a simple two-tier one. Distributed systems are complex, but this approach simplifies complex applications by separating independent tasks into tiers. One team can develop EJB components while another works on web-tier request handlers. Designers can work on XML and XSLT while database specialists focus on the database.

For simple applications, EJB is excessive and probably hurts performance. If your site serves only a few hundred visitors daily, removing EJB improves speed by avoiding the extra application tier. Remember that other EJB benefits, such as security, disappear too.

   

 

 

 

back to top