Package org.apache.hadoop.util
Class HttpExceptionUtils
java.lang.Object
org.apache.hadoop.util.HttpExceptionUtils
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic javax.ws.rs.core.ResponsecreateJerseyExceptionResponse(javax.ws.rs.core.Response.Status status, Throwable ex) Creates a HTTP JAX-RPC response serializing the exception in it as JSON.static voidcreateServletExceptionResponse(javax.servlet.http.HttpServletResponse response, int status, Throwable ex) Creates a HTTP servlet response serializing the exception in it as JSON.static voidvalidateResponse(HttpURLConnection conn, int expectedStatus) Validates the status of anHttpURLConnectionagainst an expected HTTP status code.
-
Field Details
-
ERROR_JSON
- See Also:
-
ERROR_EXCEPTION_JSON
- See Also:
-
ERROR_CLASSNAME_JSON
- See Also:
-
ERROR_MESSAGE_JSON
- See Also:
-
-
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 responsestatus- the error code to set in the responseex- 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 responseex- the exception to serialize in the response- Returns:
- the JAX-RPC response with the set error and JSON encoded exception
-
validateResponse
Validates the status of anHttpURLConnectionagainst 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
throwsof the method signature.- Parameters:
conn- theHttpURLConnection.expectedStatus- the expected HTTP status code.- Throws:
IOException- thrown if the current status code does not match the expected one.
-