cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco Share - Develop a webscript in JAVA

allen87
Champ in-the-making
Champ in-the-making
Hi everybody,

I would try to create a new webscript in JAVA not in Javascript only in Alfreso Share.
I try to refer to the link below :
http://wiki.alfresco.com/wiki/Java-backed_Web_Scripts_Samples

and especially about the locations files in Share :
.jar file in <tomcat>/webapps/share/WEB-INF/lib or .class files in <Alfresco>/tomcat/webapps/alfresco/WEB-INF/classes/<class folder structure>
web-scripts-application-context.xml - <tomcat>/webapps/share/WEB-INF/classes/org/springframework/extensions/webscripts
simple.get.desc.xml - <tomcat>/webapps/share/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/demo

I realize that when I connect to the URL http://localhost:8080/share/service/index , I can't find again a new webscript in the list.

Could someone give me more informations ?

Thanks so much for your help.
25 REPLIES 25

dejal33t
Champ in-the-making
Champ in-the-making
Hi,

Thanks for the reply. Yes I followed the instructions from this wiki page before I asked for help. I try example on Alfresco and works for me, but when I try same on Alfresco Share there is no new web scripts when I refresh web scripts list.

I add this:

1. New "web-scripts-application-context.xml" file in tomcat/webapps/share/WEB-INF/classes/org/springframework/extensions/webscripts/.
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN 2.0//EN' 'http://www.springframework.org/dtd/spring-beans-2.0.dtd'>

<beans>
      <bean id="webscript.org.springframework.extensions.webscripts.simple.get" class="org.alfresco.module.demoscripts.SimpleWebScript" parent="webscript" />
</beans>

2. "simple.get.desc.xml" file in tomcat/webapps/share/WEB-INF/classes/org/springframework/extensions/webscripts/.
<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="html"/>
    </webscript>

3. "simple.get.html.ftl" file at same location.
<html>
       <head>
          <title>Hello World</title>
       </head>
       <body>
          ${hello}
       </body>
    </html>

4. "SimpleWebScript.jar" file in tomcat/webapps/share/WEB-INF/lib/.
package org.alfresco.module.demoscripts;

import java.util.HashMap;
import java.util.Map;

import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;

public class SimpleWebScript extends DeclarativeWebScript {

    public SimpleWebScript() {
      
    }
   
    protected Map<String, Object> executeImpl(WebScriptRequest req,
          Status status) {
       Map<String, Object> model = new HashMap<String, Object>();
       model.put("hello", "Hello World");
       return model;
    }
}

Thanks.

ddraper
World-Class Innovator
World-Class Innovator
It looks like the problem is that you've placed your WebScript package folders (for the .desc.xml and .html.ftl) directly into the classpath which is not a location looked in by default.  If you place those files under "classes/webscripts" files (e.g. in tomcat/webapps/share/WEB-INF/classes/webscripts/org/springframework/extensions/webscripts/) then it should work.



Regards,
Dave

dejal33t
Champ in-the-making
Champ in-the-making
Thanks a lot, your reply was helpful, now works in Alfrescno Share too.
Thanks again.

ddraper
World-Class Innovator
World-Class Innovator
No problem - happy to help!

billwyuan
Champ in-the-making
Champ in-the-making
my helloworld.get.html.ftl,
${hello}
my helloworld.get.desc.xml
<webscript>
<shortname>Hello World</shortname>
<description>Hello world web script</description>
<url>/helloworld?name={nameArgument}</url>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

My java:
package org.alfresco.module.demoscripts;


import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.springframework.extensions.webscripts.AbstractWebScript;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;
import org.alfresco.service.cmr.repository.NodeRef.Status;
import org.json.JSONException;
import org.json.JSONObject;

public class SimpleWebScript extends DeclarativeWebScript {
    public SimpleWebScript() {

    }

    protected Map<String, Object> executeImpl(WebScriptRequest req,

          Status status) {

       Map<String, Object> model = new HashMap<String, Object>();

       model.put("hello", "Hello World");
       System.out.println("hello1");

       return model;

    }

}
My web-scripts-application-context.xml in C:\Alfresco\tomcat\webapps\alfresco\WEB-INF\classes\alfresco
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN 2.0//EN' 'http://www.springframework.org/dtd/spring-beans-2.0.dtd'>

<beans>

   <bean id="webscript.org.alfresco.demo.simple.get" class="org.alfresco.module.demoscripts.SimpleWebScript"
      parent="webscript" />
</beans>

The error I got:
13:26:46,907 ERROR [freemarker.runtime] Template processing error: "Expression hello is undefined on line 1, column 25 in simple.get.html.ftl."

Expression hello is undefined on line 1, column 25 in simple.get.html.ftl.
The problematic instruction:
———-
==> ${hello} [on line 1, column 23 in simple.get.html.ftl]

I don't have luck today.

aitbenmouh
Champ in-the-making
Champ in-the-making
Your context file should be in /web-extention and not /extention this one is for Alfresco explorer wish that can help.