Expand my Community achievements bar.

Who Me Too'd this topic

Avatar

Level 4

I have created sling:OsgiConfig nodes inside config folders like config.author, config.publish and so on. I am trying to fetch properties from these nodes by doing something like this:

public static List fetchTokenLinksFromOsgiConfig(final SlingHttpServletRequest slingRequest) throws IOException { List<String> tokenlinksList = new ArrayList<String>(); SlingBindings bindings = (SlingBindings) slingRequest.getAttribute(SlingBindings.class.getName()); log.info("=================inside fetchTokenLinksFromOsgiConfig======================"+bindings); SlingScriptHelper sling = bindings.getSling(); Configuration conf = sling.getService(org.osgi.service.cm.ConfigurationAdmin.class).getConfiguration("com.myuhc.TokenLinksConfig"); log.info("=================inside fetchTokenLinksFromOsgiConfig:::taking configurations======================"); String myuhcTokenId = (String) conf.getProperties().get("MyUHCTokenId"); String myuhcTokenSecret = (String) conf.getProperties().get("MyUHCTokenSecret"); String OAuthLink = (String) conf.getProperties().get("OAuthLink"); log.info("=================myuhcTokenId:::myuhcTokenSecret:::OAuthLink======================"+myuhcTokenId +" "+myuhcTokenSecret+" "+OAuthLink); if(!StringUtil.isEmpty(myuhcTokenId)) { tokenlinksList.add(myuhcTokenId); } if(!StringUtil.isEmpty(myuhcTokenSecret)) { tokenlinksList.add(myuhcTokenSecret); } if(!StringUtil.isEmpty(OAuthLink)) { tokenlinksList.add(OAuthLink); } return tokenlinksList; }

 

I am calling this method from a sling servlet like this: 

List tokenList = OsgiConfigUtil.fetchTokenLinksFromOsgiConfig(slingRequest);

but the bindings object of type SlingBindings is coming null. I have no idea how to work this out ?

Thanks in advance

Who Me Too'd this topic