org.apache.kafka.common.errors.AuthenticationException Java Examples

The following examples show how to use org.apache.kafka.common.errors.AuthenticationException. 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: KafkaExceptionMapper.java    From rest-utils with Apache License 2.0 6 votes vote down vote up
private Response handleException(final Throwable exception) {
  if (exception instanceof AuthenticationException) {
    return getResponse(exception, Status.UNAUTHORIZED,
        KAFKA_AUTHENTICATION_ERROR_CODE);
  } else if (exception instanceof AuthorizationException) {
    return getResponse(exception, Status.FORBIDDEN,
        KAFKA_AUTHORIZATION_ERROR_CODE);
  } else if (HANDLED.containsKey(exception.getClass())) {
    return getResponse(exception);
  } else if (exception instanceof RetriableException) {
    log.debug("Kafka retriable exception", exception);
    return getResponse(exception, Status.INTERNAL_SERVER_ERROR,
        KAFKA_RETRIABLE_ERROR_ERROR_CODE);
  } else if (exception instanceof KafkaException) {
    log.error("Kafka exception", exception);
    return getResponse(exception, Status.INTERNAL_SERVER_ERROR,
        KAFKA_ERROR_ERROR_CODE);
  } else if (exception instanceof InvalidFormatException) {
    return getResponse(exception, Status.BAD_REQUEST,
        KAFKA_BAD_REQUEST_ERROR_CODE);
  } else {
    log.error("Unhandled exception", exception);
    return super.toResponse(exception);
  }
}
 
Example #2
Source File: KafkaExceptionMapperTest.java    From rest-utils with Apache License 2.0 5 votes vote down vote up
@Test
public void testAuthenticationExceptions() {
  verifyMapperResponse(new AuthenticationException("some message"), Status.UNAUTHORIZED,
      KAFKA_AUTHENTICATION_ERROR_CODE);
  verifyMapperResponse(new SaslAuthenticationException("some message"), Status.UNAUTHORIZED,
      KAFKA_AUTHENTICATION_ERROR_CODE);
}