adopted changed boot 2 actuator jmx endpoint structure

This commit is contained in:
Martin Lippert
2017-09-14 16:18:51 +02:00
parent 0f58d6585f
commit c76d6c7496

View File

@@ -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)) {