Expand my Community achievements bar.

SOLVED

Getting 404 Error while accessing sling servlet

Avatar

Level 9

Hi All,

I have written sling servlet method with doGet method and trying to write json string onto browser.

I could see this servlet is part of bundle but when i try to access this servlet i am getting 404 error and in the logs it's saying resource is not found.

Servlet Description.

@SlingServlet(paths="/bin/servlets/mySearchServlet", methods = "GET", metatype=true)
public class ConnectToSABA extends org.apache.sling.api.servlets.SlingAllMethodsServlet {
     private static final long serialVersionUID = 2598426539166789515L;
      
     @Reference
     private SlingRepository repository;
      
     public void bindRepository(SlingRepository repository)
     {
            this.repository = repository; 
     }
           
     @Override
     protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServerException, IOException {
       
      try
      {
        //Encode the submitted form data to JSON
          JSONObject myJSON =  new JSONObject();
          myJSON.put("Name","Kishore");
         response.getWriter().write(myJSON.toString());
      }
      catch(Exception e)
      {
          e.printStackTrace();
      }
    }
     
}

Please help me in this regard.

Thanks,

Kishore

1 Accepted Solution

Avatar

Correct answer by
Level 10

configure does not require authentication at http://localhost:4502/system/console/configMgr/org.apache.sling.engine.impl.auth.SlingAuthenticator

or make user of [1] in servlet & notice the dash prefixing the path - if you don't include the dash that means the path requires authentication.

[1]   Property(name = "sling.auth.requirements", value = "-{/bin/servlets/mySearchServlet}") 

View solution in original post

7 Replies

Avatar

Level 10
Hi kishore, Ensure that you can see this servlet in osgi in cq5, if you are able see please share a screenshot from osgi. Can you tell, how you are trying to access servlet.        

Avatar

Correct answer by
Level 10

configure does not require authentication at http://localhost:4502/system/console/configMgr/org.apache.sling.engine.impl.auth.SlingAuthenticator

or make user of [1] in servlet & notice the dash prefixing the path - if you don't include the dash that means the path requires authentication.

[1]   Property(name = "sling.auth.requirements", value = "-{/bin/servlets/mySearchServlet}") 

Avatar

Level 9

Sham HC wrote...

configure does not require authentication at http://localhost:4502/system/console/configMgr/org.apache.sling.engine.impl.auth.SlingAuthenticator

or make user of [1] in servlet & notice the dash prefixing the path - if you don't include the dash that means the path requires authentication.

[1]   Property(name = "sling.auth.requirements", value = "-{/bin/servlets/mySearchServlet}") 

 

why my servlet is showing as "registered" status in Felix console Components section?

Avatar

Level 9

edubey wrote...

Hi kishore, Ensure that you can see this servlet in osgi in cq5, if you are able see please share a screenshot from osgi. Can you tell, how you are trying to access servlet.

 

I am trying to access like https://<hostname>:<port>/<servletpath>

PFA.

Avatar

Level 10

If you are following the community article - did you follow every step. You need to deploy the 2nd bundle that contains the Simple JSON JAR file. 

Also - can you post a screen shot of the bundle in the felx console. Open it so we can see the details. 

Avatar

Level 10

See this community article to learn how to build, deploy and invoke an AEM servlet: 

https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

Avatar

Level 9

smacdonald2008 wrote...

See this community article to learn how to build, deploy and invoke an AEM servlet: 

https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

 

why my servlet is showing as "registered" status in Felix console Components section?