AEM 6.4 - Java sling servlet does not work with uber 6.4 jar, but does with uber 6.3 | Community
Skip to main content
brendanf9753525
Level 4
May 10, 2018 9:21 PM UTC
Solved

AEM 6.4 - Java sling servlet does not work with uber 6.4 jar, but does with uber 6.3

Hey all,

I am seeing a really weird issue with a fresh install of AEM 6.4. I have a Java sling servlet registered at a path of /bin/feed. This servlet crashes and does not load everytime I try to visit it.

Observing the logs gives me this error.

10.05.2018 14:59:24.876 *ERROR* [FelixDispatchQueue] org.apache.sling.servlets.resolver FrameworkEvent ERROR (org.osgi.framework.ServiceException: Service factory returned null. (Component: com.amsurg.core.servlets.RSSXMLServlet (3142)))

org.osgi.framework.ServiceException: Service factory returned null. (Component: com.amsurg.core.servlets.RSSXMLServlet (3142))

It's pretty vague and I've seen some fixes for it with previous versions of AEM, but nothing concrete for 6.4 yet. The weird thing is, if I build and upload my package with the 6.4 uber-jar, I see the error 10/10 times. However when I compile it with the 6.3 uber-jar, it doesn't have any issues. That doesn't seem to be correct to me since I am using AEM 6.4.

Does anyone have any ideas or other things I can check for as to why this would not work? I have several other servlets registering in the same way and they are loaded just fine, so its a problem with this one + the uber 6.4 jar.

Thanks

Brendan

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
joerghoh
joerghohAccepted solution
Employee
May 14, 2018 10:04 PM UTC

Do you use the "new" OSGI annotations and have you updated your imports accordingly? On Using OSGi annotations (>= AEM6.2) - Experience Delivers  Feike has done a good job and listed all relevant things to consider.

Jörg

14 replies

brendanf9753525
Level 4
May 11, 2018 4:08 PM UTC

Sure thing, thanks for the quick responses all! The issue I am seeing now is that the service isn't even being seen in AEM. Here is the log below.

11.05.2018 10:05:09.534 *INFO* [qtp1956172325-1916] com.day.crx.packaging.impl.SlingInstallerSupportImpl Sling installer node /system/sling/installer/jcr/pauseInstallation/d376a330-a138-44f8-84ae-9bb541b586f0/com.day.crx.packaging.impl.SlingInstallerSupportImpl/0332235e-5f51-48d5-a0e0-9a1be9b4cf13 created.

11.05.2018 10:05:10.547 *ERROR* [qtp1956172325-1916] org.apache.jackrabbit.vault.fs.io.Importer E /apps/amsurg/components/content/SCCN/midblock-info (org.xml.sax.SAXParseException; systemId: file:///C:/aem/jcr_root/apps/amsurg/components/content/SCCN/midblock-info/.content.xml; lineNumber: 6; columnNumber: 2; XML document structures must start and end within the same entity.)

11.05.2018 10:05:10.548 *ERROR* [qtp1956172325-1916] org.apache.jackrabbit.vault.fs.io.Importer E /apps/amsurg/components/content/SCCN/midblock-info/cq:dialog (java.lang.IllegalStateException: Parent node not found.)

11.05.2018 10:05:10.548 *ERROR* [qtp1956172325-1916] org.apache.jackrabbit.vault.fs.io.Importer E /apps/amsurg/components/content/SCCN/midblock-info/midblock-info.html (java.lang.IllegalStateException: Parent node not found.)

11.05.2018 10:05:10.548 *ERROR* [qtp1956172325-1916] org.apache.jackrabbit.vault.fs.io.Importer E /apps/amsurg/components/content/SCCN/midblock-info/cq:editConfig (java.lang.IllegalStateException: Parent node not found.)

11.05.2018 10:05:10.888 *INFO* [qtp1956172325-1916] com.day.crx.packaging.impl.J2EEPackageManager Found installable at /apps/amsurg/config/com.amsurg.core.config.ServiceConstants

11.05.2018 10:05:12.491 *ERROR* [qtp1956172325-1916] org.apache.jackrabbit.vault.fs.io.Importer There were errors during package install. Please check the logs for details.

11.05.2018 10:05:12.684 *INFO* [qtp1956172325-1916] org.apache.jackrabbit.vault.packaging.impl.ActivityLog R2i-Commons/.snapshot:r2i-commons.ui.apps:1.4.43-SNAPSHOT: CREATE

11.05.2018 10:05:13.824 *INFO* [qtp1956172325-1916] org.apache.jackrabbit.vault.packaging.impl.ActivityLog R2i-Commons/.snapshot:r2i-commons.ui.apps:1.4.43-SNAPSHOT: SNAPSHOT

11.05.2018 10:05:13.948 *INFO* [qtp1956172325-1916] org.apache.jackrabbit.vault.packaging.impl.ActivityLog R2i-Commons:r2i-commons.ui.apps:1.4.43-SNAPSHOT: INSTALL

11.05.2018 10:05:13.951 *INFO* [qtp1956172325-1916] org.apache.jackrabbit.vault.packaging.impl.ActivityLog Amsurg:amsurg.ui.apps:1.4.43-SNAPSHOT: INSTALL

11.05.2018 10:05:13.959 *INFO* [qtp1956172325-1916] com.day.crx.packaging.impl.SlingInstallerSupportImpl Sling installer node /system/sling/installer/jcr/pauseInstallation/d376a330-a138-44f8-84ae-9bb541b586f0/com.day.crx.packaging.impl.SlingInstallerSupportImpl/0332235e-5f51-48d5-a0e0-9a1be9b4cf13 removed.

11.05.2018 10:05:13.959 *INFO* [qtp1956172325-1916] com.day.crx.packaging.impl.J2EEPackageManager Scanner detected potential jcr installable. delaying installation for 2 seconds.

11.05.2018 10:05:18.878 *INFO* [0:0:0:0:0:0:0:1 [1526054718868] GET /bin/feed HTTP/1.1] org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Resource /bin/feed not found

11.05.2018 10:05:20.000 *INFO* [CommitStats] CommitStats 11 commits by 2 users [90% admin, 9% sling-installer-service] from location service:jetty [CommitStats overhead was 4ms = 364.0us / commit]

Here is my code

@Component(service=Servlet.class,
   property={

  Constants.SERVICE_DESCRIPTION + "=RSS XML Feed",
   "sling.servlet.methods=" + HttpConstants.METHOD_GET,
   "sling.servlet.paths=/bin/amsurg/feed"
})

public class RSSXMLServlet extends SlingAllMethodsServlet {

It builds okay but there isn't anything on AEM for my servlet. If I check out my package it doesn't appear at all. Do you guys have any thoughts?

Thanks

Translate
smacdonald2008
Level 10
May 11, 2018 1:24 PM UTC

A Sling Servlet with DS Annotations (default for Maven 12/13 Archetype) looks like this:

/**

* Servlet that writes some sample content into the response. It is mounted for

* all resources of a specific Sling resource type. The

* {@link SlingSafeMethodsServlet} shall be used for HTTP methods that are

* idempotent. For write operations use the {@link SlingAllMethodsServlet}.

*/

@Component(service=Servlet.class,

        property={

                Constants.SERVICE_DESCRIPTION + "=Simple Demo Servlet",

                "sling.servlet.methods=" + HttpConstants.METHOD_POST,

                "sling.servlet.paths="+ "/bin/myDataSourcePoolServlet"

           })

public class SimpleServlet extends SlingAllMethodsServlet {

Translate
kautuk_sahni
Employee
May 11, 2018 10:36 AM UTC

Duplicate question: https://forums.adobe.com/message/10375900#10375900

Can you please share your code? and full error.log?

Team would require Source code to check this up. Maybe you using service which is no longer available in AEM.

Translate
Kautuk Sahni
arunpatidar
New Participant
May 10, 2018 11:41 PM UTC

I tried to create servlet in AEM6.4, for me its working fine.

below is sample servlet code and POM which I've created

@Component(service=Servlet.class,immediate=true,

  property= {

  Constants.SERVICE_DESCRIPTION + "=TitleSlindServlet Demo Servlet",

  "sling.servlet.paths=/bin/aem64app/titleservlet",

            "sling.servlet.methods=" + HttpConstants.METHOD_GET,

            "sling.servlet.extensions=" + "html"

  })

public class TitleSlingServlet extends SlingSafeMethodsServlet{

  private static final long serialVersionUID = 1L;

  @Override

    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {

  response.setHeader("Content-Type", "text/html");

    response.getWriter().print("<h1>Sling Servlet injected this title");

  response.getWriter().close();

    }  

}

Thanks

Arun

Translate
Arun Patidar