project handout

braintreesmileSoftware and s/w Development

Aug 15, 2012 (4 years and 11 months ago)

394 views

HRS2422



Course Project



A)

Create a

medical record
Web Service

and
consume the databse driven
-
service from the web
application
.
The service receives information regarding
the types of seats a customer wishes to reserve
and makes a reservation if such a seat is available. In part
-
1, you will create the Seats tables for the Java
DB database, in part
-
2 you will create the service from a given code Reservation.java, and in par
t
-
3 you
will create a web application that allows a customer to specify the reservation request, and then use the
web service to execute the request.


Part.
1

(Create Java DB database)
:


T
his part
requires
creating a Java DB database for use in the Airlin
e Reservation
. You will n
eed to
configure Netbeans 6.5.


1.1
)
In Netbeans 6.5:

Windows | Services |Databases |Java DB | Create Datab
a
se |

Call the database

Reservation


The database location should be created within the project

folder
.


Right
-
click
Jdbc:derby://localhost | Connect | Expand jdbc |right
-
click Table

| Create
Table


Call the
DB
Table

Seats.
Set data type and sizes as shown in the figure.



1.2)
Add a data to the Seats Database


Insert records as shown in the table below

(click t
his icon
):


Note:
You may use

the given
.txt

file to run the SQL query and populate the table in one command (as
an alternative to step (1.2). To do this,
copy the contents of

file
SQL
Commands
ForSeatsTable.txt

and
paste them in the SQL Comman
d tab in t
he Editor of NetBeans. Press the Run SQL button

(to the
right of the Connection drop
-
down list). Thus will insert the records into the table in one shot.Right
-
click
on the Seats table icon and
View Data

to see the table.



File:
SQLCommandsForSeatsTable.txt

(posted in the course site)

INSERT INTO Seats

VALUES ( 1, 'Aisle', 'Economy', 0 );

INSERT INTO Seats

VALUES ( 2, 'Aisle', 'Economy', 0 );

INSERT IN
TO Seats

VALUES ( 3, 'Aisle', 'First', 0 );

INSERT INT
O Seats

VALUES ( 4, 'Middle',
'Economy', 0 );

INSERT INT
O Seats

VALUES ( 5, 'Middle',
'Economy', 0 );

INSERT INTO
Sea
ts

VALUES ( 6, 'Middle', 'First', 0 );

INSERT INTO Seats

VALUES ( 7, 'Window', 'Econo
my', 0 );

INSERT INTO Seats

VALUES ( 8, 'Window', 'Economy', 0 );

INSERT INTO Seats

VALUES ( 9, 'Window', 'First', 0 );

I
NSERT INTO Seats

VALUES ( 10,
'Window', 'First', 0 );




Part
-
2 (
Creating the Reservation Web Service
)

Create the web service using the

Reservation database. The code for the web service is shown below. It
has one single Web method
-

reserve() which searches a Reservation database continaing a singkle table
(Seats) to locate a seat matching the user’s request.


The

file
for the web servi
ce:
Reservation.java


(posted in the course site).


// Part
-
1: Airline Reservation

// File: Reservation.java

// Airline reservation web service.

package

res
ervationservice;


import

java.sql.
Connection
;

import

java.sql.
Statement
;

import

java.sql.
DriverManager
;

import

java.sql.
ResultSet
;

import

java.sql.
SQLException
;

import

javax.jws.WebService;

import

javax.jws.WebMethod;

import

javax.jws.WebParam;


@WebServic
e( name =
"Reservation"
, serviceName =
"ReservationService"

)

public

class

Reservation

{


private

static

final

String

DATABASE_URL =


"jdbc:derby://localhost:1527/Reservation"
;


private

static

final

String

USERNAME =
"oct"
;


private

static

final

String

PASSWORD =
"oct"
;


private

Connection

connection;


private

Statement

statement;




// a WebMethod that can reserve a seat


@WebMethod( operationName =
"reserve"

)


public

boolean

reserve( @WebParam( name =
"seatType"

)
String

seatType,


@WebParam( name =
"classType"

) String classType )


{


try


{


connection =
DriverManager
.getConnection(


DATABASE_URL, USERNAME, PASSWORD );


statement = connection.createStatement();


ResultSet

result
Set = statement.executeQuery(


"SELECT
\
"Number
\
" FROM
\
"Seats
\
""

+


"WHERE (
\
"Taken
\
" = 0) AND (
\
"Location
\
" = '"

+ seatType +


"') AND (
\
"Class
\
" = '"

+ classType +
"')"

);




// if requested seat is avai
lable, reserve it


if

( resultSet.next() )


{


int

seat = resultSet.getInt( 1 );


statement.executeUpdate(
"UPDATE
\
"Seats
\
" "

+


"SET
\
"Taken
\
" = 1 WHERE
\
"Number
\
" = "

+ seat );


return

true
;


}
// end if




return

false
;


}
// end try


catch

(
SQLException

e )


{


e.printStackTrace();


return

false
;


}
// end catch


catch

(
Exception

e )


{


e.printStackTrace();



return

false
;


}
// end catch


finally


{


try


{


statement.close();


connection.close();


}
// end try


catch

(
Exception

e )


{


e.printStackTrace();



return

false
;


}
// end catch


}
// end finally


}
// end WebMethod reserve

}
// end class Reservation


Part
-
3 (Creating a Web Application to interact with the Reservation Web Service)

Create a web application called ReservationClient t
hat consumes the web service

Reservation.

The web application is to allow the users select seats ba
sed on
class
(
Economy or First
) and

location

(
Aisle, Middle, or Window
). User then submit the request to the Reservation wbe service.

If the request fails,
then the application should instruct the user to modify the request and try again by
resubmitting the modified request.


Both files Reserve.jsp and Reserve.java are listed below and are posted in the course site:


3.1)
File:

Reserve.jsp


(posted in the course site).

This file defines two DropDownList objects and a Button.

It also defines three labels (instructionLabel, successLabel, and errorLabel).


<?
xml

vers
ion
=
"
1.0
"

encoding
=
"
UTF
-
8
"
?>

<
jsp:root

version
=
"
2.1
"

xmlns:f
=
"
http://java.sun.com/jsf/core
"

xmlns:h
=
"
http://java.sun.com/jsf/html
"

xmlns:jsp
=
"
http://java.sun.com/JSP/Page
"

xmlns:webuijsf
=
"
http://www.sun.com/webui/webuijsf
"
>


<
jsp:directive.page

contentT
ype
=
"
text/html;charset=UTF
-
8
"

pageEncoding
=
"
UTF
-
8
"
/>


<
f:view
>


<
webuijsf:page

id
=
"
page1
"
>


<
webuijsf:html

id
=
"
html1
"
>


<
webuijsf:head

id
=
"
head1
"
>


<
webuijsf:link

id
=
"
link1
"

url
=
"
/resources/stylesheet.
css
"
/>


</
webuijsf:head
>


<
webuijsf:body

id
=
"
body1
"

style
=
"
-
rave
-
layout: grid
"
>


<
webuijsf:form

id
=
"
form1
"
>


<
webuijsf:staticText

binding
=
"
#{Reserve.instructionLabel}
"

id
=
"
instructionL
abel
"

style
=
"
height: 22px; left: 48px; top: 48px; position: absolute;
width: 238px
"

text
=
"
Please select the seat type and class to
&#xa;

reserve:
"
/>


<
webuijsf:dropDown

binding
=
"
#{Reserve.seatTypeDropDownList}
"

id
=
"
se
atTypeDropDownList
"

items
=
"
#{Reserve.seatTypeDropDownListDefaultOptions.options}
"


style
=
"
left: 48px; top: 96px; position: absolute
"

valueChangeListenerExpression
=
"
#{Reserve.seatTypeDropDownList_processValueChange}
"
/>



<
webuijsf:dropDown

id
=
"
classDropDownList
"

binding
=
"
#{Reserve.classDropDownList}
"

items
=
"
#{Reserve.classDropDownListDefaultOptions.options}
"


style
=
"
left: 48px; top: 144px; position: absolute
"

valueChangeListenerExpr
ession
=
"
#{Reserve.classDropDownList_processValueChange}
"
/>


<
webuijsf:button

id
=
"
reserveButton
"

actionExpression
=
"
#{Reserve.reserveButton_action}
"

binding
=
"
#{Reserve.reserveButton}
"

primary
=
"
true
"

style
=
"
height: 20px; left: 47px;
top: 192px; position: absolute; width: 50px
"

text
=
"
Reserve
"
/>


<
webuijsf:staticText

id
=
"
successLabel
"

binding
=
"
#{Reserve.successLabel}
"

style
=
"
height: 102px; left: 48px; top: 248px;
position: absolute; width: 238px
"



text
=
"
Your reservation has been
made. Thank you!
"

visible
=
"
false
"
/>


<
webuijsf:staticText

id
=
"
errorLabel
"

binding
=
"
#{Reserve.errorLabel}
"

style
=
"
height: 102px; left: 48px; top: 248px;
position: abs
olute; width: 238px
"


text
=
"
This type of seat is not
available. Please modify your request and try again.
"

visible
=
"
false
"
/>


</
webuijsf:form
>


</
webuijsf:body
>



</
webuijsf:html
>


</
webuijsf:page
>


</
f:view
>

</
jsp:root
>


3.
2
) File:

Reserve.java

(posted in the course site)

This file attaches event handlers to
(SeatTypeDropDownList, classDropDownList, and reserveButton) in
the .jsp file, which provides logic in genral for the Reserve.jsp file.



Part
-
4

(Creating
a Phone Book
Web Service

and Web Application that consumes the Service)
--
utilizing Java
DB and Googl
eMap Viewer

Create a web service that stores phone book entries in the
database

PhoneBookDB
and a web
application that consumes the service. Use the steps from part
-
1 to create the phone book DB.

The database should contain one
table

(
PhoneBook
) with thre
e columns (LastName, FirstName, and
PhoneNumber)

each of type VARCHAR. The LastName and FirstName columns should store up to 30
characters. The PhoneNumber columns should support phone numbers of the form (800) 555
-
1212 that
contain 14
-
characters.


Give
the client use the capability to ebter a new contact (web method entry
addEntry
) and to find
contacts by last name (web method
getEntries
). Pass only Strings as arguments to the web service.

The getEntries web methd should return an array of Strings that

contains the matching number for one
phone book entry. These values should be separated by commas.


The SELECT query that will find a PhoneBook entry by last name should be:


SELECT LastName , FirstName, PhoneNumber

FROM PhoneBook

WHERE (LastName=

Las
tName
)


The INSERT statement that inserts a new entry into the PhoneBook database should be:


INSERT INTO PhoneBook (LastName , FirstName, PhoneNumber)

FROM PhoneBook

VALUES (
LastName , FirstName, PhoneNumber
)




Part
-
5


Table (PhoneBook)

with
four

c
olumns (LastName, FirstName, PhoneNumber, and
Address
).

View the address with Google Map Viewer as you search.


You need to create an account at Google Map to obtain a key in order to utilize the MapViewer.


http://code.google.com/apis/maps/signup.html