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.core.CacheControl;
28 import javax.ws.rs.core.Context;
29 import javax.ws.rs.core.Response;
30 import javax.ws.rs.core.UriInfo;
31 import javax.ws.rs.core.Response.ResponseBuilder;
32
33 public class ExistsResource extends ResourceBase {
34
35 static CacheControl cacheControl;
36 static {
37 cacheControl = new CacheControl();
38 cacheControl.setNoCache(true);
39 cacheControl.setNoTransform(false);
40 }
41
42 TableResource tableResource;
43
44
45
46
47
48
49 public ExistsResource(TableResource tableResource) throws IOException {
50 super();
51 this.tableResource = tableResource;
52 }
53
54 @GET
55 @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
56 MIMETYPE_PROTOBUF_IETF, MIMETYPE_BINARY})
57 public Response get(final @Context UriInfo uriInfo) {
58 try {
59 if (!tableResource.exists()) {
60 return Response.status(Response.Status.NOT_FOUND)
61 .type(MIMETYPE_TEXT).entity("Not found" + CRLF)
62 .build();
63 }
64 } catch (IOException e) {
65 return Response.status(Response.Status.SERVICE_UNAVAILABLE)
66 .type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
67 .build();
68 }
69 ResponseBuilder response = Response.ok();
70 response.cacheControl(cacheControl);
71 return response.build();
72 }
73 }