14 Replies Latest reply on May 15, 2018 10:15 AM by brendanf9753525

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

    brendanf9753525 Level 1

      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

        • 1. Re: AEM 6.4 - Java sling servlet does not work with uber 6.4 jar, but does with uber 6.3
          arunp99088702 Level 3

          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();

              }  

           

          }

           

           

          Screen Shot 2018-05-11 at 1.40.11 AM.png

           

          Thanks

          Arun

          • 2. Re: AEM 6.4 - Java sling servlet does not work with uber 6.4 jar, but does with uber 6.3
            kautuksahni Adobe Employee

            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.

            • 3. Re: AEM 6.4 - Java sling servlet does not work with uber 6.4 jar, but does with uber 6.3
              smacdonald2008 Adobe Employee

              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 {

              • 4. Re: AEM 6.4 - Java sling servlet does not work with uber 6.4 jar, but does with uber 6.3
                brendanf9753525 Level 1

                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.da y.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.da y.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

                • 5. Re: AEM 6.4 - Java sling servlet does not work with uber 6.4 jar, but does with uber 6.3
                  arunp99088702 Level 3

                  from logs you are accessing /bin/feed

                  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

                   

                  but your code has different path.

                  try to access with /bin/amsurg/feed

                  • 6. Re: AEM 6.4 - Java sling servlet does not work with uber 6.4 jar, but does with uber 6.3
                    brendanf9753525 Level 1

                    Sorry about that, I was trying a bunch of different paths. Nothing seems to be registering with that annotation. It doesn't register with /bin/amsurg/feed, /bin/amsurg, or something like /bin/foo

                    • 7. Re: AEM 6.4 - Java sling servlet does not work with uber 6.4 jar, but does with uber 6.3
                      smacdonald2008 Adobe Employee

                      Try on a fresh instance - this will tell us if the issue is with your instance or something in your steps.

                      • 8. Re: AEM 6.4 - Java sling servlet does not work with uber 6.4 jar, but does with uber 6.3
                        brendanf9753525 Level 1

                        I tried on a fresh install and it still cannot find my servlet

                        • 9. Re: AEM 6.4 - Java sling servlet does not work with uber 6.4 jar, but does with uber 6.3
                          Jörg Hoh Adobe Employee

                          You have some complaints about content package importer issues, you should fix them as well. Although these have nothing to do with your reported issue.

                           

                          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.)

                           

                          Regarding your issue: Can you check the created content package and validate that your bundle is contained in the content package? The log excerpt you posted makes me think that there is no bundle contained (or at least not getting picked up for whatever reason). What's the name of your content package file?

                           

                          Jörg

                          • 10. Re: AEM 6.4 - Java sling servlet does not work with uber 6.4 jar, but does with uber 6.3
                            brendanf9753525 Level 1

                            Sure thing Jorg, I'll look at those once we can get this ironed out. Our bundle is named amsurg.ui.apps.

                             

                            It's weird, my bundle is loaded and started and showing the correct version. I even have some other servlets that are included in there, but they use the old annotations. I included that below. It's almost like all of the servlets are being loaded and started except for the one I'm trying to play with now. It just isn't included at all. No build errors or anything like that.

                             

                            @SlingServlet(paths = "/bin/amsurg/marketoNewsletterSignupServlet", methods = "POST", metatype = true)

                             

                             

                            • 11. Re: AEM 6.4 - Java sling servlet does not work with uber 6.4 jar, but does with uber 6.3
                              Jörg Hoh Adobe Employee

                              Then you should check in the target/classes/OSGI-INF if there are xml files generated for these servlets in question.

                               

                              Jörg

                              • 12. Re: AEM 6.4 - Java sling servlet does not work with uber 6.4 jar, but does with uber 6.3
                                brendanf9753525 Level 1

                                I checked and it is not generated in there. All the rest of the servlets have them but that one is missing. So it looks like it is not being added to the package.

                                 

                                What do you think the cause of this could be? It does not seem to like my new annotations.

                                • 13. Re: AEM 6.4 - Java sling servlet does not work with uber 6.4 jar, but does with uber 6.3
                                  Jörg Hoh Adobe Employee

                                  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. Re: AEM 6.4 - Java sling servlet does not work with uber 6.4 jar, but does with uber 6.3
                                    brendanf9753525 Level 1

                                    Thank you Jorg! That was it, I needed to add those OSGI dependencies and update my bundles.

                                     

                                    It is loading and looks good now.