What is webscript?
A Web Script is a service bound to a URL that responds to HTTP methods like GET, POST, PUT and DELETE.
A Webscript consists of the following three files:
A Webscript descriptor XML file.
Controller file: Either it can be a server-side JavaScript or Java backed.
Presentation file: Free Marker Template file.
In this article I show how to create a simple Java backed webscript for Alfresco Repository.
Step 1: Create a new Java project with the following structure:
Step 2: Extend the helloWorld.java using DeclarativeWebScript.
Step 3: Override the executeImpl method. In this method create a new HashMap object, add a greeting message and return it. Refer to the following image:
Step 4: Now, we need to create a webscript descriptor XML file ("helloWorld.get.desc.xml") in the "config/alfresco/extension/templates/webscripts/com/murali/webscripts" path.
Step 5: Now we need to create a simple FreeMarker Template file ("helloWorld.get.json.ftl") to render the output.
Step 6: Register the webscript bean like:
Step 7: Create the "module.properties" file in the "config/alfresco" path.
Step 8: Create the alfresco amp by using following build.xml file.
Step 13: Webscript output
Hope this helps someone !