CSCI 470
Web Science
Spring 2015

Montana Tech
Computer Science & Software Engineering



GeoTrack servlet

You will be building a Java servlet that provides a web service that tracks the location of users who are roaming around with their mobile devices. Users can update the system with their current location. They can also query the system to find people within a given distance of their location.


Overview. Each user in the system is uniquely identified by a string ID (e.g. a MAC address or cell phone ID). Only the user themselves knows their unique ID, the rest of the world only sees a friendly name that users get to choose themselves. You are building a Java servlet that provides the following functions: Coordinate system. Mobile devices report their position in UTM coordinates. UTM coordinates consist of two float-point numbers, an easting and a northing. The easting specifies how many meters the device is to the east of a fixed grid reference location. Similarly the northing is how far the device is north of the grid reference. To calculate the distance between two positions in UTM coordinates, use the Pythagorean theorem.

Web service input. You are building a servlet that provides a RESTful web service. The following GET parameters are accepted by the web service: Web service output. The web service returns results in JSON format. Every response always contains a string field status. The status contains the string "OK" if the request was successful. If their was an error, the string contains a human-readable description of what went wrong (e.g. "ERROR: unable to parse distance as a floating-point value!"). Your servlet should be robust to bad requests and always return a well-formed JSON result with a status field.

The only command with an additional result field is the query command. This command returns a field near containing an array with 0 or more elements. Each element in the array contains information about a user within the queried radius. The fields returned in each element are: Here is an example result from a query request:
{
    "status": "OK",
    "near": [
        {
            "name": "carol",
            "northing": 50,
            "easting": 150,
            "distance": 70.710678,
            "timestamp": 1362722508
        },
        {
            "name": "bob",
            "northing": 150,
            "easting": 150,
            "distance": 70.710678,
            "timestamp": 1362722494
        }
    ]
}
Pruning data. Users may disappear from the network without deleting themselves from the tracker. You need to implement a pruning mechanism. If more than 1 minute has elapsed since a user's last update command, then you should delete that user from the tracker. This pruning should happen in a timely manner (i.e. queries should not show stale users more than a few second beyond the one-minute staleness limit).

Concurrency. Remember that only one instance of your servlet object will exist. This object may get called by multiple threads in parallel. This will almost certainly happen when I test your submission. Thus you should ensure that all access to non-thread safe variables is appropriately protected. You can test your program with the Apache benchmark utility ab with a concurrency > 1.

Example implementation. You can access my completed web service: http://104.236.117.243:8080/. You can experiment by directly typing in URLs with GET parameters to the servlet. There is also an HTML test client: http://104.236.117.243/GeoTrack.html. The HTML client uses a PHP proxy page to avoid the cross-origin restriction of the AJAX requests (due to the different port numbers of the servlet and web server). The file geotrack.zip contains the HTML and PHP page running my test client along with the scripts I used to compile and run my servlet.

Servlet details. You should build a Java servlet as an embedded Jetty application (see the Java Servlets lecture/links for example code). You will need to download a copy of Jetty v9. You can develop your servlet in Eclipse if you like or work on the command line.

Here is an example of how to compile and run an embedded Jetty server at the command line:
JETTY_LIB=/home/kvertanen
javac -cp ${JETTY_LIB}/jetty-all-9.2.8.jar:${JETTY_LIB}/servlet-api-3.1.jar *.java
java  -cp .:${JETTY_LIB}/servlet-api-3.1.jar:${JETTY_LIB}/jetty-all-9.2.8.jar GeoTrackServer
The above uses the handy all-in-one JAR file: jetty-all-9.2.8.jar

Your application should take a single command-line argument specifying the port to start the server on. You can assume any HTTP request to the server is for the servlet (i.e. the server does nothing but provide the web service).
Submission. I will be testing your program on the URL (and port) described in the header of your Moodle source code submission. It should be running on your VM and you should open up the port needed to access it in ufw. You also need to submit your source file(s) to the Moodle dropbox. The Moodle timestamp is the completion time for the assignment.

Page last updated: February 22, 2015