Skip to main content
GK-007
Level 9
Oct 16, 2015 2:27 AM UTC
Solved

Getting 404 Error while accessing sling servlet

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.
Sham_HC
Sham_HCAccepted solution
Level 10
Oct 16, 2015 2:27 AM UTC

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

GK-007
GK-007Author
Level 9
Oct 16, 2015 2:27 AM UTC

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?

Translate
smacdonald2008
Level 10
Oct 16, 2015 2:27 AM UTC

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

Translate
smacdonald2008
Level 10
Oct 16, 2015 2:27 AM UTC

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. 

Translate
GK-007
GK-007Author
Level 9
Oct 16, 2015 2:27 AM UTC

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.

Translate
GK-007
GK-007Author
Level 9
Oct 16, 2015 2:27 AM UTC

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?

Translate
Sham_HC
Sham_HCAccepted solution
Level 10
Oct 16, 2015 2:27 AM UTC

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

Translate
edubey
Level 10
Oct 16, 2015 2:27 AM UTC
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.        
Translate