We now delve into an example application that uses session beans. This application uses the concepts discussed in previous sections, including stateful and stateless session beans and their local and remote interfaces. Chapter 9 looks at a session bean example that has a Web service client view. Our example application, called Benefits Enrollment, is an employee self-service Web application through which an employee manages his or her benefits enrollment selections. The application lets employees enter, review, and change their employer-provided benefits selections. The Star Enterprise IT department developed the Benefits Enrollment application. The IT department relied on its knowledge of the human resources related databases payroll, employee, and benefits databases and their schemas when developing the application. 4.3.1 User View of the ApplicationAn employee invokes the application by pointing his or her browser at a specific Uniform Resource Locator (URL). The application displays a sequence of HTML pages that contain the various benefits choices available to the employee. On each page, the employee can select from one of the displayed choices. After the employee makes a selection, the application displays the next page. After the employee makes all applicable selections, the application displays a summary of the employee's selections and prompts the employee to confirm them. If the employee confirms the selections, the application updates the user's benefits record in the benefits database. When the application displays choices to the user, it also indicates the most recent benefits selection, which it obtains from the user's benefits record. Before confirming selections, the employee may click the browser's Back button to return to previous pages and change previous selections. The application updates the user's benefits record only if the user successfully completes all the pages and confirms the selections at the end of the page sequence. Otherwise, the application leaves unmodified the previous selections stored in the benefits database. Figure 4.5 illustrates the sequence of pages displayed by the application. The figure does not show two pages: the initial login page and the final page, which confirms that the user's changes have been accepted and that they become effective as of the next paycheck. Figure 4.5. Benefits Enrollment HTML Page Sequence4.3.2 Main Parts of the ApplicationFigure 4.6 illustrates the main parts of the Benefits Enrollment application. The EnrollmentEJB session bean implements the business rules of the benefits enrollment business process. The business process consists of a conversation between one user and the server. Therefore, we implement it as a stateful session bean. The EnrollmentWeb Web application is a set of JSPs that implements the presentation logic of the Benefits Enrollment application. Figure 4.6. Parts of the Benefits Enrollment ApplicationThe Enrollment bean accesses a number of corporate databases: EmployeeDatabase, PayrollDatabase, and BenefitsDatabase.
Because of the sensitivity of the payroll information, the payroll department does not allow applications outside of the payroll system to access PayrollDatabase directly. Applications, including the Benefits Enrollment application, must go through the PayrollEJB stateless session bean to access payroll information. The Payroll bean allows client applications to access only those parts of the payroll information to which they have been authorized by the payroll department. The application is deployed as a distributed application across multiple servers. Figure 4.7 illustrates the application deployment. Figure 4.7. Deployment of the Benefits Enrollment ApplicationThe EnrollmentWeb Web application is deployed in a Web container on an application server maintained by the benefits department. The EnrollmentEJB enterprise bean is deployed in an EJB container on the same application server owned by the benefits department. The Benefits application server provides an integrated environment for the deployment of both Web applications and enterprise beans. (Because they use local interfaces, our session beans must be colocated on the same server. If the beans used remote component interfaces, the Web and application servers could be two different servers or the same server.) The PayrollEJB enterprise bean is deployed on an application server owned by the payroll department. The three databases accessed by the benefits enrollment process may reside on three different database servers, as illustrated in Figure 4.7. 4.3.3 The Benefits Enrollment Business ProcessFigures 4.8 and 4.9 illustrate the interactions that occur among the parts of the application during the benefits enrollment business process. Note how the interactions correspond to the sequence of pages shown in Figure 4.5 on page 74. (The numbers to the left of the interactions correspond to the page numbers in Figure 4.5, as well as to steps in the business process.) A step-by-step explanation of these interactions follows the diagrams.
Figure 4.8. Benefits Enrollment Process Interactions, Part 1Figure 4.9. Benefits Enrollment Process Interactions, Part 2 |