Java Code Examples for org.apache.hadoop.http.HtmlQuoting

The following examples show how to use org.apache.hadoop.http.HtmlQuoting. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: incubator-atlas   Source File: ActiveServerFilter.java    License: Apache License 2.0 6 votes vote down vote up
private void handleRedirect(HttpServletRequest servletRequest, HttpServletResponse httpServletResponse,
                            String activeServerAddress) throws IOException {
    String requestURI = servletRequest.getRequestURI();
    String queryString = servletRequest.getQueryString();
    if ((queryString != null) && (!queryString.isEmpty())) {
        requestURI += "?" + queryString;
    }
    String quotedUri = HtmlQuoting.quoteHtmlChars(requestURI);
    if (quotedUri == null) {
        quotedUri = "/";
    }
    String redirectLocation = activeServerAddress + quotedUri;
    LOG.info("Not active. Redirecting to {}", redirectLocation);
    // A POST/PUT/DELETE require special handling by sending HTTP 307 instead of the regular 301/302.
    // Reference: http://stackoverflow.com/questions/2068418/whats-the-difference-between-a-302-and-a-307-redirect
    if (isUnsafeHttpMethod(servletRequest)) {
        httpServletResponse.setHeader(HttpHeaders.LOCATION, redirectLocation);
        httpServletResponse.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
    } else {
        httpServletResponse.sendRedirect(redirectLocation);
    }
}
 
Example 2
Source Project: hadoop   Source File: RMWebAppFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void doFilter(HttpServletRequest request,
    HttpServletResponse response, FilterChain chain) throws IOException,
    ServletException {
  response.setCharacterEncoding("UTF-8");
  String uri = HtmlQuoting.quoteHtmlChars(request.getRequestURI());
  String queryString = request.getQueryString();

  if (uri == null) {
    uri = "/";
  }
  if (queryString != null) {
    uri = uri + "?" + queryString;
  }
  RMWebApp rmWebApp = injector.getInstance(RMWebApp.class);
  rmWebApp.checkIfStandbyRM();
  if (rmWebApp.isStandby()
      && shouldRedirect(rmWebApp, uri)) {
    String redirectPath = rmWebApp.getRedirectPath() + uri;

    if (redirectPath != null && !redirectPath.isEmpty()) {
      String redirectMsg =
          "This is standby RM. The redirect url is: " + redirectPath;
      PrintWriter out = response.getWriter();
      out.println(redirectMsg);
      response.setHeader("Location", redirectPath);
      response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
      return;
    }
  }

  super.doFilter(request, response, chain);

}
 
Example 3
Source Project: big-c   Source File: RMWebAppFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void doFilter(HttpServletRequest request,
    HttpServletResponse response, FilterChain chain) throws IOException,
    ServletException {
  response.setCharacterEncoding("UTF-8");
  String uri = HtmlQuoting.quoteHtmlChars(request.getRequestURI());

  if (uri == null) {
    uri = "/";
  }
  RMWebApp rmWebApp = injector.getInstance(RMWebApp.class);
  rmWebApp.checkIfStandbyRM();
  if (rmWebApp.isStandby()
      && shouldRedirect(rmWebApp, uri)) {
    String redirectPath = rmWebApp.getRedirectPath() + uri;

    if (redirectPath != null && !redirectPath.isEmpty()) {
      String redirectMsg =
          "This is standby RM. The redirect url is: " + redirectPath;
      PrintWriter out = response.getWriter();
      out.println(redirectMsg);
      response.setHeader("Location", redirectPath);
      response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
      return;
    }
  }

  super.doFilter(request, response, chain);

}
 
Example 4
Source Project: ranger   Source File: KMSAuthenticationFilter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void sendError(int sc, String msg) throws IOException {
  statusCode = sc;
  this.msg = msg;
  super.sendError(sc, HtmlQuoting.quoteHtmlChars(msg));
}