<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>EJB In 21 Days ?</title>
	<atom:link href="http://ejbvn.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ejbvn.wordpress.com</link>
	<description>CopyRight Sams Teach Yourself EJB in 21 Days</description>
	<lastBuildDate>Wed, 05 Oct 2011 09:32:01 +0000</lastBuildDate>
	<language>vi</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ejbvn.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>EJB In 21 Days ?</title>
		<link>http://ejbvn.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ejbvn.wordpress.com/osd.xml" title="EJB In 21 Days ?" />
	<atom:link rel='hub' href='http://ejbvn.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Day 21. Developing a Complete Enterprise Application</title>
		<link>http://ejbvn.wordpress.com/2008/11/02/day-21-developing-a-complete-enterprise-application/</link>
		<comments>http://ejbvn.wordpress.com/2008/11/02/day-21-developing-a-complete-enterprise-application/#comments</comments>
		<pubDate>Sun, 02 Nov 2008 07:13:47 +0000</pubDate>
		<dc:creator>EJB VIETNAM WORLD</dc:creator>
				<category><![CDATA[Day 21. Developing a Complete Enterprise Application]]></category>
		<category><![CDATA[Day 21]]></category>

		<guid isPermaLink="false">http://ejbvn.wordpress.com/?p=95</guid>
		<description><![CDATA[Today, you&#8217;ll develop a complete enterprise application. You&#8217;ll apply different concepts you learned in the previous days to build an application that consists of Web components (JSPs and servlets), EJB components (session, entity, and message-driven enterprise beans), and the EIS tier (database tables). The sample university registration system is an end-to-end application that handles the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ejbvn.wordpress.com&amp;blog=5378387&amp;post=95&amp;subd=ejbvn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://ejbvn.files.wordpress.com/2008/11/214.jpg"><img class="alignnone size-full wp-image-204" title="214" src="http://ejbvn.files.wordpress.com/2008/11/214.jpg?w=550" alt="" /></a></p>
<p class="docText">Today, you&#8217;ll develop a complete enterprise application. You&#8217;ll  apply different concepts you learned in the previous days to build an  application that consists of Web components (JSPs and servlets), EJB components  (session, entity, and message-driven enterprise beans), and the EIS tier  (database tables).</p>
<p class="docText">The sample university registration system is an end-to-end  application that handles the online course registration and enrollment process  in a transactional e-commerce environment.</p>
<p class="docText">Today you&#8217;ll see how to perform analysis, design,  implementation, and deployment of the sample application. You&#8217;ll undertake each  of the following:<a name="idd1e60043"></a><a name="idd1e60048"></a><a name="idd1e60053"></a><a name="idd1e60058"></a></p>
<ul>
<li>
<p class="docList">Understand the application requirements</p>
</li>
<li>
<p class="docList">Perform use case analysis</p>
</li>
<li>
<p class="docList">Decide on a system architecture that meets the application  requirements</p>
</li>
<li>
<p class="docList">Identify the components in the multitier architecture and the  interactions among these components</p>
</li>
<li>
<p class="docList">Implement the components, and package and deploy the  application</p>
</li>
</ul>
<h3 class="docSection1Title">Understanding the Application</h3>
<p class="docText">The university registration system is a typical e-commerce  application. The application has a Web site that enables students to browse the  course catalog and register for courses online. <a class="docLink" href="#ch21fig01">Figure 21.1</a> shows an overview of the system. <a name="idd1e60096"></a><a name="idd1e60101"></a><a name="idd1e60106"></a><a name="idd1e60111"></a><a name="idd1e60116"></a><a name="idd1e60121"></a><a name="idd1e60124"></a><a name="idd1e60129"></a><a name="idd1e60134"></a><a name="idd1e60137"></a><a name="idd1e60140"></a></p>
<h5 class="docFigureTitle"><a name="ch21fig01"></a>Figure 21.1. University  registration system.</h5>
<p class="docText"><a href="http://ejbvn.files.wordpress.com/2008/11/211.jpg"><img class="alignnone size-full wp-image-198" title="211" src="http://ejbvn.files.wordpress.com/2008/11/211.jpg?w=550" alt="" /></a></p>
<p class="docText">The application provides the following functionality:</p>
<ul>
<li>
<p class="docText"><span class="docEmphRoman">Student registration—</span> This  functionality enables new students to create and maintain their account  information. The account information includes the student&#8217;s first name, last  name, address, e-mail, login name, and password.</p>
</li>
<li>
<p class="docText"><span class="docEmphRoman">Student authentication—</span> This  module handles the student login process, such as verifying the login name and  password. This ensures that only registered students browse the course catalog  and purchase courses for enrollment.</p>
</li>
<li>
<p class="docText"><span class="docEmphRoman">Course catalog browsing—</span> The  Web site displays the current course offerings in the university and their  details. The course details include the course title and fee.</p>
</li>
<li>
<p class="docText"><span class="docEmphRoman">Enrollment cart—</span> The enrollment  cart module enables students to place their course selection in a shopping cart  while browsing the course catalog, and later to view the cart contents before  placing an order.</p>
</li>
<li>
<p class="docText"><span class="docEmphRoman">Order processing—</span> The order  module enables students to place their orders, and performs the necessary  verification before approving them.</p>
</li>
<li>
<p class="docText"><span class="docEmphRoman">Administrator interface—</span> This  functionality allows the administrator to view and approve orders for  enrollment. <a name="idd1e60215"></a><a name="idd1e60220"></a><a name="idd1e60225"></a><a name="idd1e60230"></a><a name="idd1e60235"></a><a name="idd1e60240"></a><a name="idd1e60243"></a><a name="idd1e60248"></a><a name="idd1e60253"></a><a name="idd1e60256"></a><a name="idd1e60259"></a><a name="idd1e60262"></a></p>
</li>
<li>
<p class="docText"><span class="docEmphRoman">Notification—</span> This  functionality causes the system to send e-mail to students when they have  enrolled for a course.</p>
</li>
</ul>
<h3 class="docSection1Title">Analyzing the Application</h3>
<p class="docText">Use case analysis is the standard technique for analyzing the  requirements of an application. A use case diagram shows the interaction between  the system and actors. An <span class="docEmphasis">actor</span> is a role that  human and/or nonhuman users of the system play when interacting with use cases.  <a class="docLink" href="#ch21fig02">Figure 21.2</a> shows a high-level use case  diagram of the university registration system.</p>
<h5 class="docFigureTitle"><a name="ch21fig02"></a>Figure 21.2. Use case  diagram.</h5>
<p class="docText"><a href="http://ejbvn.files.wordpress.com/2008/11/212.jpg"><img class="alignnone size-full wp-image-202" title="212" src="http://ejbvn.files.wordpress.com/2008/11/212.jpg?w=550" alt="" /></a></p>
<p class="docText">The use case diagram in this case consists of actors, such as  student, administrator, and order verification system. The following describes  the use cases:<a name="idd1e60302"></a><a name="idd1e60307"></a><a name="idd1e60312"></a><a name="idd1e60315"></a></p>
<p><a name="ch21pr01"></a></p>
<ul>
<li>
<p class="docText">New students register with the system.</p>
</li>
<li>
<p class="docText">Existing students log on to the system and can browse the  course catalog.</p>
</li>
<li>
<p class="docText">A student can select courses and add them to the enrollment  cart.</p>
</li>
<li>
<p class="docText">A student places an order for the enrollment cart contents.</p>
</li>
<li>
<p class="docText">The system verifies the order in the background.</p>
</li>
<li>
<p class="docText">An administrator can view the verified orders that need  approval for enrollment.</p>
</li>
<li>
<p class="docText">An administrator approves the order and enrolls the student in  the courses.</p>
</li>
<li>
<p class="docText">The system notifies the student of enrollment via  e-mail.</p>
</li>
</ul>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td valign="top"><a name="ch21lev1sec3"></a></p>
<h3 class="docSection1Title">Architecting the System</h3>
<p class="docText"><span class="docEmphasis">Architecting</span> consists of  deciding what tiers are needed for the application, what services are required  at each tier, and how the application logic will be spread across different  tiers. As you learned on <a class="docLink" href="0672324237_ch15.html#ch15">Day  15</a>, &#8220;Understanding J2EE Architecture,&#8221; the J2EE architecture is designed for  multitier applications. In a multitier architecture, the business logic can be  split into more than one layer. In the sample application, logic is partitioned  into the business logic tier and the presentation logic tier. The user interface  is partitioned into the client tier and the presentation tier. The  application-persistent data is stored in the EIS tier. <a class="docLink" href="#ch21fig03">Figure 21.3</a> shows the architecture of the system.<a name="idd1e60376"></a><a name="idd1e60381"></a><a name="idd1e60386"></a></p>
<h5 class="docFigureTitle"><a name="ch21fig03"></a>Figure 21.3. Architecture  diagram.<a name="idd1e60395"></a></h5>
<p class="docText"><a href="http://ejbvn.files.wordpress.com/2008/11/213.jpg"><img class="alignnone size-full wp-image-203" title="213" src="http://ejbvn.files.wordpress.com/2008/11/213.jpg?w=550" alt="" /></a></p>
<p class="docText">The sample architecture consists of the following tiers:</p>
<ul>
<li>
<p class="docText"><span class="docEmphRoman">Client tier—</span> Students and  administrators use the client tier to interact with the system. The client tier  is provided by a Web browser, such as Internet Explorer or Netscape Navigator.  The client tier communicates with the Web tier by using the HTTP protocol.</p>
</li>
<li>
<p class="docText"><span class="docEmphRoman">Web tier—</span> This tier accepts  user requests and generates responses using the presentation logic. The sample  application uses both servlets and JSPs in a Web container. The Web tier  communicates with the business logic tier using RMI/IIOP protocol.</p>
</li>
<li>
<p class="docText"><span class="docEmphRoman">Business logic tier—</span> This tier  handles the core business logic of the application. The business components are  implemented as EJB components with support from an EJB container.</p>
</li>
<li>
<p class="docText"><span class="docEmphRoman">EIS tier—</span> The EIS tier consists  of the database in which the sample application&#8217;s permanent data is stored. The  business-logic tier communicates with the EIS tier using JDBC.</p>
</li>
</ul>
<p><a name="ch21note01"></a></p>
<div class="docNote">
<p class="docNoteTitle">Note</p>
<p class="docText">J2EE offers flexibility in partitioning the application logic  across tiers. For example, you have a choice between Web-centric and EJB-centric  design. In the Web-centric design, the Web tier components are responsible for  most of the application&#8217;s functionality. The Web tier components communicate  directly with the EIS tier using container services such as the JDBC API. In the  EJB-centric design, the enterprise beans encapsulate the core application logic.  Web tier components communicate with EJB tier components instead of accessing  the EIS tier directly.<a name="idd1e60503"></a><a name="idd1e60508"></a><a name="idd1e60513"></a><a name="idd1e60516"></a></p>
<p class="docText">The decision between the Web-centric and EJB-centric approaches  depends on factors such as application functionality and scalability  requirements. The Web-centric approach offers a quick start for small  applications, but can rapidly become complex and difficult to maintain for large  applications. The EJB-centric approach offers advantages such as automatic  handling of transactions, distributed processing, security, and so on, and can  stay manageable as applications grow more complex. The sample application uses  the EJB-centric approach.</p>
<p class="docText"><!--SafClassName="docSection1Title"--><!--SafTocEntry="Designing the Application"--><!-- 	.tt1    {font-size: 10pt;} --></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td valign="top"><a name="ch21lev1sec4"></a></p>
<h3 class="docSection1Title">Designing the Application</h3>
<p class="docText">Next, you must decide what components are needed in each tier  and how they interact with each other to achieve the required functionality.</p>
<p class="docText"><a class="docLink" href="#ch21fig04">Figure 21.4</a> shows the  high-level design of the application. Please note that this diagram does not  show all the components and their interactions. The diagram shows JSPs,  servlets, enterprise beans, and database tables. The following sections discuss  the various components in detail. <a name="idd1e60544"></a><a name="idd1e60549"></a><a name="idd1e60554"></a><a name="idd1e60559"></a><a name="idd1e60564"></a><a name="idd1e60569"></a><a name="idd1e60572"></a><a name="idd1e60577"></a><a name="idd1e60582"></a><a name="idd1e60587"></a><a name="idd1e60592"></a></p>
<h5 class="docFigureTitle"><a name="ch21fig04"></a>Figure 21.4. Application  design.</h5>
<p class="docText"><a href="http://ejbvn.files.wordpress.com/2008/11/214.jpg"><img class="alignnone size-full wp-image-204" title="214" src="http://ejbvn.files.wordpress.com/2008/11/214.jpg?w=550" alt="" /></a></p>
<p><a name="ch21lev2sec1"></a></p>
<h4 class="docSection2Title">Designing the Business Logic Tier Components</h4>
<p class="docText">The following discusses the key enterprise beans in the  business logic tier:</p>
<ul>
<li>
<p class="docList">The concept of the student is central to the university  registration application. Multiple clients must share behavior, such as creating  a student account, verifying an existing account, and updating account  information. Updates to the state of a student object must be written to the  persistent store. The student object must live even when the client&#8217;s session  with the server is over. Therefore, the <tt>Student</tt> component is modeled as  a container-managed persistence entity bean.<a name="idd1e60620"></a><a name="idd1e60625"></a><a name="idd1e60630"></a></p>
</li>
<li>
<p class="docList"><tt>SignOn</tt> is the authentication component that verifies  the user login name and password. This component uses the <tt>User</tt> component to retrieve and store the user&#8217;s login name and password. Such a  component doesn&#8217;t need to maintain client-specific state information across  method invocations, so the same bean instance can be reused to service other  client requests. This can be modeled as a stateless session bean.</p>
</li>
<li>
<p class="docList">The <tt>Course</tt> component models the courses offered by the  university. Because courses are persistent objects, <tt>Course</tt> is modeled  as a container-managed persistence entity bean.</p>
</li>
<li>
<p class="docList"><tt>EnrollmentCart</tt> models the shopping cart concept in a  typical e-commerce Web site. While browsing the course catalog, a student can  add courses to and remove courses from the <tt>EnrollmentCart</tt>. A cart must  be allocated by the system for each student concurrently connected to the Web  site. All the selected courses of a student will be added to the temporary cart.  This cart is not a persistent object because the student can choose to abandon  the cart. Therefore, in the application, <tt>EnrollmentCart</tt> is modeled as a  stateful session bean. Alternatively, if you want the enrollment cart to survive  a client machine or server crash, you must model it as an entity bean.</p>
</li>
<li>
<p class="docList">A student places an order when he/she is ready to purchase the  enrollment cart contents. The <tt>Order</tt> component must live even when the  student&#8217;s session with the application is over. Therefore, the <tt>Order</tt> component is modeled as a container-managed persistence entity bean.</p>
</li>
<li>
<p class="docList">A student&#8217;s order consists of one or more line items. Each line  item represents a single course item that the student has ordered. This is  modeled as the <tt>OrderLineItem</tt> component. Similar to <tt>Order</tt>,  <tt>OrderLineItem</tt> must persist even when the student&#8217;s session with the  application is over. Therefore, <tt>OrderLineItem</tt> is modeled as a  container-managed persistence entity bean. Also, the <tt>Order</tt> entity bean  has a one-to-many bidirectional relationship with <tt>OrderLineItem</tt>. This  relationship is modeled as a container-managed relationship.</p>
</li>
<li>
<p class="docList">The <tt>OrderVerifier</tt> component is responsible for  verifying the order&#8217;s facts, such as the student&#8217;s billing information, the  classroom&#8217;s capacity, and so on. We would like to enable the student to continue  browsing the Web site and not require her to wait for the background processing  to complete. This asynchronous processing can be best modeled using a  message-driven bean. In the sample application, after the student submits an  order, a Java Message Service (JMS) message is sent to a destination, where it  will be processed by an <tt>OrderVerifier</tt> message-driven bean.<a name="idd1e60711"></a><a name="idd1e60716"></a><a name="idd1e60721"></a><a name="idd1e60726"></a></p>
</li>
<li>
<p class="docList">A student can enroll in multiple courses and each course can  have many students enrolled in it. The <tt>Enrollment</tt> CMP component models  the join relationship between the students and the courses. The <tt>Student</tt> entity bean has a one-to-many relationship with <tt>Enrollment</tt> and the  <tt>Course</tt> has a one-to-many relationship with <tt>Enrollment</tt>.</p>
</li>
<li>
<p class="docList">The <tt>Mailer</tt> component is the stateless session bean  responsible for sending e-mail messages. The <tt>AdminFacade</tt> component uses  <tt>Mailer</tt> to send an e-mail confirmation to the student when the  administrator approves the order for enrollment.</p>
</li>
<li>
<p class="docList">The <tt>StudentFacade</tt> component provides a unified  interface to student functionality. Instead of communicating directly with  enterprise beans such as <tt>Student</tt> and <tt>Order</tt>, clients go through  the simpler interface of <tt>StudentFacade</tt>. <tt>StudentFacade</tt> is  modeled as a stateful session bean.</p>
</li>
<li>
<p class="docList">The <tt>AdminFacade</tt> component provides a unified interface  to the administrator functionality. Web components use a single  <tt>AdminFacade</tt> component to access the administrator functionality. This  component is modeled as a stateful session bean.</p>
<p><a name="ch21note02"></a></p>
<div class="docNote">
<p class="docNoteTitle">Note</p>
<p class="docText">The sample application uses the following approach for the  business logic tier design.</p>
</div>
</li>
<li>
<p class="docList">Provides a simple interface to complex functionality by using  session bean façades.<a name="idd1e60807"></a><a name="idd1e60812"></a><a name="idd1e60817"></a><a name="idd1e60822"></a><a name="idd1e60827"></a><a name="idd1e60832"></a><a name="idd1e60835"></a><a name="idd1e60840"></a><a name="idd1e60845"></a><a name="idd1e60848"></a><a name="idd1e60851"></a><a name="idd1e60854"></a></p>
<p class="docList">The session bean façades front the entity beans. For example,  the <tt>StudentFacade</tt> session bean provides a simple interface to student  functionality and fronts entity beans such as <tt>Order</tt>.</p>
</li>
<li>
<p class="docList">For portability and ease of development, container-managed  entity beans are used instead of bean-managed persistence entity beans. Also,  all entity beans provide local interfaces for efficient access due to  co-location.</p>
</li>
<li>
<p class="docList">Uses distributed islands of local components. For example, as  shown in <a class="docLink" href="#ch21fig05">Figure 21.5</a>, one such island is  composed of components such as <tt>StudentFacade</tt>, <tt>SignOn</tt>,  <tt>Course</tt>, and <tt>Order</tt>. All the components within this island  communicate with each other by using local interfaces. This offers the benefit  of higher performance. An island communicates with a remote island by using  remote interfaces, which offers the benefit of scalability.</p>
<h5 class="docFigureTitle"><a name="ch21fig05"></a>Figure 21.5. Distributed islands  of local components.</h5>
<p class="docText"><a href="http://ejbvn.files.wordpress.com/2008/11/215.jpg"><img class="alignnone size-full wp-image-205" title="215" src="http://ejbvn.files.wordpress.com/2008/11/215.jpg?w=550" alt="" /></a></p>
</li>
</ul>
<p><a name="ch21lev2sec2"></a></p>
<h4 class="docSection2Title">Designing the Web Tier Components</h4>
<p class="docText">The following section discusses the Web tier components in the  sample application:<a name="idd1e60904"></a><a name="idd1e60909"></a><a name="idd1e60914"></a><a name="idd1e60919"></a></p>
<ul>
<li>
<p class="docList">The primary role of <tt>URSControllerServlet</tt> servlet is to  act as a controller. This component is responsible for receiving parameters from  the client and then invoking the calls to the EJB tier, which handles the  business logic. Finally, the servlet receives the result and uses it to provide  a response to the user. This servlet usually forwards the response to a JSP to  perform a presentation task.</p>
</li>
<li>
<p class="docList">The application contains the JSP pages, such as the  registration page, login page, course catalog page, enrollment cart page, and  order confirmation page. These components contain the presentation logic for  student-related functionality. In addition, the admin page contains the  presentation logic for administrator-related functionality.</p>
</li>
</ul>
<p><a name="ch21note03"></a></p>
<div class="docNote">
<p class="docNoteTitle">Note</p>
<p class="docText">The sample application uses the MVC (Model-View-Controller)  design pattern discussed on <a class="docLink" href="0672324237_ch07.html#ch07">Day 7</a>, &#8220;Designing Web Applications.&#8221; The  model layer contains the enterprise bean components that handle the core  business logic. The view layer contains the JSP pages, whose job is to format  and present responses to the client. The controller layer provides the  <tt>URSControllerServlet</tt> servlet, which is responsible for receiving the  client request, managing screen flow, and selecting an appropriate response. <a name="idd1e60969"></a><a name="idd1e60974"></a><a name="idd1e60979"></a><a name="idd1e60984"></a></p>
</div>
<p><a name="ch21lev2sec3"></a></p>
<h4 class="docSection2Title">Designing the EIS Tier Database Schema</h4>
<p class="docText"><a class="docLink" href="#ch21fig06">Figure 21.6</a> shows the  database tables and the relationships between them. Each table is shown as a  solid rectangle with two compartments. The top compartment holds the table name  and the bottom compartment holds a list of column names. The primary key  column(s) uniquely identifies a row in the table. We use the abbreviation PK for  the primary key. The foreign key column of a table identifies a row in a  different table. We use the abbreviation FK for the foreign key.<a name="idd1e61008"></a><a name="idd1e61013"></a><a name="idd1e61018"></a></p>
<h5 class="docFigureTitle"><a name="ch21fig06"></a>Figure 21.6. Database schema of  the sample application.</h5>
<p class="docText"><a href="http://ejbvn.files.wordpress.com/2008/11/216.jpg"><img class="alignnone size-full wp-image-206" title="216" src="http://ejbvn.files.wordpress.com/2008/11/216.jpg?w=550" alt="" /></a></p>
<p class="docText">For example, the <tt>enrollments</tt> table consists of the  columns <tt>enrollment_id</tt> (primary key), <tt>student_id</tt> (foreign key  to <tt>student_id</tt> in the <tt>students</tt> table), and <tt>course_id</tt> (foreign key to <tt>course_id</tt> in the <tt>courses</tt> table).</p>
<p><a name="ch21lev2sec4"></a></p>
<h4 class="docSection2Title">Designing the Scenarios</h4>
<p class="docText">This section examines the interactions between components for  key use case scenarios.</p>
<p><a name="ch21lev3sec1"></a></p>
<h5 class="docSection3Title">Student Logs On to the System</h5>
<p class="docText"><a class="docLink" href="#ch21fig07">Figure 21.7</a> shows the  sequence diagram for the use case Student Logs On to the System. The student  enters a login name and password, and clicks the submit button in the login  page. The browser sends an HTTP <tt>GET</tt> request to the Web server. The  <tt>URSControllerServlet</tt> servlet receives the client request and invokes  the <tt>validateUser()</tt> method of the <tt>StudentFacade</tt> enterprise  bean. The façade delegates the method call of the <tt>SignOn</tt> authentication  component, which uses the <tt>User</tt> entity bean to look up and validate the  login name and password. Finally, the controller servlet forwards the request to  the catalog page, which displays the course catalog.<a name="idd1e61095"></a><a name="idd1e61100"></a><a name="idd1e61105"></a></p>
<h5 class="docFigureTitle"><a name="ch21fig07"></a>Figure 21.7. Student Logs On to  the System sequence diagram.</h5>
<p class="docText"><a href="http://ejbvn.files.wordpress.com/2008/11/217.jpg"><img class="alignnone size-full wp-image-207" title="217" src="http://ejbvn.files.wordpress.com/2008/11/217.jpg?w=550" alt="" /></a></p>
<p><a name="ch21lev3sec2"></a></p>
<h5 class="docSection3Title">Student Places Order</h5>
<p class="docText">As shown in <a class="docLink" href="#ch21fig08">Figure 21.8</a>,  when the student clicks the Place Order button in the enrollment cart page, the  <tt>URSControllerServlet</tt> receives the request and invokes the  <tt>placeOrder()</tt> method of <tt>StudentFacade</tt>. The façade first creates  a new order using the <tt>Order</tt> entity bean. The façade then creates  multiple line items using the <tt>OrderLineItem</tt> entity bean and associates  the line items with the order. Finally, the façade sends a JMS message to the  <tt>Destination</tt> using the <tt>MessageSender</tt> component for order  verification purposes.</p>
<h5 class="docFigureTitle"><a name="ch21fig08"></a>Figure 21.8. Student Places Order  sequence diagram.</h5>
<p class="docText"><a href="http://ejbvn.files.wordpress.com/2008/11/218.jpg"><img class="alignnone size-full wp-image-208" title="218" src="http://ejbvn.files.wordpress.com/2008/11/218.jpg?w=550" alt="" /></a></p>
<p><a name="ch21lev3sec3"></a></p>
<h5 class="docSection3Title">Administrator Approves Order and Enrolls Student in  Courses</h5>
<p class="docText"><a class="docLink" href="#ch21fig09">Figure 21.9</a> shows the  sequence diagram corresponding to the use case Administrator Approves Order and  Enrolls Student in Courses. When the administrator approves an order placed by  the student, he or she clicks the Approve Order button on the administrator  page. The <tt>URSControllerServlet</tt> receives the corresponding request and  invokes the method <tt>approvedOrder</tt> of <tt>AdminFacade</tt>. The façade  retrieves the order by using its primary key, <tt>order_id</tt>, and changes the  order status to Approved. The façade then enrolls the student in all the courses  that are part of the order by using the enrollment component. Finally, the  façade sends an e-mail to the student confirming the approval.<a name="idd1e61181"></a><a name="idd1e61186"></a><a name="idd1e61191"></a><a name="idd1e61196"></a><a name="idd1e61201"></a><a name="idd1e61206"></a><a name="idd1e61209"></a><a name="idd1e61214"></a><a name="idd1e61219"></a><a name="idd1e61222"></a><a name="idd1e61225"></a><a name="idd1e61228"></a><a name="idd1e61231"></a><a name="idd1e61236"></a></p>
<h5 class="docFigureTitle"><a name="ch21fig09"></a>Figure 21.9. Administrator  Approves Order and Enrolls Student sequence diagram.</h5>
<p class="docText"><a href="http://ejbvn.files.wordpress.com/2008/11/219.jpg"><img class="alignnone size-full wp-image-209" title="219" src="http://ejbvn.files.wordpress.com/2008/11/219.jpg?w=550" alt="" /></a></p>
<h3 class="docSection1Title" style="text-align:left;">Packaging and Deploying the Application</h3>
<p class="docText" style="text-align:left;">This section describes the steps to package and deploy the  application for both WebLogic Server and JBoss application servers. These steps  assume that you configured <tt>OrderVerifierTopic</tt> as discussed on <a class="docLink" href="0672324237_ch14.html#ch14">Day 14</a>, &#8220;Developing  Message-Driven Beans,&#8221; and <tt>ursMailSession</tt> as discussed on <a class="docLink" href="0672324237_ch20.html#ch20">Day 20</a>, &#8220;Implementing  JavaMail in EJB Applications.&#8221; <a name="idd1e61273"></a><a name="idd1e61278"></a><a name="idd1e61283"></a><a name="idd1e61288"></a><a name="idd1e61293"></a><a name="idd1e61298"></a><a name="idd1e61301"></a><a name="idd1e61306"></a><a name="idd1e61311"></a><a name="idd1e61314"></a><a name="idd1e61317"></a><a name="idd1e61320"></a><a name="idd1e61323"></a><a name="idd1e61328"></a><a name="idd1e61335"></a></p>
<p class="docText" style="text-align:left;">You can run the following commands for WebLogic:</p>
<pre style="text-align:left;">C:\&gt;<span class="docEmphStrong">cd styejb\examples</span>
C:\styejb\examples&gt;<span class="docEmphStrong">setEnvWebLogic.bat</span>
C:\styejb\examples&gt;<span class="docEmphStrong">cd day21</span>
C:\styejb\examples\day21&gt;<span class="docEmphStrong">buildWebLogic.bat</span></pre>
<p class="docText" style="text-align:left;">You can run the following commands for JBoss:<a name="idd1e61363"></a></p>
<pre style="text-align:left;">C:\&gt;<span class="docEmphStrong">cd styejb\examples</span>
C:\styejb\examples&gt;<span class="docEmphStrong">setEnvJboss.bat</span>
C:\styejb\examples&gt;<span class="docEmphStrong">cd day21</span>
C:\styejb\examples\day21&gt;<span class="docEmphStrong">buildJBoss.bat
</span></pre>
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
<h3 class="docSection1Title">Running the Sample Application</h3>
<p class="docText">The following steps describe how to start the PointBase  database server and WebLogic Server, and run the sample application:<a name="idd1e61392"></a><a name="idd1e61397"></a><a name="idd1e61404"></a><a name="idd1e61409"></a></p>
<p><a name="ch21pr02"></a></p>
<ol class="docList">
<li><span style="font-weight:normal;">
<p class="docText">Start PointBase server in a new command window as follows:</p>
<pre>C:\&gt;<span class="docEmphStrong">cd styejb\examples</span>
C:\styejb\examples&gt;<span class="docEmphStrong">setEnvWebLogic.bat</span>
C:\styejb\examples&gt;<span class="docEmphStrong">startPointBase.bat</span></pre>
<p></span></li>
<li><span style="font-weight:normal;">
<p class="docText">Start WebLogic Server in a new command window as follows:</p>
<pre>C:\&gt;<span class="docEmphStrong">cd styejb\examples</span>
C:\styejb\examples&gt;<span class="docEmphStrong">setEnvWebLogic.bat</span>
C:\styejb\examples&gt;<span class="docEmphStrong">startWebLogic.bat</span></pre>
<p></span></li>
<li><span style="font-weight:normal;">
<p class="docText">Open the university registration system URL,  <tt>http://localhost:7001/urs</tt>, using a Web browser. This will display the  main page as shown in <a class="docLink" href="#ch21fig10">Figure 21.10</a>.</p>
<h5 class="docFigureTitle"><a name="ch21fig10"></a>Figure 21.10. Sample application  main page.</h5>
<p class="docText"><a href="http://ejbvn.files.wordpress.com/2008/11/2110.jpg"><img class="alignnone size-full wp-image-210" title="2110" src="http://ejbvn.files.wordpress.com/2008/11/2110.jpg?w=550" alt=""   /></a></p>
<p></span></li>
<li><span style="font-weight:normal;">
<p class="docText">Register a new student by clicking the New students register  here link. Enter <span class="docEmphStrong"><tt>tom</tt></span> for the login  name and <span class="docEmphStrong"><tt>tom</tt></span> for the password. Enter a  first name, last name, address, and email for the student. <a class="docLink" href="#ch21fig11">Figure 21.11</a> shows the corresponding screenshot. Click the  Register button.</p>
<h5 class="docFigureTitle"><a name="ch21fig11"></a>Figure 21.11. Sample application  registration page.</h5>
<p class="docText"><a href="http://ejbvn.files.wordpress.com/2008/11/21111.jpg"><img class="alignnone size-full wp-image-211" title="21111" src="http://ejbvn.files.wordpress.com/2008/11/21111.jpg?w=550" alt=""   /></a></p>
<p></span></li>
<li><span style="font-weight:normal;">
<p class="docText"><a class="docLink" href="#ch21fig12">Figure 21.12</a> shows the  course catalog page. Add a couple of courses to the enrollment cart by clicking  the Add to cart link that corresponds to each course. Click the View your  enrollment cart link to view the enrollment cart.</p>
<h5 class="docFigureTitle"><a name="ch21fig12"></a>Figure 21.12. Sample application  course catalog page.</h5>
<p class="docText"><a href="http://ejbvn.files.wordpress.com/2008/11/2112.jpg"><img class="alignnone size-full wp-image-212" title="2112" src="http://ejbvn.files.wordpress.com/2008/11/2112.jpg?w=550" alt=""   /></a></p>
<p></span></li>
<li><span style="font-weight:normal;">
<p class="docText"><a class="docLink" href="#ch21fig13">Figure 21.13</a> shows the  enrollment cart page. Click the Place Order link to purchase the cart  contents.</p>
<h5 class="docFigureTitle"><a name="ch21fig13"></a>Figure 21.13. Sample application  enrollment cart page.</h5>
<p class="docText"><a href="http://ejbvn.files.wordpress.com/2008/11/2113.jpg"><img class="alignnone size-full wp-image-213" title="2113" src="http://ejbvn.files.wordpress.com/2008/11/2113.jpg?w=550" alt=""   /></a></p>
<p></span></li>
<li><span style="font-weight:normal;">
<p class="docText">Now we&#8217;ll explore the administrator functionality. Open the URL  <tt>http://localhost:7001/urs</tt>. Click the Administrator click here link. <a class="docLink" href="#ch21fig14">Figure 21.14</a> shows the administrator page  displaying the verified order(s). Click the Approve link to approve the order  and enroll the student in the courses.<a name="idd1e61538"></a><a name="idd1e61543"></a><a name="idd1e61548"></a><a name="idd1e61553"></a><a name="idd1e61558"></a><a name="idd1e61563"></a><a name="idd1e61566"></a><a name="idd1e61571"></a><a name="idd1e61576"></a><a name="idd1e61579"></a><a name="idd1e61582"></a><a name="idd1e61585"></a></p>
<h5 class="docFigureTitle"><a name="ch21fig14"></a>Figure 21.14. Sample application  administrator page.</h5>
<p class="docText"><a href="http://ejbvn.files.wordpress.com/2008/11/2114.jpg"><img class="alignnone size-full wp-image-214" title="2114" src="http://ejbvn.files.wordpress.com/2008/11/2114.jpg?w=550" alt=""   /></a></p>
<p></span></li>
</ol>
<p class="docText">The following steps describe how to start the JBoss server and  run the sample application:</p>
<p><a name="ch21pr03"></a></p>
<ol class="docList">
<li><span style="font-weight:normal;">
<p class="docText">Start the JBoss server in a new command window as follows:</p>
<pre>C:\&gt;cd styejb\examples
C:\styejb\examples&gt;setEnvJBoss.bat
C:\styejb\examples&gt;<span class="docEmphStrong">startJBoss.bat</span></pre>
<p></span></li>
<li><span style="font-weight:normal;">
<p class="docText">Open the university registration system URL,  <tt>http://localhost:8080/urs</tt>, using a Web browser. This will display the  main page as shown in <a class="docLink" href="#ch21fig10">Figure 21.10</a>. The  remaining steps are similar to those listed for WebLogic Server&#8217;s steps 4  through 7.</p>
<p></span></li>
</ol>
<h3 class="docSection1Title">Best Practices</h3>
<p class="docText">Local architecture is implemented with local enterprise beans.  Distributed architecture is implemented with remote enterprise beans. Local  architecture offers the benefit of higher performance for the same hardware, but  it&#8217;s harder to scale and cluster. On the other hand, distributed architecture is  easier to scale and cluster, but results in reduced performance for the same  hardware. One possible solution is to create distributed islands of local  components as in the sample application.</p>
<h3 class="docSection1Title">Summary</h3>
<p class="docText">Today, you worked on a complete sample application. We explored  the requirements of the sample university application and analyzed them using a  use case approach. We decided to use the multitier architecture that J2EE  offers. We also decided to use an EJB-centric design in which the enterprise  beans encapsulate the core application logic. We identified those components and  their interactions. Finally, we packaged, deployed, and ran the sample  application.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ejbvn.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ejbvn.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ejbvn.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ejbvn.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ejbvn.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ejbvn.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ejbvn.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ejbvn.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ejbvn.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ejbvn.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ejbvn.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ejbvn.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ejbvn.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ejbvn.wordpress.com/95/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ejbvn.wordpress.com&amp;blog=5378387&amp;post=95&amp;subd=ejbvn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ejbvn.wordpress.com/2008/11/02/day-21-developing-a-complete-enterprise-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/143bf0ef23c81c94cf1f2297f6f04925?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">EJB VIETNAM WORLD</media:title>
		</media:content>

		<media:content url="http://ejbvn.files.wordpress.com/2008/11/214.jpg" medium="image">
			<media:title type="html">214</media:title>
		</media:content>

		<media:content url="http://ejbvn.files.wordpress.com/2008/11/211.jpg" medium="image">
			<media:title type="html">211</media:title>
		</media:content>

		<media:content url="http://ejbvn.files.wordpress.com/2008/11/212.jpg" medium="image">
			<media:title type="html">212</media:title>
		</media:content>

		<media:content url="http://ejbvn.files.wordpress.com/2008/11/213.jpg" medium="image">
			<media:title type="html">213</media:title>
		</media:content>

		<media:content url="http://ejbvn.files.wordpress.com/2008/11/214.jpg" medium="image">
			<media:title type="html">214</media:title>
		</media:content>

		<media:content url="http://ejbvn.files.wordpress.com/2008/11/215.jpg" medium="image">
			<media:title type="html">215</media:title>
		</media:content>

		<media:content url="http://ejbvn.files.wordpress.com/2008/11/216.jpg" medium="image">
			<media:title type="html">216</media:title>
		</media:content>

		<media:content url="http://ejbvn.files.wordpress.com/2008/11/217.jpg" medium="image">
			<media:title type="html">217</media:title>
		</media:content>

		<media:content url="http://ejbvn.files.wordpress.com/2008/11/218.jpg" medium="image">
			<media:title type="html">218</media:title>
		</media:content>

		<media:content url="http://ejbvn.files.wordpress.com/2008/11/219.jpg" medium="image">
			<media:title type="html">219</media:title>
		</media:content>

		<media:content url="http://ejbvn.files.wordpress.com/2008/11/2110.jpg" medium="image">
			<media:title type="html">2110</media:title>
		</media:content>

		<media:content url="http://ejbvn.files.wordpress.com/2008/11/21111.jpg" medium="image">
			<media:title type="html">21111</media:title>
		</media:content>

		<media:content url="http://ejbvn.files.wordpress.com/2008/11/2112.jpg" medium="image">
			<media:title type="html">2112</media:title>
		</media:content>

		<media:content url="http://ejbvn.files.wordpress.com/2008/11/2113.jpg" medium="image">
			<media:title type="html">2113</media:title>
		</media:content>

		<media:content url="http://ejbvn.files.wordpress.com/2008/11/2114.jpg" medium="image">
			<media:title type="html">2114</media:title>
		</media:content>
	</item>
	</channel>
</rss>
