REST lab - Use vlibtour-visit-emulation-server as a REST component and move the users on the map
The vlibtour-visit-emulation-system module is able to emulate the move of group of users during a visit. A group of tourists (Daltons, named Joe and Averell) are moving during a tour . Those tourists have selected ”BigParisTour” 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 server as a REST server.
- Use the emulation servers to move the users forward step by step and get their positions
- Finally display the positions of the users on an OpenStreetMap
Discover the emulation 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.
Make the emulation server available as a REST server
The class vlibtour_visit_emulation_server contains a main method that creates a graph of positions and starts a http Grizzly server.
- The server URI
- The name of the daltons (group of tourists which positions are emulated by the server).
- Some positions in Paris (including POIs positions of the ParisBigTour)
Modify the class vlibtour_visit_emulation_server (look for all the TODO inside the code)
- Add all the annotations necessary to make the service available through REST requests
- Define the paths (class, methods and parameters)
- Declare the representation format of the produced data (Json)
Discover the API of the emulation server when the server is started
You can discover the synthesis of the API 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 csc-mw-project/vlibtour-microservices/vlibtour-visit-emulation-system/vlibtour-visit-emulation-server mvn clean install start_visit_emulation_server.sh Dalton ParisBigTour
- Look at the server interface through the wadl page http://localhost:8888/VisitEmulation/application.wadl
Verfify and be aware of:
- the path of the class ressource
- the names of the four available methods
- the names of their input parameters
- the representation type for the responses you should have this in the wadl for each method : <method id="getCurrentPosition" name="GET"> ... <response> <representation mediaType="application/json"/> </response> </method>
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 the JUnit tests
A test class is provided VLibTourVisitEmulationServerIT.
When your methods are ready, in the test class, you have to remove the lines
@Disabled // FIXMEto test effectively the methods.
To run it
./run_integration_tests.shor
mvn failsafe:integration-test failsafe:verify ------------------------------------------------------- T E S T S ------------------------------------------------------- [INFO] Running vlibtour.vlibtour_visit_emulation_server.VLibTourVisitEmulationServerIT oct. 04, 2024 9:23:48 AM org.glassfish.grizzly.http.server.NetworkListener start INFOS: Started listener bound to [localhost:8888] oct. 04, 2024 9:23:48 AM org.glassfish.grizzly.http.server.HttpServer start INFOS: [HttpServer] Started. [INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.521 s -- in vlibtour.vlibtour_visit_emulation_server.VLibTourVisitEmulationServerIT [INFO] [INFO] Results: [INFO] [INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] [INFO] --- maven-failsafe-plugin:3.5.0:verify (default-cli) @ vlibtour-visit-emulation-server --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSWith Postman or a navigator
When your unitary tests work perfectly, you can test the server with a REST client !
For example
Write a proxy on the client side
Learn more on what is a proxy

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.
With the proxy
With the use of a proxy, the service will be called as if it was a call to a local object. The developer simply has to write
Without the proxy
Instead of
Find the proxy class
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
Read carefully the subject of the microproject, to understand the methods available in the emulation server. You can also look at the code javadoc of the class vlibtour.vlibtour_visit_emulation_server
You can also take a look at the figure on the right.
With this knowledge build an algorithm to move the user from its first position to the last POI. Add a test method to test your algorithm. At the end of your test Joe should arrive on position "Les catacombes".

Use the proxy in the tourist application to visualize the user tour on the map
For this step, we will work in the vlibtour-tourist-application module and we will complete the class VLibTourVisitTouristApplication in the package vlibtour.vlibtour_tourist_application
NB this class is provided, it displays a map of Paris.
To start the tourist application, go to the root of the csc-mw-project andYou have to modify the class, to see the user moving on the map till "Les catacombes". You will have to work on the TODOs that are in the main method.
Modify the tourist application (the main method)
-
TODO TOUR
- You can get the POIs through the previously created database
- Or you can copy the following code
List
pois = new ArrayList(); POI poi1 = new POI(ExampleOfAVisitWithTwoTourists.POSITION4.getName(), ExampleOfAVisitWithTwoTourists.POSITION4.getDescription()); pois.add(poi1); POI poi2 = new POI(ExampleOfAVisitWithTwoTourists.POSITION19.getName(), ExampleOfAVisitWithTwoTourists.POSITION19.getDescription()); pois.add(poi2); POI poi3 = new POI(ExampleOfAVisitWithTwoTourists.POSITION47.getName(), ExampleOfAVisitWithTwoTourists.POSITION47.getDescription()); pois.add(poi3); Tour tour = new Tour(tourId, "description of " + tourId, pois);
- TODO VISITEMULATION instantiate the visit emulation proxy
- TODO VISITEMULATION get the first position of the tourist With the proxy
- TODO VISITEMULATION Show userId first position on the map
-
TODO GROUPCOMM and VISITEMULATION loop In this part you will have to include the algorithm you have found in the previous question. This loop will be completed in other labs concerning group communication.
- TODO VISITEMULATION Close the proxy
Test the tourist application
Your micro project is on the good track !
$Date: 2019-09-09 00:31:57 +0200 (lun. 09 sept. 2019) $