From c76d6c7496319b400584f7b61ae65be18142609a Mon Sep 17 00:00:00 2001 From: Martin Lippert Date: Thu, 14 Sep 2017 16:18:51 +0200 Subject: [PATCH] adopted changed boot 2 actuator jmx endpoint structure --- .../commons/boot/app/cli/SpringBootApp.java | 65 ++++++++++++++++--- 1 file changed, 56 insertions(+), 9 deletions(-) diff --git a/headless-services/commons/commons-boot-app-cli/src/main/java/org/springframework/ide/vscode/commons/boot/app/cli/SpringBootApp.java b/headless-services/commons/commons-boot-app-cli/src/main/java/org/springframework/ide/vscode/commons/boot/app/cli/SpringBootApp.java index 5c81d9ef7..5ea87426e 100644 --- a/headless-services/commons/commons-boot-app-cli/src/main/java/org/springframework/ide/vscode/commons/boot/app/cli/SpringBootApp.java +++ b/headless-services/commons/commons-boot-app-cli/src/main/java/org/springframework/ide/vscode/commons/boot/app/cli/SpringBootApp.java @@ -91,46 +91,70 @@ public class SpringBootApp { } public String getEnvironment() throws Exception { - Object result = getActuatorData("org.springframework.boot:type=Endpoint,name=environmentEndpoint", "Data"); + Object result = getActuatorDataFromAttribute("org.springframework.boot:type=Endpoint,name=environmentEndpoint", "Data"); if (result != null) { String environment = new ObjectMapper().writeValueAsString(result); return environment; - } + + result = getActuatorDataFromOperation("org.springframework.boot:type=Endpoint,name=Env", "environment"); + if (result != null) { + String environment = new ObjectMapper().writeValueAsString(result); + return environment; + } + return null; } public String getBeans() throws Exception { - Object result = getActuatorData("org.springframework.boot:type=Endpoint,name=beansEndpoint", "Data"); + Object result = getActuatorDataFromAttribute("org.springframework.boot:type=Endpoint,name=beansEndpoint", "Data"); if (result != null) { String beans = new ObjectMapper().writeValueAsString(result); return beans; - } + + result = getActuatorDataFromOperation("org.springframework.boot:type=Endpoint,name=Beans", "beans"); + if (result != null) { + String beans = new ObjectMapper().writeValueAsString(result); + return beans; + } + return null; } public String getRequestMappings() throws Exception { - Object result = getActuatorData("org.springframework.boot:type=Endpoint,name=requestMappingEndpoint", "Data"); + Object result = getActuatorDataFromAttribute("org.springframework.boot:type=Endpoint,name=requestMappingEndpoint", "Data"); if (result != null) { String mappings = new ObjectMapper().writeValueAsString(result); return mappings; - } + + result = getActuatorDataFromOperation("org.springframework.boot:type=Endpoint,name=Mappings", "mappings"); + if (result != null) { + String mappings = new ObjectMapper().writeValueAsString(result); + return mappings; + } + return null; } public String getAutoConfigReport() throws Exception { - Object result = getActuatorData("org.springframework.boot:type=Endpoint,name=autoConfigurationReportEndpoint", "Data"); + Object result = getActuatorDataFromAttribute("org.springframework.boot:type=Endpoint,name=autoConfigurationReportEndpoint", "Data"); if (result != null) { String report = new ObjectMapper().writeValueAsString(result); return report; - } + + result = getActuatorDataFromOperation("org.springframework.boot:type=Endpoint,name=Autoconfig", "getEvaluationReport"); + if (result != null) { + String report = new ObjectMapper().writeValueAsString(result); + return report; + } + return null; } - protected Object getActuatorData(String actuatorID, String attribute) throws Exception { + protected Object getActuatorDataFromAttribute(String actuatorID, String attribute) throws Exception { String jmxConnect = this.vm.startLocalManagementAgent(); JMXConnector jmxConnector = null; @@ -153,6 +177,29 @@ public class SpringBootApp { } } + protected Object getActuatorDataFromOperation(String actuatorID, String operation) throws Exception { + String jmxConnect = this.vm.startLocalManagementAgent(); + + JMXConnector jmxConnector = null; + try { + JMXServiceURL serviceUrl = new JMXServiceURL(jmxConnect); + jmxConnector = JMXConnectorFactory.connect(serviceUrl, null); + MBeanServerConnection connection = jmxConnector.getMBeanServerConnection(); + + try { + ObjectName objectName = new ObjectName(actuatorID); + Object result = connection.invoke(objectName, operation, null, null); + return result; + } + catch (InstanceNotFoundException e) { + } + return null; + } + finally { + if (jmxConnector != null) jmxConnector.close(); + } + } + protected boolean contains(String[] cpElements, String element) { for (String cpElement : cpElements) { if (cpElement.contains(element)) {