官术网_书友最值得收藏!

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:

  1. Log in to Alfresco Share UI.
  2. Click on the Repository link from the top header.
  3. Go to Data Dictionary | Web Scripts Extensions.
  4. 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.

  5. Create a new file named helloworld.get.html.ftl with content as follows:
    <html>
      <body>
        <p>Hello world!</p>
      </body>
    </html>
  6. 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.
  7. 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.
  8. 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
主站蜘蛛池模板: 保山市| 师宗县| 翼城县| 山丹县| 磐石市| 原阳县| 阳高县| 库伦旗| 如东县| 双牌县| 清镇市| 民丰县| 行唐县| 丰原市| 潞西市| 蓬莱市| 宜春市| 浦东新区| 城步| 东乌珠穆沁旗| 新丰县| 区。| 萨嘎县| 五峰| 二连浩特市| 扎兰屯市| 三门县| 桃园市| 黄大仙区| 黑龙江省| 拉萨市| 平果县| 柘城县| 遂川县| 疏勒县| 扎鲁特旗| 恩平市| 龙门县| 炉霍县| 普安县| 禄丰县|