001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.rest; 019 020import java.io.IOException; 021import org.apache.yetus.audience.InterfaceAudience; 022 023import org.apache.hbase.thirdparty.javax.ws.rs.GET; 024import org.apache.hbase.thirdparty.javax.ws.rs.Produces; 025import org.apache.hbase.thirdparty.javax.ws.rs.core.CacheControl; 026import org.apache.hbase.thirdparty.javax.ws.rs.core.Context; 027import org.apache.hbase.thirdparty.javax.ws.rs.core.Response; 028import org.apache.hbase.thirdparty.javax.ws.rs.core.Response.ResponseBuilder; 029import org.apache.hbase.thirdparty.javax.ws.rs.core.UriInfo; 030 031@InterfaceAudience.Private 032public class ExistsResource extends ResourceBase { 033 034 static CacheControl cacheControl; 035 static { 036 cacheControl = new CacheControl(); 037 cacheControl.setNoCache(true); 038 cacheControl.setNoTransform(false); 039 } 040 041 TableResource tableResource; 042 043 /** 044 * Constructor nn 045 */ 046 public ExistsResource(TableResource tableResource) throws IOException { 047 super(); 048 this.tableResource = tableResource; 049 } 050 051 @GET 052 @Produces({ MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF, 053 MIMETYPE_BINARY }) 054 public Response get(final @Context UriInfo uriInfo) { 055 try { 056 if (!tableResource.exists()) { 057 return Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT) 058 .entity("Not found" + CRLF).build(); 059 } 060 } catch (IOException e) { 061 return Response.status(Response.Status.SERVICE_UNAVAILABLE).type(MIMETYPE_TEXT) 062 .entity("Unavailable" + CRLF).build(); 063 } 064 ResponseBuilder response = Response.ok(); 065 response.cacheControl(cacheControl); 066 return response.build(); 067 } 068}