Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

[AEM Gems Webinar] Accelerating Experience Manager as a Cloud Service development with Rapid Development Environments
SOLVED

servlet not being map to path

Avatar

Level 2

 

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

@component(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;

    @reference
    private ClientsByNameService clientsByNameService;

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

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

0 Replies

Avatar

Level 6

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

Ganthimathi_0-1664498335975.png

Ganthimathi_2-1664498422328.png

 

Avatar

Correct answer by
Community Advisor

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