@ GET @ Path ( "{key}" ) public Response getMBean ( @ PathParam ( "key" ) String key , @ QueryParam ( "jsonp" ) @ DefaultValue ( "" ) String jsonp ) throws Exception { LOG . info ( "key: " + key ) ; JSONObject json = new JSONObject ( ) ; ObjectName name = new ObjectName ( key ) ; json . put ( "domain" , name . getDomain ( ) ) ; json . put ( "property" , name . getKeyPropertyList ( ) ) ; if ( key . contains ( "*" ) ) { JSONObject keys = new JSONObject ( ) ; for ( Entry < String , Map < String , String > > attrs : jmx . getMBeanAttributesByRegex ( key ) . entrySet ( ) ) { keys . put ( attrs . getKey ( ) , attrs . getValue ( ) ) ; } json . put ( "attributes" , keys ) ; json . put ( "multikey" , true ) ; } else { json . put ( "attributes" , jmx . getMBeanAttributes ( key ) ) ; json . put ( "multikey" , false ) ; MBeanOperationInfo [ ] operations = jmx . getMBeanOperations ( key ) ; JSONArray ar = new JSONArray ( ) ; for ( MBeanOperationInfo operation : operations ) { JSONObject obj = new JSONObject ( ) ; obj . put ( "name" , operation . getName ( ) ) ; obj . put ( "description" , operation . getDescription ( ) ) ; obj . put ( "returnType" , operation . getReturnType ( ) ) ; obj . put ( "impact" , operation . getImpact ( ) ) ; JSONArray params = new JSONArray ( ) ; for ( MBeanParameterInfo param : operation . getSignature ( ) ) { JSONObject p = new JSONObject ( ) ; p . put ( "name" , param . getName ( ) ) ; p . put ( "type" , param . getType ( ) ) ; params . put ( p ) ; } obj . put ( "params" , params ) ; ar . put ( obj ) ; } json . put ( "operations" , ar ) ; } StringWriter out = new StringWriter ( ) ; if ( jsonp . isEmpty ( ) ) { json . write ( out ) ; } else { out . append ( jsonp ) . append ( "(" ) ; json . write ( out ) ; out . append ( ");" ) ; } return Response . ok ( out . toString ( ) ) . type ( MediaType . APPLICATION_JSON ) . build ( ) ; }
Return all the attributes and operations for a single mbean