Highlighted

Register Sling Servlet in Adobe Experience Manager | AEM Community Blog Seeding

kautuk_sahni

Community Manager

09-09-2020

BlogImage.jpg

Register Sling Servlet in Adobe Experience Manager by Victor Leung

Abstract

In Adobe Experience Manager (AEM), a Sling servlet can be used for handling some RESTful request-responses ajax call. It is written in Java programming language and it can be registered as OSGi (Open Services Gateway Initiative) services. In order to trigger the script, there are two ways to register it: 1. By Path or 2. By resourcesTypes and I will explain in details below:
1. Register by Path
Say for example, you want to do a form POST request to the path /bin/payment from client side to the sling servlet class, you may use the annotation below:
@SlingServlet {
metatype = true,
methods = { "POST" },
paths = "/bin/payment"
}
public class YourServlet extends SlingSafeMethodsServlet {

@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throw ServletException {
// do your work here
}
}
Then when there is a POST request to the http://localhost:4502/bin/payment, the above servlet would be trigger and the doPost method is invoked.
The prerequisites is that you have the local AEM up and running at the port 4502 and installed the bundle module via the maven bundle plugin. You may check the bundle is installed by navigating to the http://localhost:4502/system/console/bundles. If not, you may also manually upload the jar to install.

Read Full Blog

Register Sling Servlet in Adobe Experience Manager

Q&A

Please use this thread to ask the related questions.

AEM AEMEBlogSeeding Experience Manager