AnsweredAssumed Answered

Java Backed Webscript

Question asked by samuel.penn on Feb 20, 2009
Latest reply on Feb 23, 2009 by samuel.penn
I'm trying to write a Java backed web script, and I'm running into issues trying to get the Java code called. As far as I can tell, the Java class is being linked to the webscript, and the class is being initialised, but the class isn't called when the webscript is invoked. This is all in Alfresco 2.2.1, running on MS Windows.

In Data Dictionary/Web Scripts/webtools:


<h1>${title!"No Title"}</h1>


  <shortname>Unlock Website</shortname>
  <description>Unlocks all files in website.</description>

In tomcat\shared\classes\alfresco\extension I have placed a centrom-scripts-context.xml:

<?xml version="1.0" encoding="UTF-8"?>

    <bean id="webscript.webtools.unlock.get" class="com.centrom.webscripts.Unlock" parent="webscript">

And in tomcat\webapps\alfresco\WEB-INF\classes\com\centrom\webscripts I haved placed Unlock.class, the source to which is:

package com.centrom.webscripts;

import java.util.*;
import org.alfresco.web.scripts.*;
import org.apache.log4j.Logger;

public class Unlock extends DeclarativeWebScript {
   static Logger logger = Logger.getLogger(Unlock.class);
   static {
      if (logger != null) {
         logger.error("Initiating webscript");
    protected Map<String, Object> executeImpl(WebScriptRequest req, WebScriptResponse res) throws IOException {
       logger.error("Called executeImpl web script Unlock");
       Map<String,Object>   model = new HashMap<String, Object>();
       model.put("title", "Hello World");
       model.put("count", 1);
       model.put("response", "Success");

       return model;

When the server starts up, I can see the debug for the static block in the class being called, so the class is being loaded. After refreshing the webscripts, I can pull back information on this web script which suggests that it has bound to the Java class.


Web Script: webtools/unlock.get
Alfresco Enterprise Network v2.2.1 (233)
Generated from /alfresco/wcservice/script/webtools/unlock.get on 20-Feb-2009 14:38:43

Script Properties
Id:   webtools/unlock.get
Short Name:   Unlock Website
Description:   Unlocks all files in website.
Authentication:   guest
Transaction:   required
Method:   GET
URL Template:   /webtools/unlock/{path}
Format Style:   any
Default Format:   html
Implementation:   class com.centrom.webscripts.Unlock

Store: workspace://SpacesStore/app:company_home/app:dictionary/cm:extensionwebscripts

[No implementation files]

Store: workspace://SpacesStore/app:company_home/app:dictionary/cm:webscripts

File: webtools/unlock.get.desc.xml

  <shortname>Unlock Website</shortname>
  <description>Unlocks all files in website.</description>

File: webtools/unlock.get.html.ftl

<h1>${title!"No Title"}</h1>

Store: classpath:/alfresco/templates/webscripts

[No implementation files]

The Implementation:   class com.centrom.webscripts.Unlock line to me suggests that the class has been picked up and linked to the webscript correctly.

However, when the webscript is called, I get "No Title" as the response, so the model variable 'title' hasn't been set. I also see no debug in the logs, which suggests that the class isn't actually being called. My understanding is that the variables title, count and response should be set and available to the freemarker template.

I've gone through the information on the wiki, and in the Alfresco Developers Guide book several times, but haven't been able to figure out what it is I'm missing. I assume it's something simple, but I'm stumped.

Any ideas greatly appreciated,