osgiapache-felixgogo-shell

List all active Configuration for Config Admin in gogo shell


I would like to show on screen the Configuration list returned by org.osgi.service.cm.ConfigurationAdmin.listConfigurations method via gogo shell. I tried with the following:

g! _sref = $.context getServiceReference "org.osgi.service.cm.ConfigurationAdmin"
g! _srv = $.context getService $_sref
g! $_srv listConfigurations

but it fails with the following error:

gogo: IllegalArgumentException: Cannot coerce listconfigurations() to any of [(String)]

What is the right syntax here? Is it possible to do that?

Thanks!


Solution

  • The listConfigurations method takes a String parameter, which is a filter. If you just want an unfiltered list, then you can pass null, e.g.:

    $_srv listConfigurations null
    

    This returns an array of Configuration objects, which you will probably want to iterate over with the each command.

    However this kind of thing quickly gets too complex for Gogo scripting. For example you're not releasing the service reference with ungetService anywhere. It's probably better to build a reusable Gogo command in Java as a Declarative Services component.