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 import org.apache.hadoop.hbase.client.HBaseAdmin;
35
36 public class ExistsResource extends ResourceBase {
37
38 static CacheControl cacheControl;
39 static {
40 cacheControl = new CacheControl();
41 cacheControl.setNoCache(true);
42 cacheControl.setNoTransform(false);
43 }
44
45 String tableName;
46
47
48
49
50
51
52 public ExistsResource(String table) throws IOException {
53 super();
54 this.tableName = table;
55 }
56
57 @GET
58 @Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
59 MIMETYPE_BINARY})
60 public Response get(final @Context UriInfo uriInfo) {
61 try {
62 HBaseAdmin admin = new HBaseAdmin(servlet.getConfiguration());
63 if (!admin.tableExists(tableName)) {
64 throw new WebApplicationException(Response.Status.NOT_FOUND);
65 }
66 } catch (IOException e) {
67 throw new WebApplicationException(Response.Status.SERVICE_UNAVAILABLE);
68 }
69 ResponseBuilder response = Response.ok();
70 response.cacheControl(cacheControl);
71 return response.build();
72 }
73 }