Properly serialise output of endpoint command

This commit is contained in:
Christian Dupuis 2014-03-20 11:20:26 +01:00
parent b760722234
commit 99d6af6cbb
1 changed files with 15 additions and 6 deletions

View File

@ -1,6 +1,7 @@
package commands
import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.boot.actuate.endpoint.Endpoint
import org.springframework.boot.actuate.endpoint.jmx.*
@Usage("Invoke actuator endpoints")
class endpoint {
@ -8,7 +9,7 @@ class endpoint {
@Usage("List all available and enabled actuator endpoints")
@Command
def list(InvocationContext context) {
context.attributes['spring.beanfactory'].getBeansOfType(Endpoint.class).each { name, endpoint ->
if (endpoint.isEnabled()) {
out.println name
@ -20,14 +21,22 @@ class endpoint {
@Usage("Invoke provided actuator endpoint")
@Command
def invoke(InvocationContext context, @Usage("The object name pattern") @Required @Argument String name) {
context.attributes['spring.beanfactory'].getBeansOfType(Endpoint.class).each { n, endpoint ->
if (n.equals(name) && endpoint.isEnabled()) {
out.println endpoint.invoke()
EndpointMBean mbean = context.attributes['spring.beanfactory'].getBean(EndpointMBeanExporter.class).getEndpointMBean(name, endpoint)
if (mbean instanceof DataEndpointMBean) {
out.println mbean.getData()
}
else {
out.println mbean.invoke()
}
}
}
""
}
}
}