Académique Documents
Professionnel Documents
Culture Documents
: SHAMNEEZ MOHAMUDBUCUS
Student ID
: TP022221
Intake
: UC3f1211SE
Module CODE
: CT024 3 3 DCOMS
Lecturer
NAZIR
Submission DATE
: 13 august 2013
DUE DATE
: 23 august 2013
2013
ACKNOWLEDGEMENT.......................................................................................................4
ABSTRACT..............................................................................................................................4
GANTT CHART......................................................................................................................5
1.0
INTRODUCTION........................................................................................................6
2.0
PROGRAM DESIGN..................................................................................................7
2.1
Screen Design..............................................................................................................7
2.1.1
Login Interface...............................................................................................................7
2.1.2
2.1.3
2.1.4
Wallet Interface..............................................................................................................8
2.2
3.0
3.1
Technical Document..................................................................................................10
3.1.1
3.1.2
Class Diagram..............................................................................................................10
3.1.3
3.1.3.1
3.1.3.2
Swing Components................................................................................................................12
3.1.3.3
3.1.4
Questions Answered.....................................................................................................12
3.1.4.1
QUESTION 1.........................................................................................................................12
QUESTION 2.........................................................................................................................16
QUESTION 3.........................................................................................................................18
2013
QUESTION 4.........................................................................................................................24
File Handling for Getting Food List and Food Code (Functions.java)...............................................24
Displaying Food Image and List (FoodMenuFunctions.java)............................................................25
Displaying Food Details on Interface (FoodMenuPanel.java)...........................................................26
3.1.4.5
QUESTION 5.........................................................................................................................26
IRemote.java.......................................................................................................................................27
Obj.java...............................................................................................................................................28
File Handling for Purchase (Functions.java and FoodMenuFunctions.java).....................................31
Performing Purchase and Generating Receipts (FoodMenuFunctions.java)......................................35
Put Food Items in Order Table (Functions.java).................................................................................36
Setting Order Table (FoodMenuFunctions.java).................................................................................36
Update Order Table with New Orders (FoodMenuFunctions.java)....................................................36
Checking Customer Order Quantity against Food Quantity (FoodMenuFunctions.java)..................37
Check Customer Order Quantity with Food Quantity (FoodMenuFunctions.java)...........................38
Implementing Discard Button (FoodMenuPanel.java).......................................................................38
Implementing Order Button (FoodMenuPanel.java)..........................................................................39
Implementing Confirm Button (FoodMenuPanel.java)......................................................................40
3.1.4.6
QUESTION 6.........................................................................................................................41
QUESTION 7.........................................................................................................................45
QUESTION 8.........................................................................................................................46
3.1.5
3.2
User Document..........................................................................................................50
3.2.1
3.2.2
Login Interface.............................................................................................................50
3.2.3
3.2.4
4.0
2013
Transaction Interface....................................................................................................52
TESTING....................................................................................................................53
4.1
4.2
Test Results................................................................................................................55
5.0
CRITICAL EVALUATION.......................................................................................63
5.1
Limitations.................................................................................................................63
5.2
Future Enhancements................................................................................................63
6.0
CONCLUSION...........................................................................................................64
REFERENCES.......................................................................................................................65
2013
ACKNOWLEDGEMENT
I am grateful to the ALMIGHTY ALLAH, The Most Merciful for enabling me to
complete this assignment with success. My inspiration for building the two applications
successfully came from my lecturer, Dr Amril, who kept motivating me throughout the
semester to improve my work and present fully workable systems at the end. I would like to
thank my lecturer for giving me feedback on my work from time to time, keeping track of my
work and trusting my abilities to deliver a project of this quality.
I would like to show my gratitude to my parents, who have done a lot of sacrifices and
efforts to bring me to this stage, by giving me moral and financial support throughout my life
as well as physical support when I fell seriously ill during my sixth semester. Without them, I
would not have been able to complete my last semester. I would like to thank the most
wonderful mom and dad for making me what I am today.
ABSTRACT
This assignment is about developing a Food Delivery System, using the RMI (Remote
Method Invocation) Technology. The document introduces the system and its functions. It
discusses the different stages of development.
The design section consists of screen design and use case diagram. Coming to the
implementation, it consists of the technical document which has the code listings and
explanations for the major components as well as answering the questions of the assignment
and the user document which explains the program functioning.
The testing section is about the different tests performed and the results given in the
test results section. After testing is done, a critical evaluation of the system is done and the
document is concluded.
2013
GANTT CHART
1.0
2013
INTRODUCTION
Neez Food Delivery System has been developed in Netbeans, using the Remote
from other java virtual machines, possibly from different hosts (Oracle, 2013). The Food
Delivery System has been developed using Graphical User Interfaces (GUIs) in order to
provide user-friendly environment for customers. Security Module, namely Secure Socket
Layer (SSL) protocol has been used to manage security of the application as it deals with
purchase, credit cards and money transfer.
The aim of the project was to provide a fully functioning application to show
functioning of a distributed system involving security. In the following sections, the different
stages of development have been described and questions related to the assignment have been
answered.
2.0
2013
PROGRAM DESIGN
The program design consists of the primary idea of the system which includes designs
of the screens and the Use Case Diagram for the system.
2.1
Screen Design
The different interfaces for the system have been given, with description as follows.
2.1.1
Login Interface
The Login Interface allows a new customer to register and an existing customer to log
into the system.
2.1.2
The user can select the food he wants and then purchase it via this interface.
2013
The personal details interface allows the user to key in his personal details such as
phone number and address and then click on the save button to save the details.
2.1.4
Wallet Interface
The wallet interface allows the customer to deposit money in his account using a valid
credit card number and transfer valid vouchers to another customer account.
2013
Delivery System.
Customer
3.0
IMPLEMENTATION
3.1
Technical Document
3.1.1
2013
The diagram below shows the relationship between the different packages of the
application. The two-way arrows show that the relationship is two-way (classes of both
packages depend on each other to a certain extent) while the single directional arrow show
that the relationship is one way only (the classes of one package depends partially on the
pointed package).
3.1.2
Class Diagram
The Class Diagram on the following page shows the relationships between all the
classes in the system. The dotted lines represent dependencies of the classes of each other
while the single line arrows show that the classes make use of the other classes as a whole.
For example, the classes FoodMenuPanel, UserPanel, TransactionPanel and LoginUI depend
on the ClientMain class in order to obtain the username and password to identify the user
during transactions while the ClientMain class needs the classes User and IRemote to
authenticate the customer using the application.
10
2013
11
2013
Various concepts have been used in the implementation of the application listed
below.
3.1.3.1
In order to be able to read and write from the text files, arrays have been used.
3.1.3.2
Swing Components
Swing implements a set of GUI components that is built on the Abstract Windows
Toolkit (AWT) technology that provides a pluggable look and feel (EDN, 1994).
3.1.3.3
The RMI technology is a way which a programmer, using the Java programming
language and development environment, writes object-oriented programming in which
objects on different computers can interact in a distributed network.
It is also important to draw attention to the fact that different packages have been created
with classes related to functions, interfaces, security, server and main classes (server and
client). This has been done to provide an organized way of writing the codes for better
understanding.
The codes related to the questions have been broken down into different parts, namely,
File Handling, Interface and Validations. The class name and test number of tests related to
each question have been given in each part.
3.1.4
Questions Answered
3.1.4.1
QUESTION 1
A new user should be able to register a new account to the online food delivery system. The
user should be able to register by using his/her username and password. If the username
exists in the system, the user will be notified to enter a different username. (See Test# T2T3)
ANSWER:
The customer can register/log into the system through the login interface (shown in
the User Document). When the user registers with his username and password, it is checked
for existence in the User.txt file and an error message is displayed if the username already
SHAMNEEZ MOHAMUDBUCUS TP022221
12
2013
exists. The code handling registration of new Users is given below. When the registration is
accepted, a record is created in the Balance.txt for the user to update his balance.
File Handling for Registering User (LoginRegistrationFunctions.java)
The registerUser() method is used to get the user details in order to store them in the
User.txt file. The code given creates a User.txt File if the file doesnt exist and add a new
record to the file, with the username and password from the registration screen.
//register user writing details to files
public static int registerUser(User p) {
int iRet = -1;
String path = System.getProperty("user.dir") + "/src/Database
Files/User.txt";
File file = new File(path);
String username = p.getUsername();
String password = p.getPassword();
String name = " ";
String ic = " ";
String phoneNo = " ";
String address = " ";
String email = " ";
String newUserRecord = username + ";" + password + ";" + name + ";"
+ ic + ";" + phoneNo + ";" + address + ";" + email + ";";
try {
//if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
//true = append file; false = overwrite
BufferedWriter writer = new BufferedWriter(new FileWriter(path, true));
writer.write(newUserRecord);
writer.newLine();
writer.close();
//create an initial balance record
insertBalanceRecord(p.getUsername());
} catch (Exception e) {
System.out.println("RegisterUser Exception: " + e);
}
return iRet;}
//insert balance record for new user
public static void insertBalanceRecord(String username) {
try {
String newBalance = "0.00";
String newBalanceRecord = username + ";" + newBalance + ";";
String path = System.getProperty("user.dir") + "/src/Database
Files/Balance.txt";
File file = new File(path);
//if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();}
//true = append file; false = overwrite
BufferedWriter writer = new BufferedWriter(new FileWriter(path, true));
writer.write(newBalanceRecord);
writer.newLine();
writer.close();
} catch (Exception e) {
System.out.println("insertBalanceRecord Exception: " + e); }}
SHAMNEEZ MOHAMUDBUCUS TP022221
13
2013
14
2013
15
2013
QUESTION 2
After the user has registered to the online food delivery system, the user should be
allowed to log in with username and password he/she registered earlier. (See Test# T4-T6)
ANSWER:
If an existing user logs in, the following code is executed to allow the user to log into
the system and an error message is displayed if the username or password is incorrect.
File Handling for User Login (LoginRegistrationFunctions.java)
When the user logs into the system, the login() method is called in order to retrieve
the users details from the User.txt file.
//login
public static int login(String username, String password) {
int login = 1;
String path = System.getProperty("user.dir") + "/src/Database
Files/User.txt";
try {
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream(path);
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line and when username is not found
while ((strLine = br.readLine()) != null && login == 1) {
//read line and seperate string with delimiter semicolon
String[] data = strLine.split(";");
String fileUsername = data[0];
String filePassword = data[1];
String fileName = data[2];
String fileIC = data[3];
String filePhoneNo = data[4];
String fileAddress = data[5];
String fileEmail = data[6];
//if username found in file
if (fileUsername.equals(username)) {
if (filePassword.equals(password)) {
login = 0;
}}}
in.close();//Close the input stream
} catch (Exception e) {
System.out.println("Login Exception: " + e);}
return login;}
16
2013
17
2013
QUESTION 3
When log in, the user should be able deposit money (add money to his/her account),
and the online food delivery system should update the cash balance of the user. At any point
of time, the user should also be able to inquire current balance of his/her account from online
food delivery system. (See Test# T14-T19)
ANSWER:
When a user logs in and wish to deposit any amount of money into his account or
checks his balance, he can go to his wallet and deposit money via a credit card number and its
CVV2 code. The credit card number should exist in the Card.txt File in order to be valid.
Moreover, the refresh Balance Textbox displays the balance remaining for the user. The
following code allows the customer to do the transactions.
File Handling for Getting Balance (Functions.java)
The getBalance() method is used in order to obtain the current amount of money the
user has in his account. To do so, the Balance.txt file is read and the balance is value is
returned.
//get balance
public static String getBalance(String username) {
String balance = "";
int found = 1;
String path = System.getProperty("user.dir") + "/src/Database
Files/Balance.txt";
try {
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream(path);
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new
InputStreamReader(in));
String strLine;
//Read File Line By Line and when username is not found
while ((strLine = br.readLine()) != null && found == 1) {
//read line and seperate string with delimiter semicolon
String[] data = strLine.split(";");
String fileUsername = data[0];
//if username found in file
if (fileUsername.equals(username)) {
balance = data[1]; } }
//Close the input stream
in.close();
} catch (Exception e) {
System.out.println("getBalance Exception: " + e); }
return balance;
}
SHAMNEEZ MOHAMUDBUCUS TP022221
18
2013
19
2013
fileContent.append(strLine);
fileContent.append("\r\n");
} }}
// Now fileContent will have updated content, which you can
override into file
String path2 = System.getProperty("user.dir") + "/src/Database
Files/Balance.txt";
FileWriter fstreamWrite = new FileWriter(path2);
BufferedWriter out = new BufferedWriter(fstreamWrite);
out.write(fileContent.toString());
out.close();
//Close the input stream
in.close();
} catch (Exception e) {//Catch exception if any
System.err.println("Update Balance Exception: " +
e.getMessage()); }
}
File Handling for Credit Card Number and CVV2 Code (TransactionFunctions.java)
The method deposit() is used to call the method calculateBalance() to update the
Balance.txt file if and only if the checkCard() return true. The checkCard() method is used to
check for existence of credit card number and CVV2 code in the Card.txt file.
public static int deposit(String username, String cardNo, String cvv2,
String balance, String amount) {
//indicates whether deposit is successful
//1=unsuccessful; 0=successful
int success = 1;
String latestBalance = "";
//check if the credit card is exists
success = checkCard(cardNo, cvv2);
//if card exists, proceed deposit function
if (success == 0) {
//calculate balance after deposit
latestBalance = calculateBalance(balance, amount);
//update latest balance
updateBalance(latestBalance, username);
}
return success;
}
//check credit card function
public static int checkCard(String cardNo, String cvv2) {
//1=card not exists; 0=card exists
int exist = 1;
String path = System.getProperty("user.dir") + "/src/Database
Files/Card.txt";
try {// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream(path);
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line and when username is not found
while ((strLine = br.readLine()) != null && exist == 1) {
//read line and seperate string with delimiter semicolon
String[] data = strLine.split(";");
String fileCardNo = data[0];
String fileCVV2 = data[1];
//if username found in file
SHAMNEEZ MOHAMUDBUCUS TP022221
20
2013
if (cardNo.equals(fileCardNo)) {
if (fileCVV2.equals(cvv2)) {
exist = 0;
} } }
//Close the input stream
in.close();
} catch (Exception e) {
System.out.println("checkCard Exception: " + e); }
return exist; }
21
2013
22
2013
return valid;
23
2013
3.1.4.4
`
QUESTION 4
The user should be able to request a list of available food menu from the online food
delivery system. The system should return a list of available food menu to the user. (See
Section 3.2 for Screens)
ANSWER:
A food Menu is available in the application that allows the user to choose the food he
needs and purchases it. The code below displays the list of food for the user.
File Handling for Getting Food List and Food Code (Functions.java)
//get food info into list
public static ArrayList getFoodList() {
ArrayList foodListArr = new ArrayList();
String path=System.getProperty("user.dir")+"/src/Database Files/Food.txt";
try {
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream(path);
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new
InputStreamReader(in));
String strLine;
//Read File Line By Line and when username is not found
while ((strLine = br.readLine()) != null) {
//read line and seperate string with delimiter semicolon
String[] data = strLine.split(";");
foodListArr.add(data[0]); //foodNo
foodListArr.add(data[1]); //foodTitle
foodListArr.add(data[2]); //foodPrice
foodListArr.add(data[3]); //foodDes}
//Close the input stream
in.close();
} catch (Exception e) {
System.err.println("File Error: " + e);
}
return foodListArr;}
//get food code into jcmb
public static ArrayList setFoodNoJcmb() {
ArrayList foodNoArr = new ArrayList();
String path=System.getProperty("user.dir")+"/src/Database Files/Food.txt";
try {
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream(path);
// Get the object of DataInputStream
SHAMNEEZ MOHAMUDBUCUS TP022221
24
2013
}
//Close the input stream
in.close();
} catch (Exception e) {
System.err.println("File Error: " + e);
}
return foodNoArr;
25
2013
3.1.4.5 QUESTION 5
Based on a list food menu given, the user should be able to purchase food by selecting
from the list above. Upon confirmation, the user cash balance from his/her account should be
deducted from the food price. It should not be possible to purchase the food if the cash is not
sufficient from the user account. If the server crashes during purchasing transaction, what
would happen? How would your RMI program handle this problem? (See Test# T7 T19)
ANSWER:
In order to understand question 5 and question 8, the RMI concept need to be
understood. In RMI the client has no function at all. Instead the client uses the services
provided by the server. The server maintains a list of services in the IRemote.java, which
stores all the functions that can be invoked by the client. The Obj.java is the middleman that
redirects the function name registered in IRemote.java to the actual location of the coding.
For example, in this particular application, getFoodList is a function registered in
IRemote.java. It sees the Obj.java for redirecting of the function. The actual location is
Functions.getFoodList().
The application allows the user to select food and the selected food with the quantity
is displayed in the Order List. When the user clicks on purchase, if the balance of his account
is greater than or equal to the purchasing amount the purchase is confirmed, else an error
message is displayed and the application allows the user to redirect to the deposit amount
section.
Based on the RMI technology, described above, in case the server crashes, the user
can still use the application to enter data but the purchase will not be complete as all the
functions are obtained from the server. Moreover an error message will be displayed and the
text files will not be updated. The following codes are for the IRemote.java, Obj.java and
purchase transactions.
26
2013
IRemote.java
The server maintains a list of services in the IRemote.java, which stores all the
functions that can be invoked by the client.
package Server;
import
import
import
import
java.rmi.Remote;
java.rmi.RemoteException;
java.util.ArrayList;
javax.swing.JTable;
27
2013
Obj.java
public class Obj extends UnicastRemoteObject implements IRemote {
public Obj() throws RemoteException {
super();
}
//check if the username exists in DB
public int isUsernameExist(String criteria) {
try {
System.out.println(Functions.getCurrentTime() + ": Invoke
isUsernameExist from " + getClientHost());
} catch (ServerNotActiveException snae) {
snae.printStackTrace();
}
return LoginRegistrationFunctions.isUsernameExist(criteria);
28
2013
29
2013
//voucher transfer
public void voucherTransfer(String transferToUser, String voucherNo,
String voucherAmount){
try {
System.out.println(Functions.getCurrentTime() + ": Invoke
voucherTransfer from " + getClientHost());
} catch (ServerNotActiveException snae) {
snae.printStackTrace();
}
TransactionFunctions.voucherTransfer(transferToUser, voucherNo,
voucherAmount);
}
//*************************** food menu panel ************************
//place order
public void purchaseOrder(String username, double foodPrice, ArrayList
arrOrder){
try {
System.out.println(Functions.getCurrentTime() + ": Invoke
purchaseOrder from " + getClientHost());
} catch (ServerNotActiveException snae) {
snae.printStackTrace();
}
FoodMenuFunctions.purchaseOrder(username, foodPrice, arrOrder);
}
//********************************* user panel ************************
//check if the username exists in DB
public ArrayList getUserDetails(String username) {
try {
System.out.println(Functions.getCurrentTime() + ": Invoke
getUserDetails from " + getClientHost());
} catch (ServerNotActiveException snae) {
snae.printStackTrace();
}
return UserPanelFunctions.getUserDetails(username);
}
//update personal details
public void updatePersonalDetails(String username, String name, String
ic, String phone, String address, String email){
try {
System.out.println(Functions.getCurrentTime() + ": Invoke
updatePersonalDetails from " + getClientHost());
} catch (ServerNotActiveException snae) {
snae.printStackTrace();
}
UserPanelFunctions.updatePersonalDetails(username, name, ic, phone,
address, email);
}}
30
2013
31
2013
32
2013
33
2013
34
2013
35
2013
36
2013
if (tableFoodNo.equals(foodNo)) {
tableOrderQuantity += 1;
}
//check if table has record
if (orderTable.getValueAt(i, 0) != null) {
arrOrder.add(orderTable.getValueAt(i, 0)); //foodNo
arrOrder.add(orderTable.getValueAt(i, 1)); //foodName
arrOrder.add(orderTable.getValueAt(i, 2)); //price
arrOrder.add(tableOrderQuantity); //quantity
} else {
if (tableFoodNo.equals(foodNo) == false) {
arrOrder.add(foodNo);
arrOrder.add(foodName);
arrOrder.add(foodPrice);
arrOrder.add(1);
}
//to terminate the for loop
i = 25; }}
//if the order table is empty, place the order at the first row
} catch (NullPointerException e) {
System.out.println("null pointer in table"); }}
37
2013
38
2013
39
2013
40
2013
QUESTION 6
Finally, given two users in the system e.g., usernames A and B, User A should be able
to transfer cash voucher from his/her account to other user's B account. (See Test# T19 T24)
ANSWER:
The transfer of vouchers from a users account to another users account has been
implemented through a voucher system whereby the voucher code will be verified in
Voucher.txt and an error message is displayed if the voucher doesnt exist or the voucher is
expired. After a valid voucher is transferred the voucher is deleted from the Voucher.txt file.
File Handling for Voucher.txt (TransactionFunctions.java)
//check voucher
public static ArrayList checkVoucher(String voucherNo) {
ArrayList arr = new ArrayList();
String path = System.getProperty("user.dir") + "/src/Database
Files/Voucher.txt";
try {
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream(path);
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new
InputStreamReader(in));
String strLine;
//Read File Line By Line and when username is not found
while ((strLine = br.readLine()) != null) {
//read line and seperate string with delimiter semicolon
String[] data = strLine.split(";");
String fileVoucherNo = data[0];
String fileAmount = data[1];
String fileExpiryDate = data[2];
if (voucherNo.equals(fileVoucherNo)) {
arr.add(fileAmount);
arr.add(fileExpiryDate);}}
//Close the input stream
in.close();
} catch (Exception e) {
System.out.println("check Voucher Exception: " + e);}
return arr;}
//check voucher expiry date against today date
public static int checkVoucherDate(String date) {
//1=expired; 0=not expired
int ex = 0;
//voucher expiry year, month, day
int vDay = Integer.parseInt(date.substring(0, 2));
int vMonth = Integer.parseInt(date.substring(3, 5));
int vYear = Integer.parseInt(date.substring(6));
//today date
String todayDate = Functions.getTodayDate();
int tDay = Integer.parseInt(todayDate.substring(0, 2));
SHAMNEEZ MOHAMUDBUCUS TP022221
41
2013
42
2013
String strLine;
StringBuilder fileContent = new StringBuilder();
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
String user[] = strLine.split(";");
String fileVoucherNo = user[0];
if (user.length > 0) {
if (fileVoucherNo.equals(voucherNo)) {
System.out.println("Delete " + user[0]);
} else {
// update content as it is
fileContent.append(strLine);
fileContent.append("\r\n");}}}
// Now fileContent will have updated content , which has override into file
String path2 = System.getProperty("user.dir") + "/src/Database
Files/Voucher.txt";
FileWriter fstreamWrite = new FileWriter(path2);
BufferedWriter out = new BufferedWriter(fstreamWrite);
System.out.println("sss: \n" + fileContent.toString());
out.write(fileContent.toString());
out.close();
//Close the input stream
in.close();
} catch (Exception e) {//Catch exception if any
System.err.println("Error: " + e.getMessage());}}
43
2013
44
2013
QUESTION 7
Implement secure communication between session with the user and the food online
system (i) when user purchases food and (ii) when the user performs cash transfer (Hint: use
either SSL, SSH or any other security protocols for security needs). (See Test # T1)
ANSWER:
Required validations have been used in the applications to validate the values entered
in the system. However, SSL (Secure Socket Layer) has been used in order to provide
security over networks when purchasing food, depositing money and transferring vouchers as
it involves sensitive data.
Secure Sockets Layer (SSL), now known as Transport Layer Security (TLS) is a
cryptographic protocol providing provides security for communications over networks such
as the Internet. It encrypts the segments of network connections at the Transport Layer endto-end. (Sanjaal, 2013)
Implementing SSL for Receiving Cash (Server.java)
public static byte[] ReceiveCash(String fileName, int index){
try {
File file = new File(fileName);
byte buffer[] = new byte[(int)file.length()];
BufferedInputStream input = new
BufferedInputStream(new FileInputStream(file));
input.read(buffer, 0, buffer.length);
input.close();
return(buffer);
} catch(Exception e){
e.printStackTrace();
return(null);}}
45
2013
3.1.4.8
QUESTION 8
What happen if multiple users use the online food system at the same time? What
if/she purchases the same food item from the online system at the same time? What issues
you might face? How can we resolve the issues? Implement your program to resolve the
potential issues. Indicate exactly in the report of the code segment that you have written to
resolve the issues and please provide detailed explanations. (See Test# T25)
ANSWER:
Using RMI technology, one of the advantages the developer gains is to allow multiple
users to access the system. All services invoked by clients are treated as independent and it
does not affect the other clients. However, the quantity of food in the system is updated on
the spot as soon as an order is made, therefore any customer, who first purchases the last set
of a particular food item, while the remaining clients who order at the same time cannot book
the same food item.
In the application, in order to allow the quantity of food items to be up to date the
Update Food Quantity Class, given on the following pages, updates the quantity immediately
after the order is made so as to allow clients to have the most updated value of quantity.
However in order to protect integrity of the different client threads, the following
Concurrency class may be adapted.
46
2013
47
2013
48
2013
49
2013
50
2013
User Document
The User Document, also known as User Manual allows the User to browse through
the application.
The User
Document only explains the different interfaces while the testing sections provides full
testing and proofs of the functioning of the application.
3.2.1
When the server program is run with the SSL, a confirmation message is displayed on
the screen.
The following output screen shows that the SSL has been configured.
51
2013
The User Details allows a new user to enter his personal details. If the field is left
blank or inappropriate data type is used, an error message is generated when the user clicks
on Save button.
52
2013
Transaction Interface
The transaction interface allows the user to deposit money in his account or send a
voucher to another user of the system. If any invalid data type or character length is use, an
error message is displayed. When the user clicks on Deposit button with valid credit card
number and CVV2 code, the balance of the user is updated.
The Transfer Voucher allows the user to transfer vouchers to other users accounts.
When a valid voucher code and customer username is entered, then the balance of the other
customer is updated and the voucher is deleted from the Voucher File. Any expired voucher
is not acceptable to the system.
53
4.0
2013
TESTING
During the testing process, all buttons and text boxes of the application were
thoroughly tested to find errors. The Unit Test Table shows all the tests performed on the
Neez Food Delivery System.
4.1
Test
#
T1
N- Normal
A-Abnormal
E-Extreme (Border Values)
Item
Run the
Server
T2
T3
Test
data
Type
-
Username
&
Password
T4
T5
T6
Clear
button
T7
Place
Test Data
Purpose &
Test
Expected
Result
Running Server
Purpose:
A confirmation
Running the
message should
Server
be displayed.
Customer Register/Login Form
An error
message to
Username: neez
choose a new
Password: 1234
Purpose:
Username
Reject wrong
should appear.
username or
A confirmation
password
box for user
registration
Test: Click on
Username: neez1
should appear
Register in
Password: 12345
and user should
button
be redirected to
the User Details
Page.
The user should
Purpose:
Username: neez
Reject wrong be redirected to
Password: 1234
the Food Menu
username or
and order Page.
password
An error
Test: Click on message should
Username: neez
Login in
Password: 12345
be displayed on
button
the screen.
Purpose:
The Username
To check if
and Password
clear button
textboxes
clears all data should be
from textbox
emptied.
Food Menu & Order Form
Test:
The selected
Actual Result
Test
Result #
A confirmation
message is
displayed.
R1
An error message
to choose a new
username
appeared.
R2
A confirmation
box for user
registration
appears and user
is redirected to the
User Details Page.
R3
The user is
redirected to the
Food Menu and
order Page.
R4
An error message
is displayed on
the screen.
R5
The Username
and password
Textboxes are
emptied.
R6
R7
54
Item
Test
data
Type
Purpose &
Test
Test Data
Click on the
Place Order
button to put
selected food
item in order
table.
Purpose:
To check if
discard
button
empties order
table
Purpose: To
test whether
quantity more
than available
food item is
rejected
Order
button
T8
Discard
button
T10
T11
Balance: 36
Order amount: 40
T9
Customer
Food
Quantity
T12
T13
User
Order
Balance
Save
Button
T14
T15
T16
N
Credit
Card
Number
& CVV2
Balance: 36
Order Amount: 30
Test: Click on
Confirm
button
Purpose: To
test whether
order is
rejected when
user balance
is less than
order amount
Test: Click on
Confirm
Button
User Details Form
2013
Expected
Result
Test
Result #
food should
appear in the
order table.
items appear in
the order table.
R8
An error
message should
be displayed.
An error message
is displayed.
R9
The order
should be
accepted.
The order is
accepted.
R10
An error
message should
be displayed.
An error message
is displayed.
R11
Order should be
accepted and
new amount
balance
displayed in
Transaction
Interface.
Order is accepted
and new amount
balance is
displayed in
Transaction
Interface.
R12
A save
confirmation is
displayed.
R13
The Balance is
updated.
R14
An error message
is displayed.
R15
An error message
is displayed.
R15
Actual Result
55
Item
Test
data
Type
Test Data
20
T18
Ss
T19
T17
Amount
T20
Voucher
Code
T21
A
E
T22
N
Transfer
to
T23
T24
T25
Multiple
Users
Effect on
quantity
4.2
Purpose &
Test
Purpose:
To check if
data type
other than
integer is
rejected
2013
Expected
Result
Actual Result
Test
Result #
Deposit should
be successful.
Deposit is
successful.
R14
An error
message should
be displayed.
An error message
is displayed.
R16
Voucher amount
and expiry date
are displayed.
R17
An error message
is displayed.
R18
An error message
is displayed.
R19
Amount is
transferred and
Voucher Code is
deleted from
Voucher File.
R20
An error message
is displayed.
R21
An error message
is displayed.
R22
R23
Test: Click on
Confirm
Button
Transaction Form Voucher Transfer
Voucher amount
and expiry date
Purpose:
ABCDEFG123456789
should be
To see if
displayed.
incorrect
voucher code An error
Empty
is rejected
message should
be displayed.
Test: Click on An error
Check Button message must
11222211111111
be displayed
Amount should
Purpose:
be transferred
Non-existing
Valid Voucher Code
and Voucher
username
and
&
code should be
invalid
Username: john
deleted from
voucher
Voucher file.
should be
Invalid Voucher Code
rejected
An error
&
message must
Username: john
Test:
be displayed
Click on
Valid Voucher Code
An error
Confirm
&
message must
Button
Username:sss
be displayed
The second user
should not be
Test: Click on
Two user trying to buy
able to order
purchase
the same food which has
and a stock
from both
quantity 1
error message
screens
should be
displayed.
Test Results
The test results are proofs the tests have been carried out and the results are shown in
56
2013
Result
Running Server
R1
SSL Configuration:
Customer Register/Login Form
R2
R3
R4
R5
57
2013
Result
R6
R7
R8
R9
R10
58
2013
Result
R11
R12
New Balance:
User Details Form
R13
59
2013
Result
Transaction Form Deposit
R14
R15
R16
R17
R18
R19
60
Result
R20
2013
R21
R22
61
2013
Result
R23
The User on the left booked first, therefore he got the last item and the user on the right got the
error message even though the store quantity on the Food Menu shows 1.
62
5.0
CRITICAL EVALUATION
5.1
Limitations
2013
The RMI concept is a new technology learnt since a short span of time by the
developer which was quite hard. Therefore the system has some limitations which will be
discussed. Firstly, no proper concurrency method has been developed for the application
since the requirement was to allow users to access the server and obtain the most updated
values of quantity which can be satisfied by this application. Secondly, The administrator
does not have any proper interface to input the food details, image, voucher numbers in the
application and therefore has to write directly to the file following the given format.
Moreover, users cannot view their receipts via this system and validations have not
been applied in user details (name, address, phone) due to the lack of time for developing the
system.
5.2
Future Enhancements
The current application is functioning perfectly based on the requirements put forward
in the question. However few additional components that would have made the application
very interesting will be discussed as there was not enough time to implement the features.
.
The receipts generated in the application can only be stored in the Receipts File. A
View Receipt Option can be integrated in order to allow the customers to view the previous
orders made.
The administrator has to enter the food details, voucher numbers and credit card
details manually into the files in the current system which can be improved by adding
interfaces to do the actions and a proper credit card validation system with the banks.
One more feature which may be required in future if more components will be
integrated is the Concurrency Hash Map, which allows threads to use the processes of the
server without the need to use locks, which may slow down the efficiency of the system.
63
6.0
2013
CONCLUSION
During the course of this assignment, the RMI technology was well grasped in order
to build a system of quality. Moreover one thing to be highlighted while using the RMI
technology is that the server needs to be optimized for performance, i.e., the server should not
be overloaded with functions, which may slow down the processes. Small functions such as
validation of input data can be implemented on the user interface rather than on the server to
optimize efficiency of the server for the major functions.
Since the technology was newly learnt and the time for the coursework was quite less,
the maximum time that could be dedicated to the project was allocated and all the
requirements of the assignment have been fulfilled. It is very important to understand the
advantages of using the RMI technology which are to allow multiple users to access the
server at the same time as well as give a superficial look of simplicity to the code, whereby
objects being remote, are treated as if they were local on the machine the client is being run.
To shed the light on the experience and teachings obtained through the assignment, it
can be said that the basic knowledge of java on object oriented programming that has been
taught in the lower levels, has been greatly enhanced to be applied in the RMI technology,
with Transport Layer Security (TLS) protocol, previously known as Secure Socket Layer
protocol to allow data to be transmitted in a secure network. Moreover manipulation of data
for a large application using arrays and text files was also very challenging to implement as
logic errors could be fatal for the system. An additional feature was also added which was
the encryption and decryption of user details to protect confidentiality and integrity. If more
time was allocated, a better application could have been presented with additional features
like view receipts.
64
2013
REFERENCES
Code Ranch. 2009. Best Way to Write an Array To A File (Beginning Java forum at
JavaRanch). [online] Available at: http://www.coderanch.com/t/456763/java/java/WriteArray-File [Accessed: 7 Jun 2013].
EDN. 1994. AWT vs Swing. [online] Available at: http://edn.embarcadero.com/article/26970
[Accessed: 5 Jun 2013].
Java Tutorials Point. 2011. Remote Method Invocation (RMI) - javatpoint. [online] Available
at: http://www.javatpoint.com/RMI [Accessed: 20 June 2013].
Oracle Tutorials. 1995. Trail: RMI (The Java Tutorials). [online] Available at:
http://docs.oracle.com/javase/tutorial/rmi/ [Accessed: 22 Jun 2013].
Oracle. 2013. Remote Method Invocation Home. [online] Available at:
http://www.oracle.com/technetwork/java/javase/tech/index-jsp-136424.html [Accessed: 25
Jun 2013].
Sanjaal. 2013. Get Public Key Of SSL Certificate In Java - Kushal's Java Blog | Software
Engineering Blog. [online] Available at: http://sanjaal.com/java/tag/get-public-key-of-sslcertificate-in-java/ [Accessed: 15 Jul 2013].
Stack Overflow. n.d.. encryption - How to encrypt String in Java - Stack Overflow. [online]
Available at: http://stackoverflow.com/questions/1205135/how-to-encrypt-string-in-java
[Accessed: 30 Jun 2013].
Williams, D. 2011. ConcurrentHashMap - avoid a common misuse!. [online] Available at:
http://ria101.wordpress.com/2011/12/12/concurrenthashmap-avoid-a-common-misuse/
[Accessed: 14 Jul 2013].
65