Servlet with resourceType not getting called .. | Community
Skip to main content
AdobeID24
Level 5
September 27, 2022

Servlet with resourceType not getting called ..

  • September 27, 2022
  • 4 replies
  • 1719 views

 

 

 

this servlet is registered and enabled and active all good checked from below 

 

http://localhost:4502/content/we-retail/AmitHomePage.amit.ttt

http://localhost:4502/content/we-retail/AmitHomePage/jcr:content.amit.ttt

http://localhost:4502/content/we-retail/AmitHomePage/_jcr_content.amit.ttt

 

nothing is working . 

is there any configuration or anything i missing ?

nothing in logs as well.

 

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

4 replies

Level 4
September 27, 2022

Can you verify your servlet here and see if your servlet is getting registered for the given resourceType :

http://localhost:4502/system/console/servletresolver?url=yourResourceType&method=GET

 

 

milind_bachani
Adobe Employee
Adobe Employee
September 27, 2022

Hi @adobeid24 ,

Here is a working code snippet :

@Component(service = { Servlet.class }, immediate = true)
@SlingServletResourceTypes(
        resourceTypes = "anf-code-challenge/components/title",
        methods = HttpConstants.METHOD_GET,
        extensions = "ext",
        selectors = "milind"
)
public class ResourceTypeServlet extends SlingSafeMethodsServlet {

    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(final SlingHttpServletRequest req,
            final SlingHttpServletResponse resp) throws ServletException, IOException {
        resp.getWriter().write("servlet is called");
    }
}

 

Thanks,
Milind

milind_bachani
Adobe Employee
Adobe Employee
September 27, 2022

The methods inside the resource type servlet are case-sensitive.

Please use "GET"[uppercase] instead of "get"[lowercase] or use the

HttpConstants.METHOD_GET

as I used in the reference snippet in the below comment.


Post build , http://localhost:4502/content/we-retail/AmitHomePage/jcr:content.amit.ttt should resolve to your servlet.


Thanks,
Milind

AdobeID24
AdobeID24Author
Level 5
September 27, 2022

I followed the same . 

https://sourcedcode.com/blog/aem/registering-slingservletpaths-component-property-type

 

 

Thanks for the help @milind_bachani  i ll try that get thing which you asked . 

HeenaMadan
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
September 27, 2022

make Methods "GET" and it should work

 

@Component(service = { Servlet.class })
@SlingServletResourceTypes(
        resourceTypes="project/components/structure/page",
        methods= "GET",
        extensions="txt",
        selectors="amit")
public class SimpleServlet1 extends SlingSafeMethodsServlet {

    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(final SlingHttpServletRequest req,
                         final SlingHttpServletResponse resp) throws ServletException, IOException {
        final Resource resource = req.getResource();
        resp.setContentType("text/plain");
        resp.getWriter().write("Title = amit");
    }
}

try- http://localhost:4502/content/project/us/en/index/jcr:content.amit.txt

 

You can check your servlet registration and mapping here http://localhost:4502/system/console/servletresolver

 

AdobeID24
AdobeID24Author
Level 5
September 27, 2022

 

 

Not working ..