Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

[HELP] Could not get service from ref [javax.servlet.Servlet]

Avatar

Community Advisor

Hi,

We had issues deploying to Prod last night in AEM 6.3 CFP 2.

We have Servlets that are registered using following API:

@Component(service = Servlet.class,

  property = {

  Constants.SERVICE_DESCRIPTION + "=Service",

   "service.label" + "=Service",

   "sling.servlet.methods=GET",

   SLING_SERVLET_RESOURCE_TYPES + "=sling/servlet/default",

   SLING_SERVLET_RESOURCE_TYPES + "=library/components/content/component",

   "sling.servlet.selectors=mySelector",

   SLING_SERVLET_EXTENSIONS + "=json"
   })

public class MyServlet extends SlingSafeMethodsServlet {

Unfortunately, while adding bundles 25% of servers thrown following exception:

  1. 11.07.2018 11:31:15.343 *WARN* [OsgiInstallerImpl] org.apache.sling.servlets.resolver [org.apache.sling.servlets.resolver.SlingServletResolver(745)] Could not get service from ref [javax.servlet.Servlet]
  2. 11.07.2018 11:31:15.343 *ERROR* [OsgiInstallerImpl] org.apache.sling.servlets.resolver.internal.SlingServletResolver bindServlet: Servlet service not available from reference [javax.servlet.Servlet]
  3. 11.07.2018 11:31:15.345 *ERROR* [FelixDispatchQueue] org.apache.sling.servlets.resolver FrameworkEvent ERROR (org.osgi.framework.ServiceException: Service factory returned null. (Component: com.company.MyServlet (3824)))
  • org.osgi.framework.ServiceException: Service factory returned null. (Component: com.company.MyServlet (3824))

                at org.apache.felix.framework.ServiceRegistrationImpl.getFactoryUnchecked(ServiceRegistrationImpl.java:380)

                at org.apache.felix.framework.ServiceRegistrationImpl.getService(ServiceRegistrationImpl.java:247)

                at org.apache.felix.framework.ServiceRegistry.getService(ServiceRegistry.java:344)

                at org.apache.felix.framework.Felix.getService(Felix.java:3700)

                at org.apache.felix.framework.BundleContextImpl.getService(BundleContextImpl.java:470)

                at org.apache.felix.scr.impl.manager.SingleRefPair.getServiceObject(SingleRefPair.java:72)

                at org.apache.felix.scr.impl.manager.DependencyManager.getService(DependencyManager.java:1461)

                at org.apache.felix.scr.impl.manager.DependencyManager.getService(DependencyManager.java:1434)

                at org.apache.felix.scr.impl.manager.ComponentContextImpl.locateService(ComponentContextImpl.java:147)

                at org.apache.sling.servlets.resolver.internal.SlingServletResolver.createServlet(SlingServletResolver.java:968)

                at org.apache.sling.servlets.resolver.internal.SlingServletResolver.bindServlet(SlingServletResolver.java:930)

                at sun.reflect.GeneratedMethodAccessor44.invoke(Unknown Source)

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

                at java.lang.reflect.Method.invoke(Method.java:498)

                at org.apache.felix.scr.impl.inject.BaseMethod.invokeMethod(BaseMethod.java:224)

                at org.apache.felix.scr.impl.inject.BaseMethod.access$500(BaseMethod.java:39)

                at org.apache.felix.scr.impl.inject.BaseMethod$Resolved.invoke(BaseMethod.java:617)

                at org.apache.felix.scr.impl.inject.BaseMethod.invoke(BaseMethod.java:501)

                at org.apache.felix.scr.impl.inject.BindMethod.invoke(BindMethod.java:655)

                at org.apache.felix.scr.impl.manager.DependencyManager.doInvokeBindMethod(DependencyManager.java:1722)

                at org.apache.felix.scr.impl.manager.DependencyManager.invokeBindMethod(DependencyManager.java:1699)

                at org.apache.felix.scr.impl.manager.SingleComponentManager.invokeBindMethod(SingleComponentManager.java:372)

                at org.apache.felix.scr.impl.manager.DependencyManager$MultipleDynamicCustomizer.addedService(DependencyManager.java:320)

                at org.apache.felix.scr.impl.manager.DependencyManager$MultipleDynamicCustomizer.addedService(DependencyManager.java:291)

                at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.customizerAdded(ServiceTracker.java:1215)

                at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.customizerAdded(ServiceTracker.java:1136)

                at org.apache.felix.scr.impl.manager.ServiceTracker$AbstractTracked.trackAdding(ServiceTracker.java:945)

                at org.apache.felix.scr.impl.manager.ServiceTracker$AbstractTracked.track(ServiceTracker.java:881)

                at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:1167)

                at org.apache.felix.scr.impl.BundleComponentActivator$ListenerInfo.serviceChanged(BundleComponentActivator.java:127)

                at org.apache.felix.framework.util.EventDispatcher.invokeServiceListenerCallback(EventDispatcher.java:991)

                at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:839)

                at org.apache.felix.framework.util.EventDispatcher.fireServiceEvent(EventDispatcher.java:546)

                at org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:4558)

                at org.apache.felix.framework.Felix.registerService(Felix.java:3550)

                at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:348)

                at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:887)

                at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:874)

                at org.apache.felix.scr.impl.manager.RegistrationManager.changeRegistration(RegistrationManager.java:132)

                at org.apache.felix.scr.impl.manager.AbstractComponentManager.registerService(AbstractComponentManager.java:941)

                at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:741)

                at org.apache.felix.scr.impl.manager.DependencyManager$SingleStaticCustomizer.addedService(DependencyManager.java:1012)

                at org.apache.felix.scr.impl.manager.DependencyManager$SingleStaticCustomizer.addedService(DependencyManager.java:968)

                at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.customizerAdded(ServiceTracker.java:1215)

                at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.customizerAdded(ServiceTracker.java:1136)

                at org.apache.felix.scr.impl.manager.ServiceTracker$AbstractTracked.trackAdding(ServiceTracker.java:945)

                at org.apache.felix.scr.impl.manager.ServiceTracker$AbstractTracked.track(ServiceTracker.java:881)

                at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:1167)

                at org.apache.felix.scr.impl.BundleComponentActivator$ListenerInfo.serviceChanged(BundleComponentActivator.java:127)

                at org.apache.felix.framework.util.EventDispatcher.invokeServiceListenerCallback(EventDispatcher.java:991)

                at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:839)

                at org.apache.felix.framework.util.EventDispatcher.fireServiceEvent(EventDispatcher.java:546)

                at org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:4558)

                at org.apache.felix.framework.Felix.registerService(Felix.java:3550)

                at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:348)

                at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:887)

                at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:874)

                at org.apache.felix.scr.impl.manager.RegistrationManager.changeRegistration(RegistrationManager.java:132)

                at org.apache.felix.scr.impl.manager.AbstractComponentManager.registerService(AbstractComponentManager.java:941)

                at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:741)

                at org.apache.felix.scr.impl.manager.DependencyManager$SingleStaticCustomizer.addedService(DependencyManager.java:1012)

                at org.apache.felix.scr.impl.manager.DependencyManager$SingleStaticCustomizer.addedService(DependencyManager.java:968)

                at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.customizerAdded(ServiceTracker.java:1215)

                at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.customizerAdded(ServiceTracker.java:1136)

                at org.apache.felix.scr.impl.manager.ServiceTracker$AbstractTracked.trackAdding(ServiceTracker.java:945)

                at org.apache.felix.scr.impl.manager.ServiceTracker$AbstractTracked.track(ServiceTracker.java:881)

                at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:1167)

                at org.apache.felix.scr.impl.BundleComponentActivator$ListenerInfo.serviceChanged(BundleComponentActivator.java:127)

                at org.apache.felix.framework.util.EventDispatcher.invokeServiceListenerCallback(EventDispatcher.java:991)

                at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:839)

                at org.apache.felix.framework.util.EventDispatcher.fireServiceEvent(EventDispatcher.java:546)

                at org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:4558)

                at org.apache.felix.framework.Felix.registerService(Felix.java:3550)

                at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:348)

                at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:887)

                at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:874)

                at org.apache.felix.scr.impl.manager.RegistrationManager.changeRegistration(RegistrationManager.java:132)

                at org.apache.felix.scr.impl.manager.AbstractComponentManager.registerService(AbstractComponentManager.java:941)

                at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:741)

                at org.apache.felix.scr.impl.manager.AbstractComponentManager.enableInternal(AbstractComponentManager.java:675)

                at org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManager.java:430)

                at org.apache.felix.scr.impl.manager.ConfigurableComponentHolder.enableComponents(ConfigurableComponentHolder.java:657)

                at org.apache.felix.scr.impl.BundleComponentActivator.initialEnable(BundleComponentActivator.java:341)

                at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:390)

                at org.apache.felix.scr.impl.Activator.access$200(Activator.java:54)

                at org.apache.felix.scr.impl.Activator$ScrExtension.start(Activator.java:265)

                at org.apache.felix.utils.extender.AbstractExtender.createExtension(AbstractExtender.java:259)

                at org.apache.felix.utils.extender.AbstractExtender.modifiedBundle(AbstractExtender.java:232)

                at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:482)

                at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:415)

                at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:232)

                at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:444)

                at org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:916)

                at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:835)

                at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:517)

                at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4542)

                at org.apache.felix.framework.Felix.startBundle(Felix.java:2173)

                at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998)

                at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:984)

                at org.apache.sling.installer.core.impl.tasks.BundleStartTask.execute(BundleStartTask.java:97)

                at org.apache.sling.installer.core.impl.OsgiInstallerImpl.doExecuteTasks(OsgiInstallerImpl.java:894)

                at org.apache.sling.installer.core.impl.OsgiInstallerImpl.executeTasks(OsgiInstallerImpl.java:729)

                at org.apache.sling.installer.core.impl.OsgiInstallerImpl.run(OsgiInstallerImpl.java:286)

                at java.lang.Thread.run(Thread.java:745)

We had to restart servers to fix this issue. Normally, we are not restarting servers.

Is anyone aware why this issue might happen?


Regards,

Peter

9 Replies

Avatar

Administrator

See this post:-Get DataSourcePool for use in servlet  (Use latest maven-scr-plugin)

This might help you.

-Kautuk



Kautuk Sahni

Avatar

Level 10

Do these servlets deploy fine on author?

Avatar

Community Advisor

Hi Scott,

Nope it wasn't fine in Author. Author required restart as well.

This issue did not appear on a lower environment, local instances completed package installation successfully(all Servlets were up, no restart was required).

Regards,

Peter

Avatar

Employee Advisor

Is there any exception thrown by the component activator of this servlet?

Jörg

Avatar

Community Advisor

Hi Jörg,

Nothing can be seen outputted from component activator, all the logs that can be seen are attached in the first message.

Regards,

Peter

Avatar

Level 10

Peter - are you seeing any issue on Author with these servlets?

Avatar

Community Advisor

Hi Scott,

Before we restarted; servlet's in /system/console/components appeared as active, but their actual response when invoked was 400(the selector was not found).

Everything works perfectly fine after the restart.

During our deployment, we already wait 30 seconds before each package installation and try to extract global OSGi rules that may trigger multiple services restarts into a separate package.

The question here is whether anything else can be done to avoid a restart of publishers&author && ensure smooth start of Servlets?

Regards,

Peter

Avatar

Level 10

In theory - all you need to do is put the OSGi bundles in Active state. However - your experience is not lining up with theory. I am checking internally to see if there is a known issue.