Getting 404 Error while accessing sling servlet | Community
Skip to main content
GK-007
Level 9
October 16, 2015
Solved

Getting 404 Error while accessing sling servlet

  • October 16, 2015
  • 7 replies
  • 11195 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Sham_HC

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}") 

7 replies

edubey
Level 10
October 16, 2015
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.        
Sham_HC
Sham_HCAccepted solution
Level 10
October 16, 2015

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}") 

GK-007
GK-007Author
Level 9
October 16, 2015

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?

GK-007
GK-007Author
Level 9
October 16, 2015

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.

smacdonald2008
Level 10
October 16, 2015

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. 

smacdonald2008
Level 10
October 16, 2015

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

GK-007
GK-007Author
Level 9
October 16, 2015

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?