Alfresco: Hello World Java Backed Webscript

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.
 

Create a Java backed webscript 

 
Step 1: Create a new Java project with the following structure:
 
Image1.jpg 
 
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:
 
Image 2.jpg 
 
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.
 
Image 3.jpg 
 
Step 5: Now we need to create a simple FreeMarker Template file ("helloWorld.get.json.ftl") to render the output.
 
Image4.jpg 
 
Step 6: Register the webscript bean like:
 
Image5.jpg 
 
Step 7: Create the "module.properties" file in the "config/alfresco" path.
 
Image6.jpg 
 
Step 8: Create the alfresco amp by using following build.xml file.
 
Image7.jpg
 
 
Step 9: Install the amp, delete the exploded directory of Alfresco.
 
 
Step 10: Restart Tomcat.
 
 
Step 12: Search for your "/com/murali/webscripts" package and click "GET /alfresco/service/com/murali/webscripts/helloWorld/" URL to invoke the webscript.
 
Image8.jpg 
 
Step 13: Webscript output
 
Image9.jpg 
 
Hope this helps someone!


Similar Articles