Department of Computing Science Umeå University

Assignment 4 - Web Services

Due: 2008-08-22, 10:00

The assignment shall be solved individually.

The purpose of this assignment is to introduce the student to Web Services and Service-Oriented Architectures. The assignment demonstrates how these techniques can be used to construct scalable data and logic solutions in web environments, and also addresses data storage and XML Schema-based validation techniques.

In this assignment, you will construct a Web Service that provides a distributed data storage service for web system back-ends. More specifically, the Web Service will provide a distributed interface for the shopping cart history database of assignment 2. The Web Service WSDL interface is to be constructed by the student and contain a the following functionality:

  • a method for storing a shopping cart (e.g., user id + cart id + sequence of product ids)
  • a method for retrieving all shopping carts available in the database for a specific user
  • a method for retrieving a specific shopping cart (identified by a cart id)
Note that shopping carts are stored on a user by user basis, i.e., the carts stored in the database are tagged with a user (customer) id.

In the service core, a JDBC database accessor will be used to access a database, and the service will provide a distributed interface to this database. This is common way to integrate systems. As the service back-end is abstracted by the service interface, it could later be changed to integrate with a third party order system, or allow the order system to inspect the database directly for order processing.

As a front-end for the service, the student's solution from assignment 2/3 will be used (using the same regulations as specified in assignment 3). The shopping cart interface will be extended to include functionality for storing the content of a shopping cart in the database, and providing an interface for inspecting the shopping cart history stored in the database.

Laboration environment

Web Service

Download assignment4.zip and unpack it in your laboration environment. NOTE: it is important that you place the assignment4 directory at the same level as your username directory. Your 5dv093/ directory should contain the following directories after you unpack assignment4.zip:

  • apache-ant-1.7.0/
  • apache-tomcat-6.0.16/
  • assignment4/
  • username/

The assignment environment supplement (assignment4/) contains the following files

build.xml                                                                              <- Ant build file
call-linux.sh                                                                          <- service call script for linux
call-mac.sh                                                                            <-         - " -       for mac
call-windows.bat                                                                       <-         - " -       for windows
dist/
     assignment4.aar                                                                   <- service archive (generated by ant)
genstubs-linux.sh                                                                      <- service stub class generator script for linux
genstubs-mac.sh                                                                        <-              - " -                  for mac
genstubs-windows.bat                                                                   <-              - " -                  for windows
src/                                                                                   <- source directory
    se/
       umu/
           cs/
              www/
                  kurser/
                         _5dv093/
                                 ws/
                                    assignment4/                                       <- service code directory
                                                Assignment4MessageReceiverInOut.java   <- service skeleton (fully generated by the genstubs-scripts)
                                                Assignment4Skeleton.java               <- service implementation (partially generated by the genstubs-scripts)
                                                Client.java                            <- service client class (partially provided)
wsdl/                                                                                  <- WSDL file directory
     assignment4.wsdl                                                                  <- WSDL service interface definition (partially provided)

To create a functional web service, follow the following steps (the files to modify have been marked with bold text above):

  1. implement the WSDL description
  2. generate Java service stubs from the WSDL using the generate-scripts
  3. implement the service implementation
  4. implement a simple service client and test your service

WARNING: The genstubs-scripts will not overwrite any existing Java stubs or resource files, to generate new versions of your stubs (Assignment4MessageReceiverInOut.java and Assignment4Skeleton.java) and your resource files (resources/assignment4.wsdl and resources/services.xml) after you have updated your WSDL, make sure to save your work in these files in backup files and delete them.

To compile your service, user the ant command from your assignment4 directory. This will upon successful compilation generate a service archive (AAR file) in the dist/ directory.

NOTE: To develop a web-based client interface to your service, you need to update your environment to recognize the Axiom class libraries for your web service client. The easiest way of doing this is to copy the Axiom JAR files to your web application lib directory:

  cp ../apache-tomcat-6.0.16/webapps/axis2/WEB-INF/lib/*.jar web/WEB-INF/lib/              <- linux and mac
  copy ../apache-tomcat-6.0.16/webapps/axis2/WEB-INF/lib/*.jar web/WEB-INF/lib/            <- windows

To deploy your web service, copy the service AAR to the Axis2 service directory using one of the following commands and restart your container.

  cp dist/assignment4.aar ../apache-tomcat-6.0.16/webapps/axis2/WEB-INF/services/          <- linux and mac
  copy dist/assignment4.aar ../apache-tomcat-6.0.16/webapps/axis2/WEB-INF/services/        <- windows
You can check if Axis2 recognizes your web service at http://localhost:8080/axis2/services/listServices.
Once you have a functional web service, tie your web service into your web solution by transfering your service client code into suitable JSP pages.

NOTE: If you are working on another computer than localhost:8080, remember to update this address in your WSDL service bindings to reflect this (simply replace localhost:8080 with your host:port specification).

Service back-end

Download carts.jar and place it in your web service library directory. This JAR-file contains a data access layer for a three-layer web application architecture. The system is provided in a Java package called carts that contains the following classes:

carts.Id                                 <- a UUID wrapper class
carts.Cart                               <- a cart representation
carts.CartAccessor                       <- an accessor interface for the carts database
carts.CartAccessorSimulator              <- a simulated implementation of the accessor
carts.CartAccessorSimulator.Factory      <- a factory class for the simulator

The carts in this system contain four data fields: cart id, user id (i.e., the id of the web shop customer), a list of product ids, and a date. The Cart class contains get methods for each of them.

The accessor interface contains methods for querying the system for number of carts (for a specific user), retrieving a range of carts (for a specific user), retrieving a specific cart; and inserting, updating, and deleting carts.

Using the system: To use the system you simply instantiate an accessor:

  CartAccessor accessor = CartAccessorSimulator.Factory.getInstance();
and retrieve, store or search for the data you are interested in:
  int nrCarts = accessor.getNrCarts(userId);
  Cart[] carts = accessor.getCarts(userId,offset,limit);
  Cart cart = accessor.getCart(cartId);
  accessor.insertCart(cart);
  accessor.updateCart(cart);
  accessor.deleteCart(cartId);

See the environment page for details on installing and using the laboration environment.

Examination

Place a WAR-file containing your web solution and an AAR-file containing your web service in

~/edu/5dv093/assignment4/

Java source code should be placed in

~/edu/5dv093/assignment4/src/

You laboration report should be placed in

~/edu/5dv093/assignment4/report/

Due date

2008-08-22, 10:00

http://www.cs.umu.se/kurser/5DV093/SOM-08/assignments/4/index.html
Ansvarig för sidan: P-O Östberg
Senast ändrad 2008-09-01