Env. - AEM-Forms 6.5v, on-premise setup.
We want to use OutputService/ FormsService/ AssemblerService to generate a PDF using XML payload (coming from 3rd party system) and XDP template stored in AEM repository. So what is the best approach to expose this API as REST which will be hosted on AEM-Forms.
3rd party system will be calling AEM-Forms API with a xml payload to generate the PDF. Some of the searches suggested following [1], do let us know your opinions:
- A a path based Sling servlet with POST method
- an OSGi service
Solved! Go to Solution.
Views
Replies
Total Likes
This article has sample code and package that is ready to use
As you know, sling servlet is one of the options to expose functionality in a RESTful way. More details about the related method for each service are here[0], along with the javadocs.
You can review the reference implementation for the Assembler service[1] and Forms/Output service [2] and adapt these as per your use case.
The best approach for exposing the OutputService/FormsService/AssemblerService as a REST API hosted on AEM-Forms would likely be to create a custom Sling Servlet. The servlet should be configured to handle requests using the POST method, and should be able to process the XML payload from the 3rd party system and use it to generate a PDF using the XDP template stored in the AEM repository.
Alternatively, you can use an OSGi service with the same functionality, it will have the same functionality as the Sling Servlet. This will make the service available to other OSGi components in the system and can be easily configured and managed through the OSGi framework.
In either case, it is important to ensure that the API is properly secured and that only authorized 3rd party systems are able to access it.
You can refer to this article in case you want to see which servlet approach suits.
>> The best approach for exposing the OutputService/FormsService/AssemblerService as a REST API hosted on AEM-Forms would likely be to create a custom Sling Servlet. The servlet should be configured to handle requests using the POST method, and should be able to process the XML payload from the 3rd party system and use it to generate a PDF using the XDP template stored in the AEM repository.
Okay, I assume then path based sling servlet can be used here, which will be exposed as REST API (already tested with Postman) works fine.
@component(service = { Servlet.class }, property = { SLING_SERVLET_METHODS + "=POST",
SLING_SERVLET_EXTENSIONS + "=json", SLING_SERVLET_PATHS + "=/bin/generatePDFService" })
public class GeneratePDFService extends SlingAllMethodsServlet {
----
Document doc = outputService.generatePDFOutput(xdpDoc, xmlDoc, outputOptions);
---
}
This article has sample code and package that is ready to use
Views
Likes
Replies