Source:
<code>private CompletionStage<RestResponse> updateTakeOffline(RestRequest request) { NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder(); <START> String cacheName = request.variables().get("cacheName"); String site = request.variables().get("site"); Cache<?, ?> cache = invocationHelper.getRestCacheManager().getCache(cacheName, request); XSiteAdminOperations xsiteAdmin = cache.getAdvancedCache().getComponentRegistry().getComponent(XSiteAdminOperations.class); <END> if (!xsiteAdmin.checkSite(site)) { return CompletableFuture.completedFuture(responseBuilder.status(NOT_FOUND.code()).build()); } byte[] byteContent = request.contents().rawContent(); if (byteContent == null || byteContent.length == 0) { return CompletableFuture.completedFuture(responseBuilder.status(HttpResponseStatus.BAD_REQUEST.code()).build()); } TakeOfflineConfiguration current = xsiteAdmin.getOfflineStatus(site).getTakeOffline(); TakeOffline takeOffline; try { takeOffline = invocationHelper.getMapper().readValue(byteContent, TakeOffline.class); } catch (IOException e) { return CompletableFuture.completedFuture(responseBuilder.status(HttpResponseStatus.INTERNAL_SERVER_ERROR).build()); } if (takeOffline.afterFailures == current.afterFailures() && takeOffline.minTimeToWait == current.minTimeToWait()) { return CompletableFuture.completedFuture(responseBuilder.status(HttpResponseStatus.NOT_MODIFIED.code()).build()); } return CompletableFuture.supplyAsync(() -> { String status = xsiteAdmin.amendTakeOffline(site, takeOffline.afterFailures, takeOffline.minTimeToWait); if (!status.equals(XSiteAdminOperations.SUCCESS)) { responseBuilder.status(HttpResponseStatus.INTERNAL_SERVER_ERROR.code()).entity(site); } return responseBuilder.build(); }, invocationHelper.getExecutor()); }</code><technical_language>nitpick: extract a private method. duplicated everywhere. String cacheName = request.variables().get("cacheName"); Cache<?, ?> cache = invocationHelper.getRestCacheManager().getCache(cacheName, request); return cache.getAdvancedCache().getComponentRegistry().getComponent(XSiteAdminOperations.class);</technical_language>

Target:
private CompletionStage<RestResponse> updateTakeOffline(RestRequest request) { NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder(); String site = request.variables().get("site"); XSiteAdminOperations xsiteAdmin = getxsiteAdmin(request); if (!xsiteAdmin.checkSite(site)) { return CompletableFuture.completedFuture(responseBuilder.status(NOT_FOUND.code()).build()); } byte[] byteContent = request.contents().rawContent(); if (byteContent == null || byteContent.length == 0) { return CompletableFuture.completedFuture(responseBuilder.status(HttpResponseStatus.BAD_REQUEST.code()).build()); } TakeOfflineConfiguration current = xsiteAdmin.getOfflineStatus(site).getTakeOffline(); TakeOffline takeOffline; try { takeOffline = invocationHelper.getMapper().readValue(byteContent, TakeOffline.class); } catch (IOException e) { return CompletableFuture.completedFuture(responseBuilder.status(HttpResponseStatus.BAD_REQUEST).build()); } if (takeOffline.afterFailures == current.afterFailures() && takeOffline.minTimeToWait == current.minTimeToWait()) { return CompletableFuture.completedFuture(responseBuilder.status(HttpResponseStatus.NOT_MODIFIED.code()).build()); } return CompletableFuture.supplyAsync(() -> { String status = xsiteAdmin.amendTakeOffline(site, takeOffline.afterFailures, takeOffline.minTimeToWait); if (!status.equals(XSiteAdminOperations.SUCCESS)) { responseBuilder.status(HttpResponseStatus.INTERNAL_SERVER_ERROR.code()).entity(site); } return responseBuilder.build(); }, invocationHelper.getExecutor()); }