REST lab - write a client for the vlibtour-visit-emulation-system REST component
The vlibtour-visit-emulation-system component provides a REST API. It is specialized to emulate the microproject scenario: A group of tourists (Joe and Averell) are moving during a tour. Those tourists have selected ”The unusual Paris” tour instance made up of three POI (”Musée Grévin”, ”Pyramide du Louvres” and ”Les catacombes de Paris”). They are actually going from one POI to the next POI with different paths.
At the end of this lab, you will be able to:
- Use the emulation servers to move the users forward step by step and get their positions
- Display the positions of the users on an OpenStreetMap
Discover the emulation server
Discover the API of the emulation server when the server is started
You can discover the synthesis of the API of this component when the emulation server is started through its wadl.To obtain this image:
- Start the server (commands given from the root of the project)
cd vlibtour-visit-emulation-system/vlibtour-visit-emulation-server mvn clean install mvn exec:java@server
Discover the API of the emulation server with its javadoc
After the installation of the module through maven, you can discover the produced java documentation in a navigator.
Study carefully this API.
Your objective is to know how you can move one user step by step from the first POI to the last POI.
Test the emulation server
- Through a navigator or a REST client (e.g. Postman)
- A simple test client that gets the first position of the user Joe.
- Junit tests, that verify systematically all the methods of the server.
With Postman or a navigator
With the test client
With the JUnit tests
- Choose a class in src/test/java
- With a Rigt click choose Run as ... Junit test
Write a proxy on the client side
The proxy on the client implements all the methods provided by the REST server. In those methods, the proxy delegates to the REST server (send a REST request to the server).
In our case the picture is :
The proxy allows to simplify the code on the client point of view. We call the service as if it was a call to a local object. You simply has to write
Write the constructor
Write the four methods that access to the 4 methods defined in the emulator REST API
Test the proxy
Move one user from the first POI to the last POI
Use the proxy in the tourist application to visualize the user tour on the map
For this step, we will work in the vlibtour-scenario module and we will complete the class VlibTourVisitTouristApplication (NB this class is provided, it displays a map of Paris, prints the three POIs, you have to modify the class, to see the user (the user name is given in argument of the execution, Joe with mvn exec:java@touristapplijoe or Avrel with mvn exec:java@touristappliavrel) moving on the map).
Understand the map demo
Modify the constructor of
Modify the tourist application
- At the beginning of the main, initialize the client variable
by creating an instance of VlibTourVisitTouristApplication, the parameters of the constructor are the following:
- The tour Id (it may be modified when you will populate the tours in the database) for the moment you can write "The unusual Paris"
- The group Id, for the moment just write Optional.empty()
- The user Id, the user Id is provided as the first argument of the command line, it is copied in the userId variable at the beginning of the main
- Then modify the while loop get the position of the user through the call the proxy methods, and modify the position of the user on the map.
Test the tourist application
$Date: 2019-09-09 00:31:57 +0200 (lun. 09 sept. 2019) $