Alfresco Javabacked Webscripts

Alfresco webscripts provide a great power to extend or consume Alfresco repository and thus make it easy to integrate with other web application or other repositories. Now we had seen most of the things about webscripts in these posts.

Here I will mainly focus on java based webscripts. Alfresco javabased webscript are called java backed because the controller of webscript is java class where all our business logic will reside and it will create model and forward it to the views (template files). Java backed webscripts are very powerful compare to other javascript based webscript because you can inject alfresco services within webscript bean definition because our backend java controller is nothing but a spring bean only and alfresco repository services are also created within spring so we can wire them up and utilize those services (nodeservice,cotentservice,authentication service etc…). These services has rich set of APIs available with them so using them we can manipulate repository to great extent.

There are two ways to implement java backend controller

Let us see main difference between both of above implementation in brief.

AbstactWebscript DeclarativeWebScript
Abstract Class Script/template driven based implementation of an Web Script
extends Object Class andimplements WebScript Interface  extends AbstractWebScript
Important Methods areExecute Important MethodsExecute,executeImpl,executeFinallyImpl,renderFormatTemplate
Here we can write directly to output because we have direct control over response object In this case we normally create model and pass it to the view and view will render output.



Sample Webscript Implementations

package com.arvixe.sample.webscripts;


import org.springframework.extensions.webscripts.AbstractWebScript;

import org.springframework.extensions.webscripts.WebScriptException;

import org.springframework.extensions.webscripts.WebScriptRequest;

import org.springframework.extensions.webscripts.WebScriptResponse;


public class MyAbstractWebScript extends AbstractWebScript


   public void execute(WebScriptRequest req, WebScriptResponse res)

       throws IOException



           //All your business logic goes here

           //Create json or xml response string here

       String responseStr;

           // write response string directly using response object





Declarative webscript example

package com.arvixe.sample.webscript;
import java.util.HashMap;
import java.util.Map;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest; 

public class MyDeclarativeWebscript extends DeclarativeWebScript {

   protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
     //put all the objects that you need in renditions to the model map
     // You can pass map of resultset nodeRefs so that they can be //iterated in ftl files

     Map<String, Object> model = new HashMap<String, Object>();
     model.put("test", "Testing string");
     return model;

Decelarative webscript has a big advantage over Abstract webscript because here we can pass model to view so we could have multiple different views for single webscript.


Looking for quality Alfresco Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , | Posted under Alfresco | RSS 2.0

Author Spotlight


I love opensource technologies working with those technologies from the time I have stepped in to the Software Industry. Alfresco CMS is my area of expertise. I have worked on various complex implementations which involved integration of Alfresco with other technologies, extensively worked with JBPM workflows and Webscripts.

2 Comments on Alfresco Javabacked Webscripts

  1. Aditya C says:

    Hi Thank you for good post ,
    Can you please help me to know how exactly to write this java code and use maven and eclipse to develop webscripts.?
    There are few posts on this but all of them confusing me on java backed webscripts.
    Your posts always helps me to understand easily.

Leave a Reply

Your email address will not be published. Required fields are marked *