View Javadoc

1   package com.atlassian.plugins.rest.sample.expansion.resource;
2   
3   import javax.ws.rs.*;
4   import javax.ws.rs.core.Context;
5   import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
6   import static javax.ws.rs.core.MediaType.APPLICATION_XML;
7   import javax.ws.rs.core.Response;
8   import javax.ws.rs.core.UriBuilder;
9   import javax.ws.rs.core.UriInfo;
10  
11  /**
12   * A resource used to show details of a player and optionally an expandable player record element.  The
13   * {@link DataStore} will provide data of two player, one which has a player record and which doesn't.
14   *
15   * When viewing player with the record the client has the option to expand it.
16   */
17  @Path("/player")
18  @Consumes({APPLICATION_XML, APPLICATION_JSON})
19  @Produces({APPLICATION_XML, APPLICATION_JSON})
20  public class PlayerResource
21  {
22      @Context
23      private UriInfo uriInfo;
24  
25      @GET
26      @Path("/{id}")
27      public Response getPlayer(@PathParam("id") Integer id) throws Exception
28      {
29          return Response.ok(DataStore.getInstance().getPlayer(id, getPlayerUriBuilder(uriInfo))).build();
30      }
31  
32      static UriBuilder getPlayerUriBuilder(UriInfo uriInfo)
33      {
34          return uriInfo.getBaseUriBuilder().path("player").path("{id}");
35      }
36  }
37