servlet not being map to path | Community
Skip to main content
September 29, 2022
Solved

servlet not being map to path

  • September 29, 2022
  • 1 reply
  • 1503 views

 

1 - The class is being listed in /system/console/components (and active).

2 - When I entry the url in Sling Servlet Resolver (system/console/servletresolver/) I get this message:

Could not find a suitable servlet for this request!

3- When I call it from postman or direct in browser:

4242 TIMER_END{305,ResourceResolution} URI=/bin/test/clients-by-name resolves to Resource=NonExistingResource

4 - I've clenead the browser, updated postman and restarted aem instance (crx-quickstart folder was deleted as well)

5- In postman the error status massage is 409 (Conflict):

<td><div id="Message">repository state conflicting with request</div></td>
6- Deleted filter methods and checked the allow empty box
 

Servlet class (I'm just trying to do a hello world):

@8220494(service = {Servlet.class}, property = { SLING_SERVLET_METHODS + "=" + HttpConstants.METHOD_GET, SLING_SERVLET_METHODS + "=" + HttpConstants.METHOD_POST, SLING_SERVLET_EXTENSIONS + "=" + "json", SLING_SERVLET_PATHS + "=" + "/bin/test/clients-by-name", }) @ServiceDescription("list of clients by 'name'") public class ClientsByNameServlet extends SlingAllMethodsServlet { private static final long serialVersionUID = 1L; @3214626 private ClientsByNameService clientsByNameService; @9944223 protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.getWriter().write("{ \"hello\" : aa }"); } @9944223 protected void doPost(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws IOException { response.setContentType("application/json"); response.getWriter().write("{ \"hello\" : aa }"); } }

 

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 arunpatidar

Hi,

You might have issue with external services used in Servlet e.g.

@reference
    private ClientsByNameService clientsByNameService;

 

remove this reference and try.

and check the bundle, there you may see that the servlet in satisfied state

1 reply

Community Advisor
September 30, 2022

@rute Please refer the below code which works.

@Component(service = {Servlet.class},
        property = {
                "sling.servlet.methods=" + HttpConstants.METHOD_GET,
                "sling.servlet.methods=" + HttpConstants.METHOD_POST,
                "sling.servlet.paths=" + "/bin/test/clients-by-name",
                "sling.servlet.extensions=json",               
        })
public class ClientsByNameServlet extends SlingAllMethodsServlet {

    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(final SlingHttpServletRequest request,

                         final SlingHttpServletResponse response) throws ServletException, IOException {

        response.setContentType("application/json");

        response.getWriter().write("{ \"hello\" : aa }");

    }

    @Override
    protected void doPost(final SlingHttpServletRequest request,
                          final SlingHttpServletResponse response) throws IOException {
        response.setContentType("application/json");
        response.getWriter().write("{ \"hello\" : aa }");
    }
}

 

ruteAuthor
September 30, 2022

Thank you for your answer @ganthira1! Unfortunately I'm still getting the same error.

Community Advisor
September 30, 2022

@rute Adobe recommends using resourceType instead of path for registering the servlet. You can try with resource Type, Please refer these posts for more information.

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/sling-servlet-path-vs-resourcetype/m-p/322039

https://www.aemcq5tutorials.com/tutorials/sling-servlet-in-aem/#advantages_selector_over_path