/* InfoAxon GA Code */
Alfresco One: Content Management in the Cloud (Part II)
December 18, 2012 – 1:55 pm | No Comment

Alfresco Universe has a number of client applications and protocols available which can be used by your external users making this a truly Cloud Content Enterprise Content Management System.
For example,

Alfresco iOS Client App: for iPhone …

Read the full story »
Home » Open Source Tutorials

Tutorial: Building Alfresco web scripts, deploying as Liferay Portlets – Part 2

Submitted bySnig Bhaumik on October 3, 2009 – 6:24 am4 Comments

Creating a Web Script using JavaScript API

Step 1: Define the Web Script

As you know, to define a web script, we need to have:

  1. A description xml file, in our case the name would be helloworld.get.desc.xml
  2. An FTL file generating HTML code, in our case the name would be helloworld.get.html.ftl
  3. A JS file, in our case the name would be helloworld.get.js. Note that, this JS is technically not mandatory; however, in practical situation you cannot live without this, because this is only place where you write the business logic of your web script, and return some data.

These files need to be created in C:\mystackroot\webapps\alfresco\WEB-INF\classes\alfresco\templates\webscripts\ folder hierarchy.

  • Create subfolder hierarchy com\infoaxon\repository under C:\mystackroot\webapps\alfresco\WEB-INF\classes\alfresco\templates\webscripts\ folder.
  • Note that, maintaining this folder hierarchy is not mandatory; this is just because of good practice to group your web scripts. Technically as per alfresco, it will pick up all items which are defined as web scripts under the templates\webscripts\ folder.
  • Under the repository folder, create the following three files:
  • helloworld.get.desc.xml

    <webscript>
    <shortname>helloworld</shortname>
    <description>helloworld</description>
    <url>/infoaxon/helloworld</url>
    </webscript>
    

    helloworld.get.html.ftl
    <html>
    <body>
    <p>Wow, this is quite ${jstext}, rather.</p>
    </body>
    </html>

    helloworld.get.js

    Step 2: Start Server, Test your Web Script

    That’s it, that’s really it, you have just created your first JavaScript based custom web script.

    • Start your server
    • In your favourite browser, navigate to http://localhost:8080/alfresco/service/index. Find your web script and test whether it is working, but just clicking on it.
    • Since, you have created a HTTP GET Web Script, you can invoke and test the service by typing URL in your browser http://localhost:8080/alfresco/service/infoaxon/helloworld. Note that, this is the URL which you have defined in your configuration XML file.

    In the next installment of this tutorial, we will discuss about how we can create a simple helloworld web script using java.

    About The Author

    Snig Bhaumik

    Mr. Snigdhendu Bikas Bhaumik is the Technical Director and Heads the Research and Development for InfoAxon. As an Open Source enthusiast, Snig is an active contributor of several open source communities such as - Alfresco ECM (Author of Alfresco Calendar components now included and distributed in Alfresco version 3.0), Liferay Portal and Pentaho Business Intelligence Suite. Snig has just completed a book on Alfresco published by Packtpub - http://www.packtpub.com/alfresco-3-cookbook/book. Snig specializes in Knowledge Management and Business Intelligence domains, and responsible for designing and architecting InfoAxon’s KM and BI solution offerings. He holds an enriching experience of around 12 years in designing, architecting and developing various solutions on open source technologies. Follow him on twitter - @snigbb.

    4 Comments »

    • Mahesh says:

      Your tutorial is very good for understanding the concept.
      But i want to know step by step for -
      How to deploy javascript based webscript as a life ray portlet?

    • Snig Bhaumik says:

      Please see the tutorial series part-4.

    • Animesh Kashyap says:

      I am working on POC for document search in alfresco. Do you have one working copy(Example) that can help despite of helloworld. I have developehd one bu t not able to retreive docs..

      Thanks in advance

    • Snig Bhaumik says:

      Hi Animesh

      Can you describe your requirement in more detail?
      Where from you want to search documents? Since alfresco of course offers extensive search capability from both the Explorer interface as well as from Share interface.

      Do you want to perform search via web scripts, in portlets etc?

      Thanks
      Snig.

    Leave a comment!

    Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

    Be nice. Keep it clean. Stay on topic. No spam.

    You can use these tags:
    <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.