- Learning Alfresco Web Scripts
- Ramesh Chauhan
- 706字
- 2021-08-05 17:28:04
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 in general as it is not on the roadmap of Alfresco as no new implementations are being made in support of Alfresco Explorer, we will also not use Alfresco Explorer. Instead, we will use the Alfresco Share UI which is recommended to use in general.
Let's now create the web script. In order to create your first web script in Alfresco, follow these steps:
- Log in to Alfresco Share UI.
- Click on the Repository link from the top header.
- Go to Data Dictionary | Web Scripts Extensions.
- Create a new file named
helloworld.get.desc.xml
with content as follows:<webscript> <shortname>Hello World</shortname> <description>First webscript Hello world</description> <url>/helloworld</url> </webscript>
Tip
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
- Create a new file named
helloworld.get.html.ftl
with content as follows:<html> <body> <p>Hello world!</p> </body> </html>
- Now, hit the URL
http://localhost:8080/alfresco/service/index
in a browser. Provide the username and password to the authentication pop up displayed. Click on the Refresh Web Scripts button available at the bottom. - Click on the List Web Scripts link. You can see the Hello world web script by clicking on the Browse all Web Scripts link and search for
helloworld
. - Now, hit the URL
http://localhost:8080/alfresco/service/helloworld
. Here we go, you should see the output Hello world! rendered in your browser.
We have implemented the first web script in Alfresco. Now, let's try to understand what we have just done in order to implement the first web script. We first created the web script as follows:
- We implemented a GET web script to display Hello World! as the output
- We created the descriptor document
helloworld.get.desc.xml
for the web script - We also created the FreeMarker template
helloworld.get.html.ftl
to render the web script response
Note
In general, in order to create a web script in Alfresco, a minimum two files are required. One is the descriptor document and the other is FreeMarker template.
Next, we deployed the web script as follows:
- We have deployed the required files to create a web script in the Alfresco repository
- The descriptor document and FreeMarker template are placed in Data Dictionary | Web Scripts Extensions
Note
Web script files can be directly created/uploaded in the Alfresco repository in Data Dictionary | Web Scripts Extensions or web script files can be created and deployed on the filesystem through the code base as well.
We then registered the web script as follows:
- We hit the URL
http://localhost:8080/alfresco/service/index
and clicked on the Refresh Web Scripts button to register the first web script
Note
There are two ways to register a web script. One is through hitting the URL http://localhost:8080/alfresco/service/index
and clicking on the Refresh Web Scripts button. Another way is to deploy the web script files through the code base/repository and restart the server. A server restart will also register the web scripts.
Finally, we executed our first web script as follows:
- We invoked the web script from the web browser hitting the URL
http://localhost:8080/alfresco/service/helloworld
- The web script displayed an output as its response on a web browser
- JavaScript前端開發(fā)模塊化教程
- MATLAB圖像處理超級學(xué)習(xí)手冊
- Cocos2d-x學(xué)習(xí)筆記:完全掌握Lua API與游戲項目開發(fā) (未來書庫)
- Getting Started with Greenplum for Big Data Analytics
- C++從入門到精通(第5版)
- C# and .NET Core Test Driven Development
- JavaScript從入門到精通(視頻實戰(zhàn)版)
- Learning Unreal Engine Game Development
- C語言程序設(shè)計教程
- Android智能手機APP界面設(shè)計實戰(zhàn)教程
- Spring Boot從入門到實戰(zhàn)
- Python無監(jiān)督學(xué)習(xí)
- Developing Java Applications with Spring and Spring Boot
- 產(chǎn)品架構(gòu)評估原理與方法
- Swift 2 Design Patterns