View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.rest;
19  
20  import java.io.IOException;
21  
22  import javax.servlet.Filter;
23  import javax.servlet.FilterChain;
24  import javax.servlet.FilterConfig;
25  import javax.servlet.ServletException;
26  import javax.servlet.ServletRequest;
27  import javax.servlet.ServletResponse;
28  import javax.servlet.http.HttpServletRequest;
29  import javax.servlet.http.HttpServletResponse;
30  
31  import org.apache.commons.logging.Log;
32  import org.apache.commons.logging.LogFactory;
33  
34  public class DummyFilter implements Filter {
35    private Log LOG = LogFactory.getLog(getClass());
36  
37    @Override
38    public void destroy() {
39    }
40  
41    @Override
42    public void doFilter(ServletRequest paramServletRequest, ServletResponse paramServletResponse,
43        FilterChain paramFilterChain) throws IOException, ServletException {
44      if (paramServletRequest instanceof HttpServletRequest
45          && paramServletResponse instanceof HttpServletResponse) {
46        HttpServletRequest request = (HttpServletRequest) paramServletRequest;
47        HttpServletResponse response = (HttpServletResponse) paramServletResponse;
48  
49        String path = request.getRequestURI();
50        LOG.info(path);
51        if (path.indexOf("/status/cluster") >= 0) {
52          LOG.info("Blocking cluster status request");
53          response.sendError(HttpServletResponse.SC_NOT_FOUND, "Cluster status cannot be requested.");
54        } else {
55          paramFilterChain.doFilter(request, response);
56        }
57      }
58    }
59  
60    @Override
61    public void init(FilterConfig filterChain) throws ServletException {
62    }
63  
64  }