Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
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

eBook
€8.99 €19.99
Paperback
€24.99
Subscription
Free Trial
Renews at €18.99p/m

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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Learning Alfresco Web Scripts

Chapter 2. It's Time for the First Web Script

In this chapter, we will cover the following topics:

  • How to create a simple web script in Alfresco step by step
  • The implementation of the first web script
  • Extending the first web script to add a controller
  • What happens behind the scene of a web script hit
  • The most important things for any web script

It's now time to practically implement your first web script in Alfresco and get more familiar with Alfresco web script implementation. This chapter will help you get a clear understanding on how to create a simple web script in Alfresco, how to extend web script with controller implementation, and some fundamental things about web script implementation that are very important to know while working on Alfresco web scripts.

Consider a scenario where you are managing the project execution of developing an integration solution of a custom frontend application with Alfresco as backend repository. Now, you have been allocated a new developer...

Creating your first web script in Alfresco

Whenever we start learning about any new programming language, the first program we implement is the "Hello world" program wherein we simply print the text Hello world as the output of the program. We will also do the same thing here. We will create a basic web script in Alfresco that will simply display Hello world! as the output of the web script.

In order to create a basic and simple web script in Alfresco, you will need to have a descriptor for the web script and a FreeMarker template to render the output of the web script.

Web scripts can be created from the available Alfresco user interfaces or you can have them developed outside of Alfresco and then deploy them. As we are going to implement a very basic web script here, we will use the Alfresco user interface option and will create a web script. You can either use Alfresco Explorer web client or Alfresco Share UI for this. However, as Alfresco Explorer is now not being encouraged...

Understanding the web script URI

It is important to understand the web script URI. The way the web script URI can be represented in a generic form is http[s]://<host>:<port>/[<contextPath>/]/<servicePath>[/<scriptPath>][?<scriptArgs>]

The terms used in the web script URI are explained as follows:

  • http[s]: This is the protocol to invoke the web script. This could be either http or https.
  • host: This is the name or address of the server where the web script is deployed.
  • port: This is the port where the web script is exposed on the server hosting the web scripts.
  • contextPath: This is the path where the application is deployed to. For data web scripts, this would generally be /alfresco.
  • servicePath: This is the path where the web script service is mapped with. Generally, this would be /service.
  • scriptPath: This is the path to the web script as defined in the web script descriptor document *.desc.xml under the <url> tag.
  • scriptArgs: These are the arguments to...

Adding arguments to a web script

Let's say we want to modify our first web script to display the name too in the web script response, for example, Hello! Ramesh. It can be done in a simple way by passing the name as the URL argument of the web script and then using this argument to generate the response in the FreeMarker template. In order to do this, we will have to perform the following steps:

  1. Log in to Alfresco Share UI.
  2. Click on the Repository link from the top header.
  3. Edit the descriptor file helloworld.get.desc.xml at Data Dictionary | Web Scripts Extension location as follows:
    <webscript>
      <shortname>Hello World</shortname>
      <description>First webscript Hello world</description>
      <url>/helloworld?name={argumentName}</url>
    </webscript>
  4. Edit the FreeMarker template helloworld.get.html.ftl at Data Dictionary | Web Scripts Extension as follows:
    <html>
      <body>
        <p>Hello! ${args.name}.</p>
      </body>
    &lt...

Extending the first web script to use the controller

The web script framework in Alfresco makes it easy to have a clear separation of concerns by following a model-view-controller pattern in order to develop a web script. All the business logic resides in the controller and it is possible to have multiple views as required to return the response in different response formats supported by the web script framework in Alfresco. The model object is a data structure used to pass information from the controller to the view. The controller populates the model object with the required data and passes it to the view to generate the response.

In the first web script, we created a basic and simple web script, which just renders the output without interacting with the Alfresco repository. Ideally, any processing related to business logic such as querying the Alfresco repository, creation of content, updating content, deleting content from the repository, and executing actions should be done in a controller...

Behind the scenes of web script execution

Let's try to understand at a high level what happens on a web script being hit in different scenarios such as when a web script does not have a controller and when it does.

A web script without a controller

To execute the first web script we created without controller, we just hit the URL http://localhost:8080/alfresco/service/helloworld?name=Ramesh on a web browser, which is basically a HTTP GET request call.

All the incoming requests matching the URL pattern /alfresco/service/* are mapped to the web script request dispatcher servlet in the Alfresco web application configuration.

The servlet then passed the request to the Web Script Runtime to process the web script.

The Web Script Runtime passed the control to the Web Script Container. The Web Script Container internally identified which web script to execute based on the invoked web script URL, HTTP method, and the web script descriptor document helloworld.get.desc.xml.

We have not specified any...

Creating your first web script in Alfresco


Whenever we start learning about any new programming language, the first program we implement is the "Hello world" program wherein we simply print the text Hello world as the output of the program. We will also do the same thing here. We will create a basic web script in Alfresco that will simply display Hello world! as the output of the web script.

In order to create a basic and simple web script in Alfresco, you will need to have a descriptor for the web script and a FreeMarker template to render the output of the web script.

Web scripts can be created from the available Alfresco user interfaces or you can have them developed outside of Alfresco and then deploy them. As we are going to implement a very basic web script here, we will use the Alfresco user interface option and will create a web script. You can either use Alfresco Explorer web client or Alfresco Share UI for this. However, as Alfresco Explorer is now not being encouraged to be used...

Understanding the web script URI


It is important to understand the web script URI. The way the web script URI can be represented in a generic form is http[s]://<host>:<port>/[<contextPath>/]/<servicePath>[/<scriptPath>][?<scriptArgs>]

The terms used in the web script URI are explained as follows:

  • http[s]: This is the protocol to invoke the web script. This could be either http or https.

  • host: This is the name or address of the server where the web script is deployed.

  • port: This is the port where the web script is exposed on the server hosting the web scripts.

  • contextPath: This is the path where the application is deployed to. For data web scripts, this would generally be /alfresco.

  • servicePath: This is the path where the web script service is mapped with. Generally, this would be /service.

  • scriptPath: This is the path to the web script as defined in the web script descriptor document *.desc.xml under the <url> tag.

  • scriptArgs: These are the arguments...

Left arrow icon Right arrow icon

Description

If you are an Alfresco developer who has no experience with web scripts and you want to start developing Alfresco web scripts, then this book is definitely for you.

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

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 07, 2014
Length: 182 pages
Edition : 1st
Language : English
ISBN-13 : 9781784390624
Concepts :
Tools :

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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Nov 07, 2014
Length: 182 pages
Edition : 1st
Language : English
ISBN-13 : 9781784390624
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 76.97
Alfresco CMIS
€26.99
Learning Alfresco Web Scripts
€24.99
Alfresco for Administrators
€24.99
Total 76.97 Stars icon
Banner background image

Table of Contents

11 Chapters
1. Getting Familiar with Web Scripts Chevron down icon Chevron up icon
2. It's Time for the First Web Script Chevron down icon Chevron up icon
3. Understanding the Web Script Framework Chevron down icon Chevron up icon
4. Building Blocks of Web Scripts Chevron down icon Chevron up icon
5. Invoking Web Scripts Chevron down icon Chevron up icon
6. Creating Java-backed Web Scripts Chevron down icon Chevron up icon
7. Understanding JavaScript-based Web Scripts in Detail Chevron down icon Chevron up icon
8. Deployment, Debugging, and Troubleshooting Web Scripts Chevron down icon Chevron up icon
9. Mavenizing Web Scripts Chevron down icon Chevron up icon
10. Extending the Web Script Framework Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5
(4 Ratings)
5 star 50%
4 star 50%
3 star 0%
2 star 0%
1 star 0%
Paolo Predonzani Dec 11, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
"Learning Alfresco Web Scripts" was published just a few weeks ago. I bought it, quickly read the interesting bits, then re-read it from cover to cover. Overall this book covers the core webscript skills well and is appealing to both beginners and experts. Beginners will find all the tutorials and introductory material to get started. Experts will come back to this book for the depth of the more technical topics.Any book on the subject is expected to guide the readers in the steps to set up their first webscript. "Learning Alfresco Web Scripts" does a good job at introducing the parts that make up a webscript (the descriptor, the Freemarker template, the Javascript controller, the config xml file, the i18n bundles), clearly explaining which are required and which are optional, and guiding in the webscript installation and testing.Then the book illustrates the fundamental knowledge, tools and techniques that a developer has to master to become an Alfresco developer.The technical level is good. Often the book points to and explains Alfresco's source code as a source of examples and inspiration. A nice bottom-up approach that experienced developers will appreciate.
Amazon Verified review Amazon
Amita Bhandari Dec 27, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Packt sent me a free copy of Ramesh Chauhan's Book "Learning Alfresco Web Scripts" , to read and review.I have just finished up my reading and thought of writing a quick review on the book.First thing which came to my mind while reading the book is "Thankfully someone thought of writing book on this topic". I have never found good documentation about web scripts along with covering all the aspects of web scripts at one place. I was also curious to learn more about this topic as I have been working in Alfresco for many years and have experienced importance and need of web script in all my projects. This book will be more useful to developers who are using Alfresco as a backend and wants to use web script to interact with frond end application. You will get most from the book if you don't have prior experience on writing Web Scripts.This book is very well written and flows logically from one chapter to next and it covers pretty much all you need to know as a developer. This book is completely technical and I like reading behind scenes in terms of implementation of the web scripts and how and when those should be apply in different situations .I could tell a lot of effort might have gone to put all this together. I would request reader to especially read the Notes section, it makes use of informative tips that would be real help while implementing complex web scripts.In the first chapter I found a good overview about web scripts and more importantly it explains benefits of using web scripts for developer and business users. I also appreciate the section that describes its implementation in support and developing projects.Though second chapter is titled as "It's Time for the First Web Script" and seems to be simple and easy , but the fact is author has added minute details that needs to be taken care of while implementing web scripts for e.g. importance of naming convention and so on. The concepts are well explained with examples and understanding them will be easy.I found Chapter three and tenth to be little heavy for first time web scripts developers and if you want you may skip this chapter and read it later on when you have become quiet proficient in implementing web scripts. The author has moved into more technical detail about the web script framework. Experienced developers would surely appreciate this detailed technical insight.Chapter fourth is the must to be read chapter for web script developers that explains different components of the web scripts in detail. The chapter shows details about description document, Java-backed/Java Script Controller, Internationalization, configuration Document. I am glad author picked configuration Document topic also, which is rarely discussed but is useful for setting up dynamic values. Author has given well defined explanation for mandatory and optional things about web script components.Fifth chapter is all about invoking web scripts. Knowing web scripts will be of no use unless we know how to invoke them. Two applications can integrate seamlessly using web scripts. Author has covered all the basic details about invoking web scripts from different environments, however, I think author should have picked more strong examples about integration of Alfresco with other application using Web Scripts. This is just my perspective.Next two chapters explain about the controller of web scripts. I think these two chapters should have moved before chapter Fifth. Few sections are really interesting in this chapter like "how to use controllers smartly", "Difference in DeclarativeWebScript and AbstractWebScript ", "how to make use of root objects" ,"creating your own root objects" and such sections make the book helpful in true aspect.In Case you are looking for debugging and troubleshooting tips, Chapter Eights present useful pointers about it and also explain deployment options for Web Scripts. Trouble shooting tips makes this chapter really interesting where it gives pointers on common issues come across while executing Web Scripts. Another section that draws my attention is "Running Web Scripts in the background" and "Logging Web Scripts logs separately". These topics are of great help when web scripts are running for longer time and details need to be capture in the log.If you want to setup a project then chapter nine will get you going with this as it discusses how to package project using maven and deploying through amp.To sum this up I would definitely recommend this book to anyone new to Alfresco Web Scripts. The technical level of the book is perfect for anyone who wants to understand and implement web scripts The book also help reader to understand how web scripts can be package, deployed, execute and debugged for production environment. Length of chapters is also fine in terms of reading and can be finish in one sitting. Overall must book to read if you are Alfresco developer.You can get more details about the book from https://www.packtpub.com/web-development/learning-alfresco-web-scripts
Amazon Verified review Amazon
Pablo Azevedo Dec 15, 2014
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Great book for anyone who wants to learn more about Alfresco development. Teaches step - by-step how to start with web scripts and features more advanced styles of use of web scripts.It has several code snippets and detailed explanations of the same.The only failure is the lack of illustrative images on the outcome of the examples .
Amazon Verified review Amazon
Johnny Gee Feb 06, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Ramesh Chauhan's writing style is very conversational - similar to a teacher speaking to a student. This took me some time to get used to, but eventually, I stopped noticing it and the content spoke to me.I got the most value out of the book from Chapters 3 & 6. the author created several diagrams that showed the execution flow of web script. This was very helpful for me, since I am picture person. Then in Chapter 6, Ramesh presents an example of web script that a developer might want to build. He starts with requirements, goes into how to design it, and them discusses the details about the actual coding. He also describes various test cases that one should take into account when building a web script. This is something that very few writers even think to write about.In summary, I think the author had a good goal in writing this book; however, the execution left a lot to be desired. I really liked Chapter 6 and I wished Ramesh spent more effort creating/explaining more examples.
Amazon Verified review Amazon
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.