Meta-Storefront for a Distributed E-commerce System (Group Assignment)

 

This optional assignment is due December 18, 23:59pm in the course management system.

 

With your help, TechnoBooks.com deployed a first-rate e-commerce system and sales are booming.  In fact, sales are so plentiful that TechnoBooks.com has decided to implement a just-in-time inventory system.  In this new scheme, TechnoBooks.com will not buy the books and store them in their own warehouses.  Instead, when a user places an order TechnoBooks.com will purchase the books from various suppliers around the world.  This avoids the internal cost of having TechnoBooks.com store the books locally.  To do this, TechnoBooks.com has contracted three suppliers to provide books for online ordering: Addison-Wolly, Prentice Hull, and O-Really.

            Your task is to create a meta-storefront that seamlessly sells books from each of the three suppliers.  However, TechnoBooks.com does not want to store and update a database of what books are available from each supplier because they do not want to worry about availability changes.  What they would like to do is create a distributed data warehouse that queries each of the book suppliers’ systems to see if a book is available.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


            A new technology that is being developed to assist in distributed commerce systems is translation servers.  These servers can translate different data formats and different communication protocols.  For example, Barnes and Nobles has a very detailed inventory ordering form and various book suppliers would need to match their own data to the format specified by Barnes and Nobles.

In this exercise you will write a meta-storefront that implements a portion of one of these translation servers.  Each of the book suppliers uses a different Xml communication format for receiving and responding to orders placed by TechnoBooks.com.  Your task is to translate the order received from a user into an Xml request for each of the three different server types.  This can easily be done using Xslt stylesheets to transform one order request into the proper Xml format for each book supplier.  When the book supplier responds to the request, you can again transform the result using an Xslt stylesheet into one standard format that TechnoBooks.com can understand.  Although this sounds like a lot of work, writing Xslt stylesheets to assist in the transformation is much easier than writing custom parsing and processing code for each supplier’s Xml protocol (in the future, more suppliers may be added!).

            Although each book supplier expects different information from your translation server, each uses a similar protocol.  This protocol is a transaction: there is a statement to query the book supplier for a book, and a result statement that is returned from the supplier stating whether the book was ordered or whether the book could not be found.  The actual Xml statements that are required are listed below

 

Addison-Wolly

 

I. To send a query for a book:

<single_book_order>

       <title>Title of Book</title>

       <qty> Quantity</qty>

</single_book_order>

 

II. If Addison-Wolly does not have the book it will return

<single_book_order>

       <fail/>

</single_book_order>

 

III. If Addison-Wolly has the book and places the order it will return

<single_book_order>

       <title>Title of Book</title>

       <author>Author of Book</author>

       <price>Price of Book</price>

       <isbn>ISBN of Book</isbn>

       <qty>Quantity</qty>  

       <order_id>ID</order_id>          

</single_book_order>

 

Prentice Hull

 

I. To send a query for a book:

<customer>

       <order>

              <item qty='Quantity'>

                     <book title='Title of Book'/>

              </item>

       </order>

</customer>

 

II. If Prentice Hull does not have the book it will return

<customer>

       <order>Item Not Found</order>

</customer>

 

III. If Prentice Hull has the book and places the order it will return

<customer>

       <order id=’ID’>

              <item qty=’Quantity’>

                     <book>

                           <title>Title of Book</title>

                           <author>Author of Book</author>

                           <price>Price of Book</price>

                           <isbn>ISBN of Book</isbn>

                     </book>

              </item>

       </order>

</customer>

 

O-Really

 

I. To send a query for a book:

<form7957>

<purchase item=’book’ property=’title’ value=’Title of Book’ quantity=’Quantity’/>

</form7957>

 

II. If O-Really does not have the book it will return

<form855>

       <message result=’Reject’>Order Failed</message>

</form855>

 

III. If O-Really has the book and places the order it will return        

<form855>

       <message result=’Accept’>

              <book_order>

                     <title>Title of Book</title>

                     <author>Author of Book</author>

                     <price>Price of Book</price>

                     <isbn>ISBN of Book</isbn>
                     <order_id>
ID</order_id>

<quantity>Quantity</quantity>

              </book_order>

       </message>

</form855>

 

Traditionally, a system such as this would require the developer to implement three different parsers and three different processors to understand the “protocols” from each of the different suppliers.  However, with the formalization of XSLT by the W3 Consortium, it is possible to translate one Xml protocol into another.  Thus, the distributed transaction can look like:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


The sequence of events can then be broken into:

 

Receive the Original Book Request from the user

Create a standard Xml document containing the information in the request (include

title and quantity) and store it in a Standard_Request string

For each book supplier

Transform the Standard_Request string into a Supplier_Request string using XSLT

Send the Supplier_Request string to the supplier as a socket request

Receive a result from the supplier as Supplier_Result string

Transform the Supplier_Result string into a Standard_Result string using XSLT

Interpret the results from the Standard_Result

End For

 

When you apply an Xslt stylesheet to an Xml document, the result is another Xml document.  This is the key that allows us to translate any Xml protocol into another Xml protocol.

 

What To Do

Your task is to implement the servlet that will perform these transformations and send the proper requests to each supplier.

 

Step 1: Setup your JavaXml directory

 

Setting Up a Java Servlet and Apache Xml Development Environment

 

You will need to set up Xerces and Xalan from the Apache XML libraries and install them. Don’t forget to to set the  CLASSPATH environment variable to the proper libraries (Java SDK, Servlet SDK, Xerces, and Xalan).  Create a new file using NotePad and name it “start.bat”.  If you stored the “JavaXml” directory on your C drive (C:\JavaXml), then no modifications will be necessary, otherwise modify the paths appropriate to your JavaXml directory:

 

set PATH=%PATH%;C:\JavaXml\jdk1.3\bin

set CLASSPATH=%CLASSPATH%;C:\JavaXml\xerces-1_2_0\xerces.jar;C:\JavaXml\xerces-1_2_0\xercesSamples.jar;C:\JavaXml\Xalan\xalan.jar;C:\JavaXml\Xalan\samples\xalansamples.jar;C:\JavaXml\JSDK2.0\lib\jsdk.jar

 

Step 2: Write the Xslt Stylesheets

            You will use the Adisson-Wolly protocol as the standard protocol (Standard_Request and Standard_Result in the pseudocode).  When an incoming book request arrives, you should create a request in Xml that matches the Adisson-Wolly protocol.  Write stylesheets to transform Addison -Wolly’s request into that of Prentice Hull and O-Really, and stylsheets to transform a Prentice Hull or O-Really response into Addison-Wolly.  You will need four stylsheets in all (you can get by with two, one for each supplier, but for simplicity you may use four).  They should do:

1.       AWtoPHRequest.xsl: Transform the Addison-Wolly Request into a Prentice Hull Request

2.       AWtoORRequest.xsl: Transform the Addison-Wolly Request into an O-Really Request

3.       PHtoAWResponse.xsl: Transform the Prentice Hull Response into the Addison-Wolly Response

4.       ORtoAWResponse.xsl: Transform the O-Really Response into the Addison-Wolly Response

Use the names listed in 1-4 and store each of your stylesheets on the local computer in a directory /stylesheets/ under your Apache file tree.  Try out each of your stylesheets on a variety of samples, and familiarize yourself with the samples in the Xerces and Xalan libraries.

 

Step 3: Database Tables

 

To store your listing of Supplier servers, create a database table with the following server information.


Servers Table in your database

 

Table Schema (underlining is primary key)

 

Field Name

Type

Description

ServerId

Integer

A Server Id

ServerUrl

String

The url where the server is

ServerPort

Integer

The socket port for the server

QueryStylsheetUrl

String

Xslt file for transforming Addisson-Wolly query to another format (not used here)

ResponseStylesheetUrl

String

Xslt file for transforming another response to an Addisson-Wolly response (not used here)

 

Table Data – Insert this data into the Servers table.

 

ServerId

ServerUrl

ServerPort

QueryStylsheetUrl

ResponseStylesheetUrl

3

localhost

1313

“”

“”

4

localhost

1314

<Stylesheet_1_URL>

<Stlyesheet_3_URL>

5

Localhost

1315

<Stlyesheet_2_URL>

<Stlyesheet_4_URL>

 

The stylesheets listed above (<Stlyesheet_1_URL>, etc.) will be a URL to the stylesheets you wrote in Step 2.  You should store your stylesheets in your directory use the Apache path to locate them: http://localhost/stylesheets/<stylesheet-name>.

 

You will also be storing the result of each order in a database on SQL Server.  For this, create the Orders listed below:

 

Orders Table in your database

 

Field Name

Field Type

Description

TransactionId

Integer

A uniquely generated Id for this customer transaction

ServerId

Integer

The Id of the Supplier server that has the order

OrderId

String

The Id returned by the Supplier server

Title

String

The title of the book that was ordered

Author

String

The author’s name

Price

Float

The price of the book

Isbn

String

The ISBN of the book

Quantity

Integer

The quantity of the book that was ordered

 

 

For your own testing purposes, the suppliers have given you a sample of the book information stored on each server.  You should test your final servlet with this information:

 

Adisson-Wolly Server

Title

Author

ISBN

Price

The Blind Assassin

Margaret Eleanor Atwood

1111-1111-1111-1000

2.08

The Lost World

Michael Crichton

1111-1111-1111-1003

6.99

The 13th Warrior

Michael Crichton

1111-1111-1111-1006

4.50

Where In The Dark

Tony Russel

1111-1111-1111-1009

7.25

Free Flowing Water

Sonic Breeze

1111-1111-1111-1012

6.99

Deep Water Is Dangerous

Greg Simons

1111-1111-1111-1015

6.99

 

Prentice-Hull Server

Title

Author

ISBN

Price

How To Walk

Slow Guy

1111-1111-1111-1016

6..99

Blue Sky Horizons

Margaret Eleanor Atwood

1111-1111-1111-1013

6.99

Java in 10 Seconds

Craig Hammang

1111-1111-1111-1010

9.99

Flying Pig Tales

Whacky Jones

1111-1111-1111-1007

10.99

Congo

Michael Crichton

1111-1111-1111-1004

6..99

When We Were Orphans

Kazuo Ishiguro

1111-1111-1111-1001

20.00

 

 

O-Really Server

Title

Author

ISBN

Price

How To Run

Slow Guy

1111-1111-1111-1017

6.99

Dead Ants

James Smith

1111-1111-1111-1014

6.99

Fun with Physics

Waine Youth

1111-1111-1111-1011

13.75

Holy Grounds

James Smith

1111-1111-1111-1008

3.55

Sphere

Michael Crichton

1111-1111-1111-1005

6.99

Jurassic Park

Michael Crichton

1111-1111-1111-1002

6.99

 

 

Step 4: Servlet Design

            Name your servlet BookClient.  Your servlet will have two functions: to order books and to display all the current orders.  To do this you will need to write both the doGet() and doPost() methods of the servlet.  Invoking the doGet() method of the servlet is done by calling the Servlet on your local host.

 

http://localhost/servlet/BookClient

 

doGet()

            When no data is being sent to the servlet or when data is sent as part of the URL (http://localhost/servlet/BookClient?displayOrders=true), the doGet() method of your servlet will be called and the web server returns the output contents that were prepared in the doGet() method.  When no data is sent, the page http://localhost/servlet/BookClient should display a simple <form> that allows a user to enter a title of a book and a quantity.  The html should look something like:

 

<html>

<body>

<form method='post' action=’http://localhost/servlet/BookClient’>

Title: <input name='title' size='60' maxlength='100'/><br/><br/>

Quantity: <input name='qty' size='10' maxlength='50'/><br/><br/>

<input type='submit' name='submit' value='Submit Order'/>

<form>

</body>

</html>

 

When the user enters a title of a book and a quantity (sample book titles are listed in Step 3), the servlet will call the doPost() method and allow you to gather the form data, form an Xml request, communicate with the three supplier servers, and interpret their responses.

 

You should also have a link on this page that allows the user to display all the orders (this is an administrative sample, so no user identification is necessary).  The link should lead to the address:

 

http://localhost/servlet/BookClient?displayOrders=true

 

When this link is clicked, the doGet() method is called. Check the result of request.getParameter(“displayOrders”) (which can possibly be null) to determine whether to display the form or the orders in the database. If the user decided to display all the orders in the database, do a query in your Orders table to retrieve the orders and return them in an html table.  You should also include a link that returns to the main page of your servlet (http://localhost/servlet/BookClient).

 

 

doPost()

            This method will handle processing an order. If the user decided to order a book, then you will have the title of a book and a quantity as form data.  You should implement the pseudocode listed in the assignment’s introduction, which is repeated here:

 

Receive the Original Book Request from the user

Create a standard Xml document containing the information in the request (include

title and quantity) and store it in a Standard_Request string

For each book supplier

Transform the Standard_Request string into a Supplier_Request string using XSLT

Send the Supplier_Request string to the supplier as an socket request

Receive a result from the supplier as Supplier_Result string

Transform the Supplier_Result string into a Standard_Result string using XSLT

Interpret the results from the Standard_Result

End For

 

 

Some Hints:

  1. The Supplier server code is provided as a guide for how to use the Apache Xml tools, how to receive socket data, how to do XSLT transformations, and some sample Xslt stylesheets.  You should try to use as much of this code as possible!  The transformation code is fairly complete, but you should be familiar with how it works.

 

The supplier server is really one application that simulates three different servers.  Thus, it works just like the servlet you are writing but does the opposite:  it converts O-Really and Prentice Hull requests into a standard format (Adisson-Wolly), and when the server creates a response, it converts the standard (Addisson-Wolly) into O-Really or Prentice Hull responses.  There are four stylesheets that the supplier server uses:

 

PHtoAWQuery.xsl

When the Prentice Hull server receives a query for a book, it converts the query into an Addison-Wolly request.

 

ORtoAWQuery.xsl

When the O-Really server receives a query for a book, it converts the query into an Addison-Wolly request.

 

AWtoORResponse.xsl

When the O-Really server finds a book, the standard response (Adisson-Wolly) is converted into an O-Really response.

 

AWtoPHResponse.xsl

When the Prentice Hull server finds a book, the standard response (Adisson-Wolly) is converted into an Prentice Hull response.

 

  1. You should first retrieve all of the supplier servers from the Server table.  This will allow you to loop through that information quickly.
  2. Look at the Java API to figure out how to send information using Sockets.  This is a very important step.  If you have trouble, the sequence of events should be:

Create a new Socket with the host URL and port number

Create a PrintStream that uses the Socket’s output stream

Information can be sent through the socket using this PrintStream

                        Be sure to flush the contents of the PrintStream to send data!                  

 

                        To receive from the Socket, get the Socket’s InputStream

                        You can use a BufferedReader and an InputStreamReader to read the result of a Socket

                       

It is VERY IMPORTANT that you only send ONE LINE through the socket!  You should remove all ‘\n’ and ‘\r’ characters from any string that is sent over a socket!  You may want to copy the RemoveCR() method in the Supplier Server code for this.

 

  1. Test your servlet with the server provided!
  2. VERY IMPORTANT: close all socket connections when you are done with them. Also close database connections. If you don’t, the server is likely to crash during peak times (i.e. the night before the assignment is due). Therefore part of your grade may depend on this.

 

Hand-In Procedure

 

You need to hand in all files through the course management system by December 18, 23:59pm. You need to include the following files: