AnsweredAssumed Answered

Java-backed web script

Question asked by sihnu on Mar 30, 2015
Latest reply on Mar 30, 2015 by sihnu
Hey,

I've been working now with java-backed web script because I need some data manipulation I can't achieve with JavaScript. I followed these instructions https://wiki.alfresco.com/wiki/Java-backed_Web_Scripts_Samples#SimpleWebScript.java. So I've tried to implement SimpleWebScript with Java. I implemented the -context file to load the bean, the JAR file and description file and deployed them all to the server in the locations described in the guide. The webscript is loaded and recognized but when I call the url I got error message template file is missing. The webscript is not actually using any template. It should just write some simple JSON and that's all. I think my webscript is not running the execute method I've defined in my Java class. I'm quite sure about that. I've been trying to understand how the web script is actually supposed to call the method and I can't figure that out. How Alfresco knows what method inside which class it is supposed to call?

To make things easier for you here is the code:

SimpleWebscript.class

public class SimpleWebScript extends AbstractWebScript
{
    public void execute(WebScriptRequest req, WebScriptResponse res)
        throws IOException
    {
       …
    }   
}


web-scripts-application-context.xml
<bean id="webscript.org.alfresco.demo.simple.get" 
      class="org.alfresco.module.demoscripts.SimpleWebScript"
      parent="webscript">
</bean>


simple.get.desc.xml
<webscript>
  <shortname>The World's Simplest Webscript</shortname>
  <description>Hands back a little bit of JSON</description>
  <url>/demo/simple</url>
  <authentication>none</authentication>
  <format default="">argument</format>
  <family>Alfresco Java-Backed WebScripts Demo</family>
</webscript>


And this is the error message I get when calling the webscript:

<blockquote>Cannot locate template processor for template org/alfresco/demo/simple.get.html</blockquote>

Outcomes