示例#1
0
 @GET
 @javax.ws.rs.Path("/{index: \\d+}")
 @Produces(MediaType.APPLICATION_JSON)
 public Photo getPhoto(@PathParam("index") int index) throws IOException {
   int max = Photos.getInstance().getSize();
   if (index < 0 || max <= index) {
     throw new WebApplicationException(Response.noContent().build());
   }
   Photo photo = Photos.getInstance().getPhoto(index);
   if (photo == null) {
     throw new WebApplicationException(Response.noContent().build());
   }
   return photo;
 }
示例#2
0
 @GET
 @javax.ws.rs.Path("/search")
 @Produces(MediaType.APPLICATION_JSON)
 public List<Photo> search(@QueryParam("for") String searchString)
     throws IOException, ParseException {
   Photos photos = Photos.getInstance();
   return photos.search("\"" + searchString + "\"", 32);
 }
示例#3
0
 @GET
 @javax.ws.rs.Path("/random")
 @Produces(MediaType.TEXT_PLAIN)
 public String getRandom(@Context HttpServletRequest request) throws IOException {
   Photos photos = Photos.getInstance();
   List<Photo> singleton = photos.getRandomSlice(0, 1);
   return photos.toURL(request, singleton.get(0).getImage());
 }
示例#4
0
 @GET
 @javax.ws.rs.Path("/random/page/{page}/count/{count}")
 @Produces(MediaType.APPLICATION_JSON)
 public List<Photo> getRandomSlice(
     @PathParam("page") Integer page, @PathParam("count") Integer count) throws IOException {
   Photos photos = Photos.getInstance();
   return photos.getRandomSlice(page, count);
 }
示例#5
0
 @GET
 @javax.ws.rs.Path("/")
 @Produces(MediaType.APPLICATION_JSON)
 public List<Photo> getPhotos() throws IOException {
   return Photos.getInstance().getPhotos();
 }