projects/positioning/backend/src/main/java/io/v/positioning/GpsLocationServlet.java
/**
     * Processes a POST request to save device's GPS location
     *
     * @param req  The servlet request that includes JSONObject with properties to be saved
     * @param resp The servlet response informing a user if the request was successful or not
     */
Processes a POST request to save device's GPS location
@param req  The servlet request that includes JSONObject with properties to be saved
@param resp The servlet response informing a user if the request was successful or not
Processes a POST request to save device ' s GPS location @param req The servlet request that includes JSONObject with properties to be saved @param resp The servlet response informing a user if the request was successful or not
@Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.setContentType("text/plain");
        BufferedReader br = req.getReader();
        try {
            JSONObject jo = new JSONObject(br.readLine());
            DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
            Entity entity = new Entity("gps");
            entity.setProperty("androidId", jo.get("androidId"));
            entity.setProperty("latitude", jo.get("latitude"));
            entity.setProperty("longitude", jo.get("longitude"));
            entity.setProperty("deviceTime", jo.get("deviceTime"));
            entity.setProperty("serverTime", System.currentTimeMillis());
            datastore.put(entity);
            resp.getWriter().println("New GPS location added.");
        } catch (Exception e) {
            resp.getWriter().println("Recording failed. " + e.getMessage());
        }
    }
@ Override public void doPost ( HttpServletRequest req , HttpServletResponse resp ) throws IOException { resp . setContentType ( "text/plain" ) ; BufferedReader br = req . getReader ( ) ; try { JSONObject jo = new JSONObject ( br . readLine ( ) ) ; DatastoreService datastore = DatastoreServiceFactory . getDatastoreService ( ) ; Entity entity = new Entity ( "gps" ) ; entity . setProperty ( "androidId" , jo . get ( "androidId" ) ) ; entity . setProperty ( "latitude" , jo . get ( "latitude" ) ) ; entity . setProperty ( "longitude" , jo . get ( "longitude" ) ) ; entity . setProperty ( "deviceTime" , jo . get ( "deviceTime" ) ) ; entity . setProperty ( "serverTime" , System . currentTimeMillis ( ) ) ; datastore . put ( entity ) ; resp . getWriter ( ) . println ( "New GPS location added." ) ; } catch ( Exception e ) { resp . getWriter ( ) . println ( "Recording failed. " + e . getMessage ( ) ) ; } }
Processes a POST request to save device's GPS location
 @param req  The servlet request that includes JSONObject with properties to be saved
 @param resp The servlet response informing a user if the request was successful or not
Processes a POST request to save device ' s GPS location @param req The servlet request that includes JSONObject with properties to be saved @param resp The servlet response informing a user if the request was successful or not