cancel
Showing results for 
Search instead for 
Did you mean: 

Java-backed web script

sihnu
Champ in-the-making
Champ in-the-making
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>
4 REPLIES 4

sihnu
Champ in-the-making
Champ in-the-making
The description in my starting post refers to when files are deployed according to Alfresco Share Standalone. Now I'm not sure if my Alfresco is really Share Standalone but it is version 4.2f so it's newer than 3.3 (in the documents it says 3.3 or greater). However, I've tried to deploy the files according to the other instruction also. But when I start my server I get this error:

<blockquote>SEVERE: Allocate exception for servlet apiServlet
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'webscripts.authenticator.basic' is defined</quote>

Looks like Alfresco is reading my context file but something is going wrong. I think Alfresco can't load my bean and then stops loading all the other beans as well and throws that error because can't find the bean used for authentication. Just a guess it might be like this.

pkie
Champ in-the-making
Champ in-the-making
Maybe it does need the template to render any GET response…

Try the newer tutorial - I've used it on 4.2f, and works good.
http://docs.alfresco.com/4.2/tasks/ws-folderListing-Java-scripting.html

Regards,

sihnu
Champ in-the-making
Champ in-the-making
Yes, it doesn't need a template but still it asking for one. I think it's because it's not running the execute method of the Java Class. Alfresco finds new web script from description file but not the execute method and that's why it's asking for the template. Anyway, I'm now trying out the tutorial you linked. I'll tell here how it goes. Thanks for the reply.

sihnu
Champ in-the-making
Champ in-the-making
Hey,

thanks for the tutorial. I got it working right away. I will use this as an example for my own web script. Thanks a lot!