Exercises—Case Study

To help understand the role of each of the technologies in the J2EE specification, a single case study will be followed throughout the daily exercises. As you work through the 21 days, a functional implementation of a simple enterprise application will be developed.

The Job Agency

The chosen case study is a simple Job Agency. Jobs are categorized by Location and Skills required for the job. Customers advertise jobs, and Applicants register their location and skills so they can be matched to jobs. Customers and applicants will be notified of job matches by e-mail.

To illustrate the relationships between the different components in the data model for the Agency, a traditional database ERD diagram is shown in Figure 2.16.

Figure 2.16. Case Study ERD.


Today's exercise, which is described later, will be to create the database and register it as a javax.sql.DataSource to the J2EE RI.

The case study has a front office part with the following components:

  • Maintaining the location and job lookup tables

  • Adding customers and advertising jobs

  • Registering job applications

The back office part consists of the following:

  • Matching a new job against existing applicants

  • Matching a new applicant against existing jobs

  • Generating e-mails

Using the Agency Case Study

The example code shown in each day's lesson will use the Customer functionality (jobs and invoices) from the case study. At the end of each day's work, you will be asked to enhance the case study by adding the Applicant functionality (registering jobs) to the system. A fully-worked solution for the exercises is provided on the CD-ROM included with this book, so that you will have a working case study if you choose to omit any day's exercise.

Note

Material for many days exercises, particularly JNDI, JavaMail, JMS and Java Connectors, will primarily use examples and exercises not related to the case study. The last two days' work discuss J2EE in the context of the wider context of Web applications and do not refer to the Agency case study.


Table 2.3 shows roughly what will be covered on each day. Don't worry if some of the terminology is new to you; all will become clear as you work your way through the book.

Table 2.3. Daily Workout
Day Lesson Exercise
1 Introduce multi-tiered application architectures No exercise
2 Introduce the J2EE platform, technologies and roles Install J2EE RI and case study database.
3 Using JNDI naming and directory services Write a JNDI namespace browser.
4 Using data sources, environment entries, and EJB references Build and deploy a simple EJB and client application with J2EE RI.
5 Using Session EJBs to implement business logic Add a Session bean to register job applicants.
6 Using Entity EJBs to encapsulate access to persistent data Add Entity beans for the applicant data and refactor the register Session bean.
7 Using Container Managed Persistence (CMP) and Container Manage Relationships (CMR) with entity EJBs Refactor the applicant Entity bean to use CMP.
8 Adding transaction management to Session and Entity EJBs Add transaction management to the Applicant processing.
9 Using JMS topics and queues Develop a simple chat room service.
10 Using Message-driven beans to implement back office functionality Use Message-driven beans to match new or changed applicants to advertised jobs.
11 Adding e-mail capabilities to back office functionality Use e-mail to send matched jobs to applicants.
12 Developing Web-based applications using servlets Develop a servlet front end to create a new applicant for the Agency case study.
13 Developing Web-based applications using Java Server Pages Use JSPs to register job applicants.
14 Using custom Tag Libraries with JSPs Refactor the register job JSP to use Tag Libraries.
15 Adding security to restrict access to J2EE application functionality and data Add security to control access to the job skills data.
16 Understanding XML and writing simple XML documents Refactor the messages sent to the back office job/applicant matching functionality to use XML
17 Using XSL to transform XML documents into different data formats Transforming an XLD document into HTML for viewing in a Web browser.
18 Understanding design patterns and recognizing patterns present (and absent) from the case study Identify which design patterns can be applied to the case study to improve maintainability.
19 Working with legacy systems using the Connector architecture Identify how the case study could be linked into a legacy invoicing system.
20 Exposing J2EE components as Web Services Create a simple Java stock quote class and expose it as a Web Service. Create a client to retrieve the stock quote information from the server.
21 Using XML-based registries and asynchronous Web Services Create a Web Service JobPortal that will take a SOAP message containing new agency customer information and return a generated customer login ID.

By the end of the course, you will have a simple, but working, job agency enterprise application. The agency will have both a GUI-based front end and a Web-based interface and will have given you a good grounding in the relative strengths of each J2EE technologies and how to apply them.

Practice Makes Perfect

Developing J2EE architectures requires two disciplines:

  • Good analysis and design skills

  • Practical hands-on experience with the J2EE technologies

The first comes with time and experience, but the last few days lessons will help point you in the right direction to becoming a J2EE designer.

The second discipline comes with practice. If you read this book and attempt all the exercises, you will learn a lot more than if you just read the book and simply study the example code shown.

The case study exercises are not complex. They have been designed to take between 30 minutes and 2 hours to complete. The exercises only use information presented and your existing knowledge: you will need to know something about JDBC, Swing, and HTML, but you certainly don't need to be an expert in these technologies. The book “Teach Yourself Java in 21 Days” from SAMS Publishing is a good source for improving your knowledge of JDBC and Swing should you require a little refresher course. More importantly, the exercises will give you hands-on coding experience using J2EE.

The Case Study Directory on the CD-ROM

On the CD-ROM included with this book, you will find all the Java software required to develop all of the code shown in this book.

The CD-ROM contains a directory called CaseStudy. All the example code solutions to the exercises are included in this directory.

There are 21 sub-directories corresponding to each days work. Each day will have one or more of the following directories:

  • Agency The complete Agency case study so far. This includes code from the examples in the book and the completed exercise if this is based on the case study.

  • Examples The code for all the example programs show in the book where these examples are not part of the case study.

  • Exercise Any existing code to be used as a starting point for the exercise. Typically, this will be the Agency case study, including all the example code in the book but excluding the code the reader needs to provide as part of the exercise.

  • Solution A solution to the set problem if the exercise does not enhance the Agency case study.

Installing the Case Study Database

The Job Agency case study requires a small database for storing information about customers, jobs, applicants, and invoices. A Java program to create the database has been provided in the Day 2 exercises on the accompanying CD-ROM. The program uses the Cloudscape database provided with the J2EE RI and can easily be adapted to work with any JDBC compatible database.

Find the directory on the CD called CaseStudyDay02Exercise.

Inside this directory is a Java source file, class file, and two script files:

  • CreateAgency.java A source file for a program to create the Agency database under J2EE RI Cloudscape database.

  • CreateAgency.class The compiled Java class file for CreateAgency.java

  • CreateAgency.bat A Windows NT/2000 batch file to run the application to create the database

  • CreateAgency.sh Unix/Linux Bourne shell script to run the application to create the database

To create the Agency database, you will need write permission to the J2EE installation directory.

Follow the instructions shown earlier in today's lesson for stopping the Cloudscape and J2EE, servers and stop these servers if they are currently running. If you have installed J2EE as suggested, you simply have to enter the following commands from a command (or shell) window:

j2ee –stop
cloudscape -stop

The Java CreateAgency program provided in the Day 2 exercises will create the necessary database files in a sub-directory called Agency. To create and install the database, you will need to do the following:

1.
Copy all the files from the Day 2 exercises directory CD-ROM to the cloudscape sub-directory of the J2EE SDK installation directory.

2.
Change directories to the cloudscape sub-directory of the J2EE SDK home directory and then run the appropriate script program as follows:

Under Windows, type

cd %J2EE_HOME%cloudscape
CreateAgency

Under Linux/Unix, type

cd $J2EE_HOME/cloudscape
./CreateAgency.sh

A new sub-directory called Agency will be created under the current cloudscape directory.

3.
Having created the database, you must now add a data source called Agency to J2EE (data sources are discussed on Day 4, “Introduction to EJBs”). Run the following command to add the data source (the same command is used for both windows and Linux/Unix):

j2eeadmin -addJdbcDatasource jdbc/Agency jdbc:cloudscape:rmi:Agency;create=true

If you have not included the J2EE bin directory in your program search path, you will have to run the command as shown below:

Under Windows, enter the following command:

%J2EE_HOME%inj2eeadmin -addJdbcDatasource jdbc/Agency jdbc:cloudscape:rmi
:Agency;create=true

Under Linux/Unix, enter the following command:

$J2EE_HOME/bin/j2eeadmin -addJdbcDatasource jdbc/Agency jdbc:cloudscape:rmi
:Agency;create=true
								

Finally, restart the Cloudscape and J2EE servers as described in the earlier section, “Starting the J2EE Reference Implementation (RI).” Normally, you would start the J2EE server and Cloudscape database server in separate windows by using the following commands:

j2ee –verbose
cloudscape -start

If you start the J2EE server as shown with the -verbose option, you will see the diagnostic output shown in Listing 2.4 (the line showing the Agency data source configuration is highlighted in bold).

Listing 2.4. The J2EE Reference Implementation Startup Diagnostics
 1: > j2ee -verbose
 2: J2EE server listen port: 1050
 3: Naming service started:1050
 4: Binding DataSource, name = jdbc/DB2, url = jdbc:cloudscape:rmi:CloudscapeDB;create=true
 5: Binding DataSource, name = jdbc/DB1, url = jdbc:cloudscape:rmi:CloudscapeDB;create=true
 6: Binding DataSource, name = jdbc/Agency, url = jdbc:cloudscape:rmi:Agency;create=true
 7: Binding DataSource, name = jdbc/InventoryDB, url = jdbc:cloudscape:rmi
:CloudscapeDB;create=true
 8: Binding DataSource, name = jdbc/Cloudscape, url = jdbc:cloudscape:rmi
:CloudscapeDB;create=true
 9: Binding DataSource, name = jdbc/EstoreDB, url = jdbc:cloudscape:rmi
:CloudscapeDB;create=true
10: Binding DataSource, name = jdbc/XACloudscape, url = jdbc/XACloudscape__xa
11: Binding DataSource, name = jdbc/XACloudscape__xa, dataSource = COM.cloudscape.core
.RemoteXaDataSource@653220
12: Starting JMS service...
13: Initialization complete - waiting for client requests
14: Binding: < JMS Destination : jms/Queue , javax.jms.Queue >
15: Binding: < JMS Destination : jms/firstQueue , javax.jms.Queue >
16: Binding: < JMS Destination : jms/Topic , javax.jms.Topic >
17: Binding: < JMS Cnx Factory : QueueConnectionFactory , Queue , No properties >
18: Binding: < JMS Cnx Factory : jms/QueueConnectionFactory , Queue , No properties >
19: Binding: < JMS Cnx Factory : TopicConnectionFactory , Topic , No properties >
20: Binding: < JMS Cnx Factory : jms/TopicConnectionFactory , Topic , No properties >
21: Starting web service at port: 8000
22: Starting secure web service at port: 7000
23: J2EE SDK/1.3
24: Starting web service at port: 9191
25: J2EE SDK/1.3
26: J2EE server startup complete.
						

You will test the Agency database configuration on Day 4 when you learn how to create and deploy a simple EJB.

Congratulations, you have installed J2EE successfully and completed today's exercise to configure the Agency database for use with the other exercises in this book.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.179.35