private <B, R> R executeRequest( RequestSpec requestSpec, PathParams pathParams, B requestBody, Class<R> responseType, int expectedStatus) { String url = String.format( ADMIN_URL_PREFIX + requestSpec.path(pathParams), scheme, host, port, urlPathPrefix); RequestBuilder requestBuilder = RequestBuilder.create(requestSpec.method().getName()).setUri(url); if (requestBody != null) { requestBuilder.setEntity(jsonStringEntity(Json.write(requestBody))); } String responseBodyString = safelyExecuteRequest(url, expectedStatus, requestBuilder.build()); return responseType == Void.class ? null : Json.read(responseBodyString, responseType); }
private String urlFor(Class<? extends AdminTask> taskClass) { RequestSpec requestSpec = adminRoutes.requestSpecForTask(taskClass); checkNotNull(requestSpec, "No admin task URL is registered for " + taskClass.getSimpleName()); return String.format(ADMIN_URL_PREFIX + requestSpec.path(), scheme, host, port, urlPathPrefix); }