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

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
主站蜘蛛池模板: 津南区| 安达市| 周口市| 保山市| 裕民县| 宁化县| 板桥市| 南昌市| 金沙县| 兴文县| 延吉市| 邵阳县| 冕宁县| 浑源县| 白沙| 桓仁| 临潭县| 平凉市| 泸定县| 筠连县| 商都县| 内丘县| 沙雅县| 南充市| 手机| 崇左市| 砀山县| 东宁县| 台东县| 资源县| 依安县| 馆陶县| 禹州市| 博野县| 雅安市| 东光县| 汉川市| 满城县| 平原县| 洛川县| 东山县|