Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

ConfigurationAdmin - Access OSGi configuration of other services | AEM Community Blog Seeding

kautuk_sahni
Community Manager
Community Manager

BlogImage.jpg

ConfigurationAdmin - Access OSGi configuration of other services by Adobe Experience Manager Blog

Abstract

In this article we will explore ConfigurationAdmin interface. Service for administering configuration data.

ConfigurationAdmin is a dictionary of properties. To identify a target service’s dictionary use its PID.

Sharing as code snippet that reads “rootmapping.target” configuration of the OOTB “Day CQ Root Mapping” service.

package com.techrevel.dam.core.servlets;

import java.io.IOException;
import java.util.Dictionary;

import javax.servlet.Servlet;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.HttpConstants;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(service = Servlet.class, property = { "sling.servlet.methods=" + HttpConstants.METHOD_GET,
"sling.servlet.paths=" + "/apps/techrevel/accessserviceconfig" })
public class AccessServiceConfig extends SlingAllMethodsServlet {

private final Logger LOGGER = LoggerFactory.getLogger(getClass());

@Reference
private ConfigurationAdmin configAdmin;

/**
* The method fetches the Post Process Observation configuration
*
* @throws IOException
*/
private void getConfigs() throws IOException {
Configuration taxonomyFeedConfig = configAdmin
.getConfiguration("com.day.cq.commons.servlets.RootMappingServlet");
Dictionary<String, Object> properties = taxonomyFeedConfig.getProperties();

LOGGER.debug("[getConfigs] – Root Mapping Target: {}",
PropertiesUtil.toString(properties.get("rootmapping.target"), ""));

}

@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
getConfigs();
}
}
view rawAccessServiceConfig.java hosted with ❤ by GitHub
When a target service’s configuration is updated, config details would also refresh in ConfigurationAdmin API. Thus, if you read configuration once updates are persisted, you would get the updated values. Example: if we access above servlet after updating the “rootmapping.target”, we would receive the updated value in logs.

Read Full Blog

ConfigurationAdmin - Access OSGi configuration of other services

Q&A

Please use this thread to ask the related questions.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

0 Replies