1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.rest;
22
23 import java.io.IOException;
24
25 import javax.ws.rs.GET;
26 import javax.ws.rs.Produces;
27 import javax.ws.rs.WebApplicationException;
28 import javax.ws.rs.core.CacheControl;
29 import javax.ws.rs.core.Context;
30 import javax.ws.rs.core.Response;
31 import javax.ws.rs.core.UriInfo;
32 import javax.ws.rs.core.Response.ResponseBuilder;
33
34 public class ExistsResource extends ResourceBase {
35
36 static CacheControl cacheControl;
37 static {
38 cacheControl = new CacheControl();
39 cacheControl.setNoCache(true);
40 cacheControl.setNoTransform(false);
41 }
42
43 TableResource tableResource;
44
45
46
47
48
49
50 public ExistsResource(TableResource tableResource) throws IOException {
51 super();
52 this.tableResource = tableResource;
53 }
54
55 @GET
56 @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
57 MIMETYPE_BINARY})
58 public Response get(final @Context UriInfo uriInfo) {
59 try {
60 if (!tableResource.exists()) {
61 throw new WebApplicationException(Response.Status.NOT_FOUND);
62 }
63 } catch (IOException e) {
64 throw new WebApplicationException(Response.Status.SERVICE_UNAVAILABLE);
65 }
66 ResponseBuilder response = Response.ok();
67 response.cacheControl(cacheControl);
68 return response.build();
69 }
70 }