@GET @Path("/location/{deviceId}") /* * @PreAuthorize( "hasRole('mobileAppUser')") */ @Produces(MediaType.APPLICATION_JSON) public Response getClientsByMAC(@PathParam("deviceId") String deviceId) { MDC.put(MDCKeys.DEVICE_ID, deviceId); MobileAppStats.getInstance().incrementLocationRequestsCount(); LOGGER.trace("Request to retrieve client current location for device ID '{}'", deviceId); WirelessClient macClientLocation = mobileServerCacheService.getWirelessClientByUniqueID(deviceId); if (macClientLocation == null) { // Forbidden better than File Not Found - it doesn't leak // information LOGGER.trace("Unable to determine client MAC address from device ID '{}'", deviceId); MDC.remove(MDCKeys.DEVICE_ID); return Response.status(Response.Status.UNAUTHORIZED).build(); } JSONObject clientObject = new JSONObject(); try { clientObject.accumulate("deviceId", macClientLocation.getUniqueID()); clientObject.accumulate( "lastLocationUpdateTime", macClientLocation.getLastLocationUpdateTime()); clientObject.accumulate("venueId", macClientLocation.getVenueUdId()); clientObject.accumulate("floorId", macClientLocation.getFloorId()); try { if (!macClientLocation.getZoneId().isEmpty()) { clientObject.accumulate("zoneId", macClientLocation.getZoneId()); clientObject.accumulate("zoneName", macClientLocation.getZoneName()); clientObject.accumulate("zonePoints", macClientLocation.getZonePoints()); } } catch (Exception ex) { LOGGER.error( "Error during zone object creation for device ID '{}'", deviceId, ex.getLocalizedMessage()); } JSONObject locationObject = new JSONObject(); locationObject.accumulate("x", macClientLocation.getX()); locationObject.accumulate("y", macClientLocation.getY()); clientObject.accumulate("mapCoordinate", locationObject); JSONObject geoCoordinateObject = new JSONObject(); geoCoordinateObject.accumulate("latitude", macClientLocation.getLatitude()); geoCoordinateObject.accumulate("longitude", macClientLocation.getLongitude()); clientObject.accumulate("geoCoordinate", geoCoordinateObject); LOGGER.trace( "Completed setting current location for device ID '{}' with MAC Address '{}'", deviceId, macClientLocation.getMacAddress()); } catch (Exception e) { LOGGER.error( "Error during location object creation for device ID '{}'", deviceId, e.getLocalizedMessage()); } LOGGER.trace("Returning JSON object with device ID '{}' : {}", deviceId, clientObject); MDC.remove(MDCKeys.DEVICE_ID); if (macClientLocation.getFloorId() == null || macClientLocation.getFloorId().length() <= 0 || macClientLocation.getVenueUdId() == null || macClientLocation.getVenueUdId().length() <= 0) { return Response.status(Response.Status.NOT_FOUND).entity(clientObject).build(); } return Response.status(Response.Status.OK).entity(clientObject).build(); }