added extraction of beans, request mappings, config report, and environment data to boot app cli component

This commit is contained in:
Martin Lippert
2017-05-17 17:13:17 +02:00
parent ba8a6161bc
commit 48c77e14b5
2 changed files with 68 additions and 9 deletions

View File

@@ -73,6 +73,69 @@ public class SpringBootApp {
if (jmxConnector != null) jmxConnector.close();
}
}
public String getEnvironment() throws Exception {
Object result = getActuatorData("org.springframework.boot:type=Endpoint,name=environmentEndpoint", "Data");
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");
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");
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");
if (result != null) {
String report = new ObjectMapper().writeValueAsString(result);
return report;
}
return null;
}
protected Object getActuatorData(String actuatorID, String attribute) 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.getAttribute(objectName, "Data");
return result;
}
catch (InstanceNotFoundException e) {
}
return null;
}
finally {
if (jmxConnector != null) jmxConnector.close();
}
}
protected boolean contains(String[] cpElements, String element) {
for (String cpElement : cpElements) {
@@ -126,13 +189,8 @@ public class SpringBootApp {
}
protected String getPortViaActuator(MBeanServerConnection connection) throws Exception {
try {
String DEFAULT_OBJECT_NAME = "org.springframework.boot:type=Endpoint,name=environmentEndpoint";
ObjectName objectName = new ObjectName(DEFAULT_OBJECT_NAME);
Object result = connection.getAttribute(objectName, "Data");
String environment = new ObjectMapper().writeValueAsString(result);
String environment = getEnvironment();
if (environment != null) {
JSONObject env = new JSONObject(environment);
if (env != null) {
JSONObject portsObject = env.getJSONObject("server.ports");
@@ -142,8 +200,6 @@ public class SpringBootApp {
}
}
}
catch (InstanceNotFoundException e) {
}
return null;
}

View File

@@ -35,6 +35,9 @@ public class SpringBootAppCLI {
System.out.println("Spring Boot App: " + app.getProcessID());
System.out.println("Name: " + app.getProcessName());
System.out.println("Port: " + app.getPort());
System.out.println("Beans: " + app.getBeans());
System.out.println("Mappings: " + app.getRequestMappings());
System.out.println("ConfigReport: " + app.getAutoConfigReport());
System.out.println();
}