org.apache.hadoop.http.HtmlQuoting Java Examples

The following examples show how to use org.apache.hadoop.http.HtmlQuoting. 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 File: ActiveServerFilter.java    From incubator-atlas with 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 File: RMWebAppFilter.java    From hadoop with 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 File: RMWebAppFilter.java    From big-c with 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 File: KMSAuthenticationFilter.java    From ranger with 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));
}