Class HttpExceptionUtils

java.lang.Object
org.apache.hadoop.util.HttpExceptionUtils

@Private @Unstable public class HttpExceptionUtils extends Object
HTTP utility class to help propagate server side exception to the client over HTTP as a JSON payload.

It creates HTTP Servlet and JAX-RPC error responses including details of the exception that allows a client to recreate the remote exception.

It parses HTTP client connections and recreates the exception.

  • Field Details

  • Constructor Details

    • HttpExceptionUtils

      public HttpExceptionUtils()
  • Method Details

    • createServletExceptionResponse

      public static void createServletExceptionResponse(javax.servlet.http.HttpServletResponse response, int status, Throwable ex) throws IOException
      Creates a HTTP servlet response serializing the exception in it as JSON.
      Parameters:
      response - the servlet response
      status - the error code to set in the response
      ex - the exception to serialize in the response
      Throws:
      IOException - thrown if there was an error while creating the response
    • createJerseyExceptionResponse

      public static javax.ws.rs.core.Response createJerseyExceptionResponse(javax.ws.rs.core.Response.Status status, Throwable ex)
      Creates a HTTP JAX-RPC response serializing the exception in it as JSON.
      Parameters:
      status - the error code to set in the response
      ex - the exception to serialize in the response
      Returns:
      the JAX-RPC response with the set error and JSON encoded exception
    • validateResponse

      public static void validateResponse(HttpURLConnection conn, int expectedStatus) throws IOException
      Validates the status of an HttpURLConnection against an expected HTTP status code. If the current status code is not the expected one it throws an exception with a detail message using Server side error messages if available.

      NOTE: this method will throw the deserialized exception even if not declared in the throws of the method signature.

      Parameters:
      conn - the HttpURLConnection.
      expectedStatus - the expected HTTP status code.
      Throws:
      IOException - thrown if the current status code does not match the expected one.