@Test public void objectOkResponse() throws Exception { class Obj { private final int mStatus; private final String mMessage; Obj(int status, String message) { mStatus = status; mMessage = message; } public int getStatus() { return mStatus; } public String getMessage() { return mMessage; } } int status = 200; String message = "OK"; final Obj object = new Obj(status, message); Response response = RestUtils.call(new RestUtils.RestCallable<Obj>() { @Override public Obj call() throws Exception { return object; } }, ServerConfiguration.global()); Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); Obj obj = (Obj) response.getEntity(); Assert.assertEquals(status, obj.getStatus()); Assert.assertEquals(message, obj.getMessage()); }
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);  }