Professional Documents
Culture Documents
Web Programming
Vincent Labatut
Galatasaray University
Lab Session 5
web services
The goal of this lab session is to implement both a web service (WS) allowing to remotely access our discography database, and a client using this service. The DB can take any form, but to make it simple we will keep on using the usual XML file. An incomplete Eclipse dynamic web project is provided with this document. It contains (src folder) a database package proposing a set of classes you will use to access the database. The Database class owns a static list of discs, built from the bd_1_4.xml file. Each disc is represented through a Record object, whose fields correspond to the data defined in the XML document.
1 Service creation
1.1 Bottom-up approach Exercise 1
The simplest way to create a service is the so-called bottom-up approach, consisting in using some existing code to automatically or semi-automatically generate the files needed to describe the WS (like, for instance, its WSDL description). After having imported the project in Eclipse, go in the tr.edu.gsu.kikencere.INF532 package and open the empty Service1SOAP class. Then, use the Database.list list in order to implement the following methods: getSize: o No input parameter; o Returns the total number of discs in the database. getImageURLFromId: o Takes the unique identifier (id) of a disc as an input; o Returns the URL of the disc sleeve image (under the form of a String). Note: depending on how you organize you project, you may have to adapt bd_1_4.xml path in the Database class.
Exercise 2
Create a WS with WTP from the Service1SOAP.java file, and test-it using the WSDL explorer (cf. the WS appendix). The limits of the bottom-up approach appear when one wants to pass a complex typed value as a parameter or result (like an object containing several values, for instance). In this case, it is necessary to use the so-called top-down approach, because the parameters structures must be preferably defined by the user.
Web Programming
web services
Exercise 4
Use WTP to generate the Java classes from your Service2.wsdl description (cf. the WS appendix). In src, go to the tr.edu.gsu.kikencere.INF532 package, edit the Service2SOAPImpl class and complete it so that it implements the desired functionality. You may notice WTP already generated some classes to represent the types defined in the XML schema and used in your WSDL description (TypeDisque, TypeInterprete, etc.). Of course, these classes are different from those provided to represent our database (package database). Consequently, the methods you have to program here mainly focus on data conversion.
Exercise 5
Using WTP WSDL explorer, test locally your WS.
2 Client creation
The WTP WSDL constitutes a basic form of WS client, but WTP also allows generating automatically the classes needed to implement a full Java client, from the description of the targeted WS.
Exercise 6
From the Service1.SOAP.wsdl file located in the WebContent\wsd folder, generate a draft client under the form of a new Eclipse project called TP05_NameFirstname_Client. In this new
Web Programming Computer Science Master [INF532] 2010/11 Lab Session 5 2/3
web services
project, go to the tr.edu.gsu.kikencere.INF532 package and create a main class called Launcher in order to host the project main function.
Exercise 7
Complete this main function so that it displays: The number of discs in our database; The sleeve URL for the disc whose id is 2.
Web Programming