@Test public void stringOkResponse() throws Exception { final String message = "ok"; Response response = RestUtils.call(new RestUtils.RestCallable<String>() { @Override public String call() throws Exception { return message; } }, ServerConfiguration.global()); Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); ObjectMapper mapper = new ObjectMapper(); String jsonMessage = mapper.writeValueAsString(message); Assert.assertEquals(jsonMessage, response.getEntity()); }
public static <T> Response call(RestUtils.RestCallable<T> callable, AlluxioConfiguration alluxioConf, @Nullable Map<String, Object> headers) { try { if (SecurityUtils.isSecurityEnabled(alluxioConf) && AuthenticatedClientUser.get(alluxioConf) == null) { AuthenticatedClientUser.set(ServerUserState.global().getUser().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); } }
RestUtils { public static <T> Response call(RestUtils.RestCallable<T> callable, AlluxioConfiguration alluxioConf, @Nullable Map<String, Object> headers) { try { if (SecurityUtils.isSecurityEnabled(alluxioConf) && AuthenticatedClientUser.get(alluxioConf) == null) { AuthenticatedClientUser.set(ServerUserState.global().getUser().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); } } }
RestUtils { public static <T> Response call(RestUtils.RestCallable<T> callable, AlluxioConfiguration alluxioConf, @Nullable Map<String, Object> headers) { try { if (SecurityUtils.isSecurityEnabled(alluxioConf) && AuthenticatedClientUser.get(alluxioConf) == null) { AuthenticatedClientUser.set(ServerUserState.global().getUser().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); } } private  RestUtils(); }
RestUtils { public static <T> Response call(RestUtils.RestCallable<T> callable, AlluxioConfiguration alluxioConf, @Nullable Map<String, Object> headers) { try { if (SecurityUtils.isSecurityEnabled(alluxioConf) && AuthenticatedClientUser.get(alluxioConf) == null) { AuthenticatedClientUser.set(ServerUserState.global().getUser().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); } } private  RestUtils(); static Response call(RestUtils.RestCallable<T> callable,
      AlluxioConfiguration alluxioConf, @Nullable Map<String, Object> headers); static Response call(RestUtils.RestCallable<T> callable,
      AlluxioConfiguration alluxioConf); static Response.ResponseBuilder makeCORS(Response.ResponseBuilder responseBuilder,
      String returnMethod); static Response.ResponseBuilder makeCORS(Response.ResponseBuilder responseBuilder); }
RestUtils { public static <T> Response call(RestUtils.RestCallable<T> callable, AlluxioConfiguration alluxioConf, @Nullable Map<String, Object> headers) { try { if (SecurityUtils.isSecurityEnabled(alluxioConf) && AuthenticatedClientUser.get(alluxioConf) == null) { AuthenticatedClientUser.set(ServerUserState.global().getUser().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); } } private  RestUtils(); static Response call(RestUtils.RestCallable<T> callable,
      AlluxioConfiguration alluxioConf, @Nullable Map<String, Object> headers); static Response call(RestUtils.RestCallable<T> callable,
      AlluxioConfiguration alluxioConf); static Response.ResponseBuilder makeCORS(Response.ResponseBuilder responseBuilder,
      String returnMethod); static Response.ResponseBuilder makeCORS(Response.ResponseBuilder responseBuilder);  }