don't use class names as example namespaces
1 file changed
tree: f2b9d728a77118a3114750e426cf13fa9366e57d
  1. src/
  2. .gitignore
  3. pom.xml
  4. README.md
README.md

Sling Capabilities Module

The servlet provided by this module allows for creating Capabilities HTTP endpoints on a Sling instance: Resources that provide information on which services are available, version levels etc.

For now, a single type of endpoint is provided: all Resources which have the sling/capabilities resource type will return the same set of Capabilities, generated by aggregating the output of all active CapabilitiesSource services.

This can be easily expanded to multiple sets of Capabilities if needed later on, by changing the code to use service properties to group or tag the CapabilitiesSource services.

These capabilities are not the same as OSGi capabilities: they can be application-related, indicate the availability of external services, etc.

CapabilitiesSource services

The tests provide simple CapabilitiesSource examples, that API is as follows:

@ProviderType
public interface CapabilitiesSource {

    /** @return the namespace to use to group our capabilities.
     *  That name must be unique in a given Sling instance.
     */
    String getNamespace();

    /** @return zero to N capabilities, each being represented by
     *      a key/value pair.
     * @throws Exception if the capabilities could not be computed.
     */
    Map<String, Object> getCapabilities() throws Exception;
}

CapabilitiesServlet output

The CapabilitiesServlet produces output as in the example below, where two CapabilitiesSource services are available:

$ curl -s -u admin:admin http://localhost:8080/tmp/cap.json | jq .
{
  "org.apache.sling.capabilities": {
    "org.apache.sling.capabilities.osgi": {
      "framework.bundle.symbolic.name": "org.apache.felix.framework",
      "framework.bundle.version": "5.6.10"
    },
    "org.apache.sling.capabilities.jvm": {
      "java.specification.version": "1.8",
      "java.vm.version": "25.171-b11",
      "java.vm.vendor": "Oracle Corporation"
    }
  }
}