AD0-E137 practice question 1 of 10

A developer is asked to create an Adobe Experience Manager servlet MyServlet that listens for HTTP requests capable of handling the GET method. The…

Full set: 50 questions
A developer is asked to create an Adobe Experience Manager servlet MyServlet that listens for HTTP requests capable of handling the GET method. The servlet must be registered using Declarative Services (OSGi) and be bound to a specific resource type /my/resourcetype allowing it to serve requests for a particular component. What is the correct way to register a servlet? A) @SlingServletResourceTypes(resourceTypes ="/my/resourcetype", methods = {"get"}) public class MyServlet extends SlingSafeMethodServlet { @Override protected void doGET(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { // Handle get request } } B) @SlingServletResourceTypes(resourceTypes="/my/resourcetype", methods = { "GET" }) public class MyServlet extends SlingAllMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { // Handle get request } } C) @SlingServletResourceTypes(resourceTypes ="/my/resourcetype", methods = { "get" }) public class MyServlet extends SlingSafeMethodServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Handle get request } }
Answer options
A: Option A
B: Option B Correct answer
C: Option C
Correct Answer:
B. Option B
Explanation

This option provides a functionally correct implementation for the requested servlet. The @SlingServletResourceTypes annotation correctly registers the servlet, binding it to the specified resource type (/my/resourcetype) and HTTP method (GET). While SlingSafeMethodsServlet is often considered a best practice for read-only operations, extending SlingAllMethodsServlet is a perfectly valid and functional approach. Most importantly, this option correctly overrides the doGet method with the proper case and the required (SlingHttpServletRequest, SlingHttpServletResponse) signature, making it the only fully working solution among the choices.

Why Incorrect

A: This option is incorrect because the method name is doGET. Java method names are case-sensitive, and the correct method to override from the SlingSafeMethodsServlet class is doGet. C: This option is incorrect because the doGet method signature uses the standard HttpServletRequest and HttpServletResponse types. To correctly override the method from the Sling base servlet, it must use SlingHttpServletRequest and SlingHttpServletResponse.

References

1. Apache Sling Documentation, "Servlets and Scripts": This official documentation outlines the registration of servlets using OSGi Declarative Services annotations like @SlingServletResourceTypes. It also clarifies the base servlet classes available.

Reference: Apache Sling Project, "Servlets and Scripts", Section: "Registering a Servlet". Available at: https://sling.apache.org/documentation/bundles/servlets.html

2. Apache Sling API Documentation (Javadoc) for SlingSafeMethodsServlet: The official Javadoc specifies the exact method signature to be implemented for handling GET requests.

Reference: org.apache.sling.api.servlets.SlingSafeMethodsServlet, Method Detail: protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response). Available at: https://sling.apache.org/apidocs/sling11/org/apache/sling/api/servlets/SlingSafeMethodsServlet.html

3. Adobe Experience League, "Servlets in AEM": This official Adobe guide provides examples and best practices for creating servlets in AEM, reinforcing the use of Sling's base classes and correct method overriding.

Reference: Adobe Experience League, "Servlets", Section: "Creating a simple servlet". The examples consistently show public class MySafeMethodServlet extends SlingSafeMethodsServlet { ... protected void doGet(...) ... }. Available at: https://experienceleague.adobe.com/docs/experience-manager-65/developing/introduction/servlets.html?lang=en

Scroll to Top