/** * Calls the given {@link RestUtils.RestCallable} and handles any exceptions thrown. * * @param <T> the return type of the callable * @param callable the callable to call * @param alluxioConf Alluxio configuration * @param headers the headers * @return the response object */ public static <T> Response call(RestUtils.RestCallable<T> callable, AlluxioConfiguration alluxioConf, @Nullable Map<String, Object> headers) { try { // TODO(cc): reconsider how to enable authentication if (SecurityUtils.isSecurityEnabled(alluxioConf) && AuthenticatedClientUser.get(alluxioConf) == null) { AuthenticatedClientUser.set(LoginUser.get(alluxioConf).getName()); } } catch (IOException e) { LOG.warn("Failed to set AuthenticatedClientUser in REST service handler: {}", e.getMessage()); return createErrorResponse(e, alluxioConf); } try { return createResponse(callable.call(), alluxioConf, headers); } catch (Exception e) { LOG.warn("Unexpected error invoking rest endpoint: {}", e.getMessage()); return createErrorResponse(e, alluxioConf); } }
/** * Calls the given {@link RestUtils.RestCallable} and handles any exceptions thrown. * * @param <T> the return type of the callable * @param callable the callable to call * @return the response object */ public static <T> Response call(RestUtils.RestCallable<T> callable) { try { // TODO(cc): reconsider how to enable authentication if (SecurityUtils.isSecurityEnabled() && AuthenticatedClientUser.get() == null) { AuthenticatedClientUser.set(LoginUser.get().getName()); } } catch (IOException e) { LOG.warn("Failed to set AuthenticatedClientUser in REST service handler: {}", e.getMessage()); return createErrorResponse(e); } try { return createResponse(callable.call()); } catch (Exception e) { LOG.warn("Unexpected error invoking rest endpoint: {}", e.getMessage()); return createErrorResponse(e); } }