Expand my Community achievements bar.

Nomination window for the Adobe Community Advisor Program, Class of 2025, is now open!

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

Level 7

I followed the same . 

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

AdobeID24_0-1664297882643.png

 

 

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

Avatar

Level 7

@milind_bachani 

 

AdobeID24_1-1664298234073.png

 

It did not work .

 

AdobeID24_2-1664298274881.png

 

 

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

 

Avatar

Level 7

AdobeID24_0-1664301522737.png

 

AdobeID24_1-1664301559816.png

 

Not working ..