내 커뮤니티 업적 표시줄을 확대합니다.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.

해결됨

AEM 6 SlingBindings object is null

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

1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Level 7

Its hard to say why binding is coming up null, but if its null there is one more way of getting the service reference:

//serviceClass is the class object for which you need reference from OSGI BundleContext bundleContext = FrameworkUtil.getBundle(serviceClass).getBundleContext(); ServiceReference osgiRef = bundleContext.getServiceReference(serviceClass.getName()); serviceRef = (T) bundleContext.getService(osgiRef);

Imports are as follows:

import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference;

- Runal

원본 게시물의 솔루션 보기

1 답변 개

Avatar

정확한 답변 작성자:
Level 7

Its hard to say why binding is coming up null, but if its null there is one more way of getting the service reference:

//serviceClass is the class object for which you need reference from OSGI BundleContext bundleContext = FrameworkUtil.getBundle(serviceClass).getBundleContext(); ServiceReference osgiRef = bundleContext.getServiceReference(serviceClass.getName()); serviceRef = (T) bundleContext.getService(osgiRef);

Imports are as follows:

import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference;

- Runal