@Override
 @POST
 @Path("/deviceid/")
 public String usernameFromDeviceId(@FormParam("deviceid") final String id) {
   Device device = findDeviceByDeviceId(id);
   if (device == null) {
     return "{\"deviceExists\":false}";
   }
   if (device.getUsername() == null || device.getUsername().length() == 0) {
     return "{\"deviceExists\":true,\"hasUsername\":false}";
   } else {
     return "{\"deviceExists\":true,\"hasUsername\":true,\"username\":\""
         + device.getUsername()
         + "\"}";
   }
 }
  @Override
  @POST
  @Path("/username/")
  public String devicesFromUsername(@FormParam("username") final String username) {
    List<Device> devices = findDevicesByUsername(username);
    String result = "{\"username\":\"" + username + "\",\"devices\":[";
    String sDevices = "";
    Iterator<Device> i = devices.iterator();

    while (i.hasNext()) {
      Device d = i.next();
      sDevices += "\"" + d.getDeviceId() + "\",";
    }

    if (sDevices.length() > 0) {
      sDevices = sDevices.substring(0, sDevices.length() - 1);
    }

    result += sDevices + "]}";
    return result;
  }