Expand my Community achievements bar.

SOLVED

How to get SlingScriptHelper in servlet in CQ5.5

Avatar

Level 2

Hi,

I am unable to get SlingScriptHelper in servlet using the below code..

bundleContext = FrameworkUtil.getBundle(SlingScriptHelper.class).getBundleContext();
factoryRef = bundleContext.getServiceReference(SlingScriptHelper.class.getName());
sling= (SlingScriptHelper) bundleContext.getService(factoryRef);

and 

SlingBindings bindings = (SlingBindings) req.getAttribute(SlingBindings.class.getName());

SlingScriptHelper scriptHelper = bindings.getSling();

 

I am getting null.

java.lang.NullPointerException: Specified service reference cannot be null.

 

Please help me..

 

Thanks & Regards,

Veeru

1 Accepted Solution

Avatar

Correct answer by
Level 10
3 Replies

Avatar

Level 10

What you trying to do - are you trying to get a reference to the Sling Servlet from Java code?

Avatar

Correct answer by
Level 10

Avatar

Employee

Just use indeed @Reference in your servlet...