Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning Alfresco Web Scripts
Learning Alfresco Web Scripts

Learning Alfresco Web Scripts: Learn a powerful way to successfully implement unique integration solutions with Alfresco

By Ramesh Chauhan
€19.99 €13.98
Book Nov 2014 182 pages 1st Edition
eBook
€19.99 €13.98
Print
€24.99
Subscription
€14.99 Monthly
eBook
€19.99 €13.98
Print
€24.99
Subscription
€14.99 Monthly

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Nov 7, 2014
Length 182 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781784390600
Category :
Concepts :
Table of content icon View table of contents Preview book icon Preview Book

Learning Alfresco Web Scripts

Chapter 1. Getting Familiar with Web Scripts

In this chapter, we will cover the following topics:

  • Understanding web scripts

  • Reasons to use web scripts

  • Understanding when to use a web script

  • Understanding where web scripts can be used

  • Understanding how web scripts work

  • Types of web scripts

Consider a scenario where you have to work on a project to develop a customized business solution with a backend repository such as an Alfresco content management system. It is going to be an integration project with the Alfresco content repository. The end goal is to build up a business implementation that has a custom frontend application interacting with the Alfresco repository in a secure way in order to allow the end users to access the content on demand and to provide access to features of the Alfresco repository. Basically, you want to create, update, and delete content in the Alfresco repository and are interested in retrieving the required content on demand from the Alfresco repository from the custom frontend application in a secure way.

Now, you might have a lot of questions on your mind. You must be curious to find out how it is possible to access the Alfresco repository from the custom frontend application. What are the possible alternatives to access the content residing in the Alfresco repository from the custom frontend application? Is it going to be a complex implementation to build up an API accessing the Alfresco repository? Is it going to be a secure communication from the frontend application to the backend repository? How is it going to maintain the client state during the communication with the Alfresco repository in order to access, update, or delete content from the repository based on the user's access? And the list of questions still goes on…

Whenever there is a question, there is an answer. Also, the answer to all of your previous questions is Alfresco web scripts. Using web scripts, you can build up a customized integration solution using Alfresco as the backend content repository.

It is always a good idea when we start learning about any new topic to always start with the "5Ws and 1H". It's basically the who, what, when, why, where, and how questions. This helps us to understand the topic in a better way. In this chapter, we are going to find out the useful information about web scripts by discovering the answers to some of the basic questions such as what, why, when, where, and how. Let's start and find out the answers to them and understand web scripts in a better way.

Understanding web scripts


In order to understand web scripts in Alfresco, let's begin with finding out the answer to the question "What is a web script?" from multiple perspectives.

In simple words, web scripts can be explained as follows:

  • Web scripts are powerful and extremely useful services supported by Alfresco

  • They are a way to interact with the Alfresco repository securely

  • They are reusable across different platforms

  • Web scripts provide uniform access of the content to a wide range of client applications

In technical terms, web scripts can be defined as follows:

  • They are RESTful web services

    Note

    What is RESTful?

    REST stands for REpresentational State Transfer, which is basically an architectural style. Well-defined and uniform access to the resources through HTTP request methods, uniquely identified resources through the URI, and representation of these resources are the key principles of REST. Any implementation following this architectural style is known as RESTful.

  • They are bound to a specific Uniform Resource Identifier (URI)

  • They respond to HTTP methods such as GET, POST, PUT, and DELETE

  • They are a lightweight implementation

From a developer's point of view, web scripts have the following properties:

  • They are easy to understand and learn

  • They are easy to develop

  • They are easy to debug

  • They are easy to maintain

  • They are easy to deploy

  • They are faster to implement

  • 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 empower Alfresco in its integration capabilities to develop useful Alfresco integration solutions with external systems

  • 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

In essence, web scripts can be talked about as follows:

  • Web scripts are built on the idea of URL addressability

  • Web scripts are simply a service, mapped to a human-readable form, and developed using a piece of code as their backend implementation

  • For example, in a contract management system built using Alfresco as the backend repository, you can have a web script to retrieve all the draft agreements from the repository and then display them on the custom frontend application. This repository web script to get all the draft agreements will simply be accessed through its URL. This web script will also have a piece of code in the backend to retrieve the data from the Alfresco repository to produce the results in the formats as required. The URL for this web script might look like the following:

    /alfresco/service/contract/get_draft_agreements

Reasons to use web scripts


It's now time to discover the answer to the next question—why web scripts? There are various alternate approaches available to interact with the Alfresco repository, such as CMIS, SOAP-based web services, and web scripts. Generally, web scripts are always chosen as a preferred option among developers and architects when it comes to interacting with the Alfresco repository from an external application. Let's take a look at the various reasons behind choosing a web script as an option instead of CMIS and SOAP-based web services.

In comparison with CMIS, web scripts are explained as follows:

  • In general, CMIS is a generic implementation, and it basically provides a common set of services to interact with any content repository. It does not attempt to incorporate the services that expose all features of each and every content repository. It basically tries to cover a basic common set of functionalities for interacting with any content repository and provide the services to access such functionalities.

  • Alfresco provides an implementation of CMIS for interacting with the Alfresco repository. Having a common set of repository functionalities exposed using CMIS implementation, it may be possible that sometimes CMIS will not do everything that you are aiming to do when working with the Alfresco repository. While with web scripts, it will be possible to do the things you are planning to implement and access the Alfresco repository as required. Hence, one of the best alternatives is to use Alfresco web scripts in this case and develop custom APIs as required, using the Alfresco web scripts.

  • 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:

  • It takes a long time to develop them

  • They depend on SOAP

  • Heavier client-side requirements

  • They need to maintain the resource directory

  • Scalability is a challenge

  • They only support XML

In comparison, web scripts have the following properties:

  • There are no complex specifications

  • There is no dependency on SOAP

  • There is no need to maintain the resource directory

  • They are more scalable as there is no need to maintain session state

  • They are a lightweight implementation

  • They are simple and easy to develop

  • They support multiple formats

In a developer's opinion:

  • They can be easily developed using any text editor

  • No compilations required when using scripting language

  • No need for server restarts when using scripting language

  • No complex installations required

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

  • They provide RESTful access to the content residing in the Alfresco repository and provide uniform access to a wide range of client applications

  • 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

Understanding when to use a web script


Having understood what a web script is and the reasons for using web scripts, let's now understand when to use web scripts. When working with Alfresco, it is important to know in which scenarios web scripts can be used. Web scripts allow you to build custom URI-identified and HTTP-accessible Content Management Web services to access the Alfresco content repository, and hence they can be used in various kinds of implementations to build useful business solutions with Alfresco content management systems.

In development projects:

  • You can use web scripts to develop business implementations integrating Alfresco with external applications

  • You can develop customized web scripts as per your business requirement

  • You can leverage on the out-of-the-box web scripts available in Alfresco wherever they fit in your custom implementation

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.

  • On a live production system, it is not possible to restart the server, and restarting a server could impact the business of a customer. Consider a scenario where you need to fix some critical issues on a production system and you are looking for an option to have the issue fixed without restarting the server. The powerful feature of web scripts to interact with the Alfresco repository without restarting the server will help you in this case, and you can fix some critical issues using web scripts to provide a good content management experience to the business users.

In general, web scripts can be used in all kinds of solutions, such as:

  • Integrating Alfresco with external applications that can communicate with Alfresco using HTTP

  • Developing JSR-168 portlets to build up UI services

  • Developing data services

  • Providing feeds for repository content

  • Alfresco integration with Office

  • Developing Facebook applications

  • Building UI components in Alfresco SURF

Understanding where web scripts can be used


Now, it's time to understand where web scripts can be used. There are a number of different environments from where a web script can be accessed and used.

In different environments:

  • They can be used from an HTTP client such as a web browser and HTTP client APIs

  • It is also possible to access web scripts in JSF pages

  • They can be used in JSR-168 portals

  • They can be used from Facebook applications

  • Web scripts can be used in the Alfresco SURF platform as well

Understanding how web scripts work


Web scripts in Alfresco mostly use the model-view-controller pattern. However, it isn't mandatory to follow this pattern all the time. The way MVC pattern works in web scripts is as follows:

  • The controller is responsible for performing the required business logic as per the business requirement. After processing the business logic, controller populates the model object with the required data. Once this is done, controller will then forward the request to the view.

MVC in web scripts

The model-view-controller pattern in web scripts is explained as follows:

  • The controller is a server-side JavaScript or Java class or it could be both as well

  • The model is a data structure object passed between the controller and view

  • The view is a FreeMarker template that is responsible for generating the response in the required format

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.

Note

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.

Making web scripts work

To make web scripts work, it is important to deploy the web script files at an appropriate location.

The descriptor file and the FreeMarker template as per the response format for a web script can be either placed on a filesystem or put into the Alfresco repository.

If a JavaScript-based controller is used for a web script, then it could be placed along with the descriptor and FreeMarker template on a filesystem or in the Alfresco repository.

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.

Note

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.

Types of web scripts


There are two types of web script in Alfresco: Data web scripts and Presentation web scripts.

Data web script

Data web scripts provide an interface to the repository for the client applications to create, retrieve, update, and delete content/data in the repository. These web scripts typically send the response in formats such as XML and JSON, and client applications will have to parse it in order to use it further.

Data web scripts encapsulate access and modification of content/data residing in the repository. These web scripts are provided and exposed by the Alfresco repository server only.

Presentation web script

Presentation web scripts can be used to build user interfaces such as dashlets for Alfresco explorer, dashlets for Alfresco share, portlets for a JSR-168 portal, a UI component within Alfresco SURF, or a custom application.

These kinds of web scripts generally render HTML responses.

It is possible to host these web scripts on a separate presentation server or they can also be exposed by the Alfresco repository server.

Presentation web scripts generally make a call to Data web scripts in order to get the required data from the repository.

Note

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-the-box web scripts under the alfresco package inside alfresco-remote-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.

Left arrow icon Right arrow icon

Key benefits

What you will learn

Implement web scripts in Alfresco and learn about their fundamentals Understand the endtoend execution flow with core details and get an insight into the robust web script framework Gain extensive knowledge about the building components of web scripts Explore different options to invoke Alfresco web scripts Leverage the power of useful JavaScript APIs in web script implementation Understand various deployment options, debugging techniques, and troubleshooting pointers Learn about extension capabilities to extend the web script framework

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Nov 7, 2014
Length 182 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781784390600
Category :
Concepts :

Table of Contents

18 Chapters
Learning Alfresco Web Scripts Chevron down icon Chevron up icon
Credits Chevron down icon Chevron up icon
About the Author Chevron down icon Chevron up icon
Acknowledgments Chevron down icon Chevron up icon
About the Reviewers Chevron down icon Chevron up icon
www.PacktPub.com Chevron down icon Chevron up icon
Preface Chevron down icon Chevron up icon
Getting Familiar with Web Scripts Chevron down icon Chevron up icon
It's Time for the First Web Script Chevron down icon Chevron up icon
Understanding the Web Script Framework Chevron down icon Chevron up icon
Building Blocks of Web Scripts Chevron down icon Chevron up icon
Invoking Web Scripts Chevron down icon Chevron up icon
Creating Java-backed Web Scripts Chevron down icon Chevron up icon
Understanding JavaScript-based Web Scripts in Detail Chevron down icon Chevron up icon
Deployment, Debugging, and Troubleshooting Web Scripts Chevron down icon Chevron up icon
Mavenizing Web Scripts Chevron down icon Chevron up icon
Extending the Web Script Framework Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.