HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

The story about how the n-tier architectures evolved from the single-tier mainframe model has probably been told umpteen times by now (in fact, I retold it myself in last month's e-Java column). Nowadays the trend is to distribute functionality. Modularize everything. Components provide the means to successfully replicate your product in a gazillion scenarios. Client/server is old news. Think distributed architectures. Personalized Webtops. That's the name of the game today.

It's easy to get caught up in the hype and lose touch with reality. The Internet fosters a new type of dynamics that encourages and embraces change faster than the stability of technology. It's an ever-increasing challenge for developers and architects to make decisions regarding when to adopt a new technology and how long to retain the old one. The complexity of these decisions is compounded in that computing technologies usually span multiple tiers of an n-tier application. Development managers and project managers face their own problems when dealing with distributed architectures. One of them is how to structure the development team such that the skillsets of the team members map across the various technologies used to implement the business solution. Who is the architect and how does he or she keep a handle on both ends of the spectrum - from the back office to the front-end browser? What kind of middleware expertise is needed? What kind of GUI needs to be built and how much are the tools going to cost? How does the team responsible for the middleware interact with the front-end Web developers?

One way to alleviate the risk in making such decisions is to clearly define what the tiers of the architecture are going to be and how the functionality of your application maps to those tiers. Everybody talks about n-tier architectures and distributed architectures. But the bottom line is - How do you serve up data to your clients? This month in e-Java we'll start from where we left off last month.

We'll revisit the four basic tiers of a distributed e-commerce application. Our focus will be more on the front end and middle tiers, and on some alternative Java and Web technologies available in the market to implement functional modules in business applications.

The Four Tiers
A typical distributed architecture that nurtures e-commerce applications consists of four-tiers:

  • Client user interface tier
  • Presentation tier
  • Business logic tier
  • Data access tier
Table 1 describes the purpose of each tier in an e-commerce application. In today's Web applications all of us strive to make the client as thin as possible. One of the main reasons for this is that end-user devices today range from desktop PCs to handheld PCs, cell phones and pagers. Thus, in the optimum distribution of tiers, the client UI tier will have minimum functionality; its only purpose will be to render the data on the screen using the display device's native graphic utilities. The thinnest "universal" client in today's distributed systems is the browser.

Table 1

After All, It's All HTML
When it comes to the browser-based UI, all the data that the browser renders is interpreted from HTML. This means that the next tier down in the distributed system serves up HTML to the client. Traditional HTML serves static data only. To provide the high degree of interactivity typical of e-commerce transactions, HTML allows Web developers to embed tags that direct the browser to get fresh data from the server.

Why do we have to go to the server to get data? Because the thin client doesn't do anything else but display data; it doesn't produce data. That's the job of the presentation tier.

Java applets provide a way to dynamically generate HTML content. However, applets are downloaded to the client and executed there, thus making the client thicker. Applets enable highly interactive behavior for the client and are good for calculations that can be conducted on the client side. But more complex computations that involve frequent data access (and require security) on the server side need to be executed in the next tier. This is the presentation tier and its responsibility in our context is serving up HTML to the browser-based client.

Splitting the Middle Tier
Thus dynamic content is generated by the tier next to the client UI. This tier, called the middle tier in traditional three-tier systems, could basically access the data from the back-office system, apply business logic to it and serve up HTML to the client. So why split this into a presentation and a business logic tier? Let me answer that question with another question. How do you get data from your data source that resides in the back office? The data could be obtained from sources of various types - database server, file servers, LDAP servers or some legacy system's proprietary interface. The result is that the means of getting the data will differ. Depending on the back-office interface, the middle tier's connection to the back office could be via DCOM, CORBA, RMI, raw HTTP or a variety of other protocols. The scope of a transaction could be very different, depending on the business logic defined in the middle tier. If it's the same logical layer that deals with presentation logic as well as business logic, it becomes very complex. Also, since it's tightly coupled with the back office, it becomes less flexible and nonportable. This leads to scalability and performance issues.

The popular approach to solve these problems is to allow multiple application objects in a business logic layer. These application objects are responsible for getting the data from the server and making it available to the presentation layer. The presentation layer generates the dynamic HTML and makes it available to the client browser.

Generating Dynamic Content
The presentation layer has several alternatives for generating the dynamic content and serving it back to the client. The most popular approaches are via server-side scripting, Java servlets and Java Server Pages (JSPs), and Active Server Pages (ASPs). ASPs, Microsoft's technology for accessing COM objects, are beyond the scope of this article. JSPs are Java's counterpart to ASPs (hence the name JSP) and are Sun's technology for accessing Java objects on the server. All services on the servlets are Java's gateway to all services on the server side. Servlets are always associated with a Web server. They're created as server threads as a result of a client's HTTP request and they serve up HTML content as a response. A JSP allows developers to embed Java code in HTML pages. These hybrid pages have a .jsp extension and can contain a combination of HTML, Java code and JavaBean components. When the client makes an HTTP request, the servlet engine on the server compiles the JSPs into corresponding servlets.

Another way to add dynamism to HTML is via server-side scripting using JavaScript or JScript. Scripting code is embedded in the page. The difference is that, unlike JSPs, scripting code isn't compiled, it's interpreted. Although this is slower, it's faster to develop, prototype and test. Another popular middleware technique for generating dynamic HTML is to use extensions to HTML tags, which allow the page to access dynamic content. This technique is offered by Web application programming languages like Allaire's CFML.

These presentation technologies are still needed to talk to the business logic tier in order to actually obtain the data that needs to be presented. That is where server-side technologies like EJBs and COM come into the picture. The business logic and data source accessibility is abstracted by these technologies.

E-Commerce Functional modules
The technologies selected for your application should be based on the behavior that's expected from the functional module. For example, you can create a shopping cart component using CGI, JavaScript, servlets, JSPs, CFML or other types of dynamic-content generation technologies. However, when settling on a technology, you should ask yourself what the interface to the business logic tier is. Are your business objects COM objects, EJB objects or just database adapters? Can you access the COM objects via CORBA? Is there even a need to talk to the business logic tier for all transactions? For example, if the next step in your workflow is a credit card payment, the information doesn't need to go beyond the presentation layer, provided that the presentation layer has hooks into a credit card payment system like CyberCash.

One of the unique features offered by technologies like CFML is that it allows you to embed SQL inside your HTML. This means you can access the database directly from your HTML page as opposed to going to a business logic layer. This allows you to segregate your database into a front-end database, which could contain, for example, user profiles, account information and maybe local catalog information. On the other hand, if you need to access services offered by the back office such as information pulled out in real time from a reservation engine, you probably need to call Java or COM objects on the server side. In addition, if your catalog information is dependent on business rules that tie into the back office, then you'd probably like to go through a business logic tier. In that case JSPs may be a better alternative to build your shopping cart.

Trading Places
The notion of splitting the middle tier is important for building robust and flexible business applications. You may also want to divide the responsibility of load balancing and fault tolerance between the two middle-tier layers (presentation and business logic). For example, both ColdFusion (presentation) and WebLogic (business logic) offer clustering capabilities. Some transactions, such as credit card payments or catalog queries, may not need to go back to the business logic tier. Decoupling these two layers gives a large boost to scalability.

In the end, what the end user sees is your workflow that abstracts him or her from all these complexities. However, as someone who provides e-business solutions, I believe it's our job to create these abstractions to offer a more satisfying experience for the users of our systems.

E-Book
Starting this month, I'd like to add a monthly book review to the e-Java column, an idea I am shamelessly stealing from Alan Williamson of Straight Talking fame. Having received mail from several readers who have asked about good sources of information on several topics, I figured this is a good way to share my opinion on recently released books with all you fine folks.

In the mad rush for deliverables and the race to overcome the time-to-market dilemma, I find myself more often than not desperately trying to catch up on technology. In Java, that roughly translates to new APIs. Since I returned to Dallas pumped up from JavaOne in June, I've been trying to find time to catch up on J2EE. O'Reilly & Associates' Nutshell Handbook series seems to be created for such situations. Java Enterprise in a Nutshell: A Desktop Quick Reference is a great book if you want to get a quick ramp-up on the J2EE APIs.

It starts off where Java in a Nutshell ended. This is an excellent reference, but it's not for everyone. If you're looking for a comprehensive Java reference that covers Java in all its glory, this isn't the book for you - try Core Java published by Prentice Hall. If you're looking for a book on Java 1.1 APIs, don't start with this one - start with its predecessor.

If you know core Java, however, and are interested in a quick introduction to the APIs provided by the Java platform for developing enterprise applications, make sure you get a copy of Java Enterprise in a Nutshell. In typical "nutshell" style, Part I starts with a quick introduction to the Java enterprise APIs, and also gives a concise explanation of what enterprise computing means and how it relates to Java. The diagram on page 12 and the corresponding discussion in chapter 1 are instrumental in bringing readers up to speed with the current role of Java APIs in an e-commerce application. Part II covers the J2EE APIs - JDBC, RMI, Java IDL, Java servlets, JNDI and EJBs. There's just enough code to get your feet wet. If you want to look up an API, read the corresponding chapter, play around with the examples and then go write your application. For more detail and complex examples you'll have to get a book that focuses on that particular API. Finally, Part III of the book is a comprehensive quick reference for the enterprise APIs.

All in all, this is a good book to add to your library. And it's light enough to haul along if you have to travel.

Author Bio
Ajit Sagar is a member of the technical staff at i2 Technologies in Dallas, Texas, focusing on Web-based e-commerce applications and architectures. A Sun-certified Java programmer with nine years of programming experience, including three in Java, Ajit holds an MS in computer science and a BS in electrical engineering.
He can be reached at: [email protected].

 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.