Learning Alfresco Web Scripts Sample Chapter
Learning Alfresco Web Scripts Sample Chapter
Ramesh Chauhan
Chapter No. 1
"Getting Familiar with Web Scripts"
Acknowledgments
I would first like to extend my gratitude to Lord Swaminarayana and my guru, H. H.
Pramukh Swami Maharaj, for all the blessings. I would like to thank my mom and dad
for their unconditional love and support. Special thanks to my loving and caring wife,
Priyanka Chauhan, who has always encouraged me and supported me throughout the
journey of this book. Big thanks to my one-year-old daughter, Misri, who has been the
source of inspiration for me.
I would like to thank Packt Publishing for this opportunity. I would like to thank all the
technical reviewers for their valuable feedback and give my thanks to Kevin Colaco,
Priyanka Shah, and Nikhil Potdukhe from the Packt Publishing team. It was really nice
working with the entire Packt Publishing team. I sincerely appreciate Priyanka Shah,
the content development editor, and Nikhil Potdukhe, the technical editor, who helped
a lot in fixing my writing style with their valuable feedback.
I would like to thank our management team at CIGNEX Datamatics for encouraging me
to write this book as a part of the community contribution from our organization. My
sincere thanks to Mr. Munwar Shariff (CTO, CIGNEX Datamatics) for all his support.
I would also like to thank the entire Alfresco practice team at CIGNEX Datamatics for
being very supportive. Thanks to Aadit Majmudar for helping me whenever needed
while writing this book. I would like to thank Dhaval Joshi especially, who has been
my very good friend and colleague at CIGNEX Datamatics. He has always been with
me whenever I needed his help and input. Thanks to him and my friend, Chirayu Joshi,
for believing in me, supporting me, and motivating me to write this book.
[8]
Chapter 1
They respond to HTTP methods such as GET, POST, PUT, and DELETE
From a developer's point of view, web scripts have the following properties:
They would be the first choice when it comes to accessing the Alfresco
repository securely from external applications
From a business user's point of view, web scripts are useful as follows:
They bridge the gap between the business requirement and technical
implementation for building up business solutions with Alfresco
They are a unique way to implement the integration solutions on top of the
Alfresco repository
They are the backbone of the integration solution implementation with the
Alfresco repository
[9]
Chapter 1
Another important thing to note is, with the transaction support of web
scripts, it is possible to perform a set of operations together in a web script,
whereas in CMIS, there is a limitation for the transaction usage. It is possible
to execute each operation individually, but it is not possible to execute a set
of operations together in a single transaction as possible in web scripts.
SOAP-based web services are not preferable for the following reasons:
Scalability is a challenge
In a developer's opinion:
In essence:
Web scripts are a REST-based and powerful option to interact with the
Alfresco repository in comparison to the traditional SOAP-based web
services and CMIS alternatives
[ 11 ]
They are easy to develop and provide some of the most useful features such
as no server restart, no compilations, no complex installations, and no need
of a specific tool to develop them
All these points make web scripts the most preferred choice among developers
and architects when it comes to interacting with the Alfresco repository
You can develop customized web scripts as per your business requirement
In support projects:
Web scripts could be your savior when you are working on a support or
maintenance project to maintain the live system for your customers that
is built on Alfresco and has millions of records.
You might come across a range of issues, for example, updating existing
content to fix some data issues, deleting some unneeded content, getting the
required content matching with the criteria specified by the business team,
and so on. Web scripts can be used in such scenarios to serve these purposes.
Chapter 1
In general, web scripts can be used in all kinds of solutions, such as:
They can be used from an HTTP client such as a web browser and HTTP
client APIs
[ 13 ]
The model is a data structure object passed between the controller and view
The mapping of the web script URI to the controller is done through a descriptor file.
It is mainly an XML file that will have the required details for a web script such as
URL, description, arguments, transaction, authentication, and response formats.
Response formats are mapped to FreeMarker templates through naming conventions.
For example, a FreeMarker template that returns an HTML response will have the
extension html.ftl.
Web scripts are registered and executed by the web script engine in Alfresco.
A descriptor, optional controller, and one or more FreeMarker
response templates collectively make a web script in general scenarios.
All these components are tied together through a specific document
naming convention.
[ 14 ]
Chapter 1
If a Java-based controller is used for a web script, then the class file for the controller
must be available on the class path.
There are two types of controllers available for web scripts:
JavaScript-based controllers and Java-based controllers. It is
possible to have none of them, either of them, or even both
of them for a web script.
[ 15 ]
Presentation web scripts generally make a call to Data web scripts in order to get the
required data from the repository.
Out-of-the-box web scripts available in an Alfresco installation can
be found at ALFRESCO_HOME\tomcat\webapps\alfresco\
WEB-INF\classes\alfresco\templates\webscripts\org\
alfresco, where ALFRESCO_HOME is the base directory where
Alfresco is installed.
If you are using Alfresco Community 5, you can find out-of-thebox web scripts under the alfresco package inside alfrescoremote-api-*.jar, which is available at ALFRESCO_HOME\
tomcat\webapps\alfresco\WEB-INF\lib.
Summary
In this chapter, we gained a better understanding of web scripts through some
of the basic questions about web scripts. We learned what web scripts in Alfresco
are, why they are the preferred choice of developers, when and where we can use
web scripts, how web scripts work, and also the different types of web scripts
available in Alfresco.
In the next chapter, we are going to do a hands-on exercise to learn how to
implement our first web script in Alfresco.
[ 16 ]
Alternatively, you can buy the book from Amazon, BN.com, Computer Manuals and
most internet book retailers.
www.PacktPub.com