// Path: core/src/main/java/io/confluent/rest/exceptions/RestTimeoutException.java
// public class RestTimeoutException extends RestException {
// 
//   public static final int DEFAULT_ERROR_CODE = Response.Status.REQUEST_TIMEOUT.getStatusCode();
// 
//   public RestTimeoutException(String message, int status, int errorCode) {
//     super(message, status, errorCode);
//   }
// 
//   public RestTimeoutException(String message, int status, int errorCode, Throwable cause) {
//     super(message, status, errorCode, cause);
//   }
// }


import java.lang.reflect.Type;
import java.util.concurrent.TimeoutException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import io.confluent.rest.exceptions.RestTimeoutException;
import javax.validation.ConstraintViolationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;

  @Override
  public Object readFrom(Class<Object> type,
                         Type genericType,
                         Annotation[] annotations,
                         MediaType mediaType,
                         MultivaluedMap<String, String> httpHeaders,
                         InputStream entityStream) throws IOException {
    try {
      return super.readFrom(type, genericType, annotations, mediaType, httpHeaders, entityStream);
    } catch (UnrecognizedPropertyException e) {
      throw ConstraintViolations.simpleException("Unrecognized field: " + e.getPropertyName());
    } catch (JsonMappingException e) {
      // This needs to handle 2 JSON parsing error cases. Normally you would expect to see a
      // JsonMappingException because the data couldn't be parsed, but it can also occur when the
      // raw JSON is valid and satisfies the validation constraint annotations, but an exception is
      // thrown by the entity during construction. In the former case, we want to return a 400
      // (Bad Request), in the latter a 422 (Unprocessable Entity) with a useful error message. We
      // don't want to expose just any exception message via the API, so this code specifically
      // detects ConstraintViolationExceptions that were thrown *after* the normal validation
      // checks, i.e. when the entity Java object was being constructed.
      Throwable cause = e.getCause();
      if (cause instanceof ConstraintViolationException) {
        throw (ConstraintViolationException) cause;
      }
      throw e;
    } catch (IOException e) {
      Throwable cause = e.getCause();
      if (cause instanceof TimeoutException) {
        throw new RestTimeoutException("Timeout while reading from inputStream",
// Path: core/src/main/java/io/confluent/rest/exceptions/RestTimeoutException.java
// public class RestTimeoutException extends RestException {
// 
//   public static final int DEFAULT_ERROR_CODE = Response.Status.REQUEST_TIMEOUT.getStatusCode();
// 
//   public RestTimeoutException(String message, int status, int errorCode) {
//     super(message, status, errorCode);
//   }
// 
//   public RestTimeoutException(String message, int status, int errorCode, Throwable cause) {
//     super(message, status, errorCode, cause);
//   }
// }


// Path: core/src/main/java/io/confluent/rest/validation/JacksonMessageBodyProvider.java
import java.lang.reflect.Type;
import java.util.concurrent.TimeoutException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import io.confluent.rest.exceptions.RestTimeoutException;
import javax.validation.ConstraintViolationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;


  @Override
  public Object readFrom(Class<Object> type,
                         Type genericType,
                         Annotation[] annotations,
                         MediaType mediaType,
                         MultivaluedMap<String, String> httpHeaders,
                         InputStream entityStream) throws IOException {
    try {
      return super.readFrom(type, genericType, annotations, mediaType, httpHeaders, entityStream);
    } catch (UnrecognizedPropertyException e) {
      throw ConstraintViolations.simpleException("Unrecognized field: " + e.getPropertyName());
    } catch (JsonMappingException e) {
      // This needs to handle 2 JSON parsing error cases. Normally you would expect to see a
      // JsonMappingException because the data couldn't be parsed, but it can also occur when the
      // raw JSON is valid and satisfies the validation constraint annotations, but an exception is
      // thrown by the entity during construction. In the former case, we want to return a 400
      // (Bad Request), in the latter a 422 (Unprocessable Entity) with a useful error message. We
      // don't want to expose just any exception message via the API, so this code specifically
      // detects ConstraintViolationExceptions that were thrown *after* the normal validation
      // checks, i.e. when the entity Java object was being constructed.
      Throwable cause = e.getCause();
      if (cause instanceof ConstraintViolationException) {
        throw (ConstraintViolationException) cause;
      }
      throw e;
    } catch (IOException e) {
      Throwable cause = e.getCause();
      if (cause instanceof TimeoutException) {
        throw new RestTimeoutException("Timeout while reading from inputStream",
            RestTimeoutException.DEFAULT_ERROR_CODE,