Michael Cochez

Assistant Professor at Vrije Universiteit Amsterdam

Web Service Clients


To know basics of consuming a web service using JAX-WS and learn the basic use of Servlets.


You can also read some basic information about Java Servlets, but most things should become clear while working on the second part of the task and studying the example.


This assignment contains a programming part and several reflective questions.

In the task you are required to make a simple secretary application which will communicate with web services using the WSDL/SOAP standards.

The WSDL files of the services are located at http://ub1.ad.jyu.fi/teacher?wsdl and http://ub1.ad.jyu.fi/courses?wsdl. You can open these addresses with your browser to take a look at them. Each WSDL file defines only one service. In a more realistic setting there would be multiple services per WSDL descriptor.

The first teacher service defines a service from which you can search for people in the registry. Currently the data in the database is as follows (exactly this data):

ID         First name         Surname     Email    
id1 John Doe jd@jd.com
id2 Peter Caine pc@pc.com
id3 Mary Smith ms@ms.com

The method in the course service defines a way of creating a new course in the system. It returns the ID of the created course. Your task is to make a Java application which is able to communicate with both services.

First application

Your first application must work from the command line and use System.in for input. (This must be a maven project) First, you need to use the wsimport tools to create helper classes which will interact with the published web services. Create the helper classes in the package fi.jyu.it.ties456.week38.services.teacher and fi.jyu.it.ties456.week38.services.course (see -p option of wsimport) It is the easiest to keep the generated classes in your project. (use -keep and -Xnocompile). If you forget to generate the classes directly in the package (using -p), it is not possible to just change the package name at the top of the code file. You will have to regenerate the files.

Then you can write the application in the class fi.jyu.it.ties456.week38.Main, which needs to have a main method. In the application menu there must be three options : “quit”, “search” and “create”.

  • “quit” quits the application.
  • “search” asks for a search string, performs the search method on the teachers registry and prints the results. Then the application starts over asking the option from the user.
  • “create” asks all needed input parameters (course name, teacher id (which should to be from the teacher search), number of credits and a short description). Then the course registration method on the courses web service is called and the application prints the returned course ID. Then the application starts over asking the option from the user.

Do not spend to much time on things like input validation, beautiful design, etc. However, it would be good to have one class containing two methods. One for each action.

Second application

Once this task is done, you will have to make a second application. This will be is an API with the same functionality. This web application should be created using Java Servlets. Each Servlet is responsible for handling one of the following requests:

path method query parameters response failures
/searchTeacher GET queryString respnse code 200 and json containing the persons’ information response code 404 and json containing an error message
/createCourse POST none, data should be sent in the POST body code 302 or 303 (See https://en.wikipedia.org/wiki/Post/Redirect/Get) and redirect to /courseDetails?courseID=theID response code 404 and a human readbale error message
/courseDetails GET courseID always fails response code 501 and a message telling that this is not implemented

You can use the following steps to setup this project:

  1. Create a standard maven project (maven-archetype-quickstart)
  2. Add dependencies as show in this example
    • make sure that you also add a dependency on the project you created for the first application. This way you can reuse the pieces.
  3. Create your Servlets. A servlet is a normal Java class which extends from the javax.servlet.http.HttpServlet class.
    • In the class you should override the doPost or doGet method depending on the type of requests this Servlet needs to answer to.
    • In the method, you have to call methods on the request and response objects to get the query parameters, set status codes and write the response itself.
    • A simple example
  4. To run your servlets, make a class similar to this one

The following reflective questions must be answered by each group and the answers must be placed in the readme.md file in the repository.

  • Most REST services do not use WSDL and SOAP. What could be reasons for this?
  • SOAP and WSDL use XML, would it be better if they would use something more modern like JSON?
  • How did you handle errors and how should it be done? Imagine that your application is running on a production server.

Returning the task###

The finished project(s) must be uploaded to the git repository which will be made by the teacher. The repository should contain a short readme.md file which should be formatted using markdown. Also add the answers to the questions to the readme file.


  1. Use Eclipse IDE for Java EE Developers from http://www.eclipse.org/downloads/.
  2. Make first the command line app and then the website stuff.
  3. The services will not run anymore after 30 September 2015.
  4. Use tools available on the Internet (e.g. WSDL testers, validators, visualizers etc.).
  5. To get some result from the teachers search service, use search strings that are substrings of strings stored in the database (e.g. “Jo”, “Cai”, “ary”)
  6. Strictly speaking, a Servlet is anything which implements the javax.servlet.Servlet interface. However, in practice you will almost always use HttpServlets.
  7. If you are familiar with Servlets, you can also work with other web containers (Glassfish, Tomcat, …) and use web.xml. However, you have to make sure that all group members understand what is happening.