Expand my Community achievements bar.

Servlet with resourceType not getting called ..

Avatar

Level 7

AdobeID24_0-1664290108258.png

 

AdobeID24_3-1664290364064.png

 

 

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

AdobeID24_1-1664290180985.png

 

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.

 

7 Replies

Avatar

Level 5

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

 

poojac35931336_0-1664292654390.png

 

Avatar

Employee Advisor

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

milind_bachani_0-1664296068030.png

 

Thanks,
Milind

Avatar

Employee Advisor

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.

milind_bachani_0-1664296739126.png


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


Thanks,
Milind

Avatar

Community Advisor

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

 

HeenaMadan_0-1664298245542.png

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