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

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
主站蜘蛛池模板: 抚宁县| 剑川县| 阿尔山市| 兰溪市| 临颍县| 南丰县| 天镇县| 正宁县| 竹溪县| 苍山县| 中卫市| 通榆县| 岑溪市| 托里县| 临颍县| 凤冈县| 万年县| 安塞县| 香河县| 兴宁市| 北京市| 贵溪市| 泸水县| 扶余县| 宜黄县| 保康县| 加查县| 凤翔县| 定边县| 黔西| 永修县| 松溪县| 乐亭县| 上蔡县| 武陟县| 宿州市| 忻州市| 江源县| 米脂县| 建瓯市| 铁岭县|