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>
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 }");
}
}
Solved! Go to Solution.
Views
Replies
Total Likes
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
@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 }"); } }
Thank you for your answer @Ganthimathi_R! Unfortunately I'm still getting the same error.
@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://www.aemcq5tutorials.com/tutorials/sling-servlet-in-aem/#advantages_selector_over_path
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
Views
Likes
Replies