DhsDeployServersCommand extends DeployHubOtherServersCommand { @Override protected String adjustPayloadBeforeSavingResource(CommandContext context, File f, String payload) { final String[] originalIncludeProperties = context.getAppConfig().getIncludeProperties(); context.getAppConfig().setIncludeProperties("server-name", "error-handler", "url-rewriter"); try { return super.adjustPayloadBeforeSavingResource(context, f, payload); } finally { context.getAppConfig().setIncludeProperties(originalIncludeProperties); } }    }
@Test public void test() throws Exception { AppConfig appConfig = new AppConfig(); appConfig.setIncludeProperties("shape", "size"); CommandContext context = new CommandContext(appConfig, null, null); Server server = new Server(); server.setServerName("some-server"); server.setUrlRewriter("some-rewriter"); server.setErrorHandler("some-handler"); server.setPort(8123); server.setAuthentication("digestbasic"); final String payload = new DhsDeployServersCommand().adjustPayloadBeforeSavingResource(context, null, server.getJson()); JsonNode node = ObjectMapperFactory.getObjectMapper().readTree(payload); assertEquals("some-server", node.get("server-name").asText()); assertEquals("some-rewriter", node.get("url-rewriter").asText()); assertEquals("some-handler", node.get("error-handler").asText()); final String message = "Only server-name, url-rewriter, and error-handler should be retained so no other DHS settings can be overridden"; assertFalse(node.has("port"), message); assertFalse(node.has("authentication"), message); }