コード例 #1
0
ファイル: PlayerResource.java プロジェクト: szwork2013/music
  /**
   * Register a new player.
   *
   * @return Response
   */
  @POST
  @Path("register")
  public Response register() {
    if (!authenticate()) {
      throw new ForbiddenClientException();
    }

    // Create a new player
    PlayerDao playerDao = new PlayerDao();
    Player player = new Player();
    String id = playerDao.create(player);

    // Return the token
    return Response.ok().entity(Json.createObjectBuilder().add("token", id).build()).build();
  }
コード例 #2
0
ファイル: PlayerResource.java プロジェクト: szwork2013/music
  /**
   * Unregister a player.
   *
   * @return Response
   */
  @POST
  @Path("unregister")
  public Response unregister(@FormParam("token") String token) {
    if (!authenticate()) {
      throw new ForbiddenClientException();
    }

    ValidationUtil.validateRequired(token, "token");

    // Delete the player
    PlayerDao playerDao = new PlayerDao();
    Player player = playerDao.getById(token);
    if (player == null) {
      throw new ClientException("PlayerNotFound", "Player not found: " + token);
    }
    playerDao.delete(token);

    // Always return OK
    return Response.ok().entity(Json.createObjectBuilder().add("status", "ok").build()).build();
  }