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