4.7 Application Migration
4.7.1 Migrating a Web-Centric Application to Use
When migrating a Web-centric application to use enterprise beans apply the follow- ing steps:
1. Change Web portions of the application to use a front component and MVC architecture.
2. Create enterprise beans representing model objects. 3. Move application logic to enterprise beans.
4. Move external resource communication from JavaBeans components to enter- prise beans.
5. Minimize display logic code in JSP pages.
4.7.1.1 Centralize Application Control Using an MVC Architecture
If your Web components do not already use an MVC architecture, you will need to modify the design. For more details on implementing an MVC architecture with Web components and enterprise beans, refer to Section 4.6.3 on page 103.
APPLICATION MIGRATION 109
4.7.1.2 Create Enterprise Beans
You will need to create enterprise beans corresponding to the JavaBeans compo- nents used within your application. For an EJB-centric application, you will also need to design a controller enterprise bean. The responsibilities of the controller enterprise bean are described in “Controller Components” on page 105. You may also want to introduce other enterprise beans to handle other tasks, such as sending and receiving messages.
4.7.1.3 Move Application Logic to Enterprise Beans
All application logic provided by JavaBeans components in the Web application will need to be migrated to enterprise beans. This includes code to communicate with external resources.
Application logic for processing events generated by the Web components will need to be moved into the EJB controller. The EJB controller will also need logic for returning model update events to the Web controller.
4.7.1.4 Modify JavaBeans Components
JavaBeans components originally designed to hold the model data will need to be modified to obtain data from the enterprise beans when they receive model update events from the EJB controller. In addition, application logic in JavaBeans compo- nents will need to be moved to the enterprise beans representing the model.
After this modification, the JavaBeans components will become part of the view to represent the contract between JSP pages and the model. The only other logic that should remain in the Web container components is that tied to handling HTTP requests and managing the flow of the application.
4.7.1.5 Minimize Display Logic in JSP Pages
JSP pages should be used to render HTML instructions. To make the JSP pages more manageable, display logic code should be moved out of the JSP pages into custom tags and JavaBeans components whenever possible. For more details, refer back to Section 4.4 on page 85 of this chapter.
4.8
Summary
As a medium, the Web requires application developers to create user interfaces that are flexible and easy to maintain. Web applications can be made more flexible and maintainable through the use of J2EE component technologies such as servlets and JavaServer Pages which used to generate dynamic content in a portable and scalable manner.
Enterprise Web applications should be developed using modular components. These components include servlets, JSP pages, JavaBeans components, and tag libraries containing custom tags. Depending on the composition of your develop- ment team, time constraints, and application architecture, the use of JSP pages and servlets will differ. Both technologies have merits and should be used accordingly. Internationalization expands the potential user base of a Web application. A properly internationalized application can be quickly localized for any number of languages without modifications to the code. It is much easier to internationalize an application during the design phase at the beginning of a development cycle. Retrofitting an existing application can be difficult and expensive.
Architectures for Web applications include basic JSP pages and servlets, Web-centric applications that use JSP pages with modular components, and EJB- centric applications that use JSP pages with enterprise beans. A Web-centric application can be migrated to a highly manageable, scalable, modular, EJB- centric application by using the steps described in this chapter. Gradual migration to a more complex design is less risky than making large-scale design changes to an application.
V
INITA KHANNAis a Member of Technical Staff at Sun Microsystems, where she works as an enterprise bean developer in the J2EE programming model team. Her major contributions include best practices and guidelines when developing business solutions using enterprise beans. Prior to the APM project Vinita was a member of the Enterprise Software Solutions Group where she was involved in the design and development of mission critical business applications for Sun. Vinita holds a B.Tech. degree in Electron- ics from Kamla Nehru Institute of Technology, India and a M.S. degree in Computer Science from California State University, Hayward.113
C H A P T E R
5
The Enterprise JavaBeans
Tier
by Vinita Khanna
I
Na multitier J2EE application, the Enterprise JavaBeans (EJB) tier hosts applica- tion-specific business logic and system-level services such as transaction manage- ment, concurrency control, and security. Enterprise JavaBeans technology provides a distributed component model that enables developers to focus on solving business problems while relying on the J2EE platform to handle complex system-level issues. This separation of concerns allows rapid development of scalable, accessible, and highly secure applications. In the J2EE programming model, EJB components are a fundamental link between presentation components hosted by the Web tier and business-critical data and systems maintained in the enterprise information system tier.This chapter examines the nature of business logic and describes the problems a developer needs to resolve when implementing business logic. It then describes the component model that the EJB tier of the J2EE platform provides to address these problems. The chapter then presents recommendations and practices to best utilize the services provided by the J2EE platform.