Problem on Java approach to web scripts not working

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2013 12:52 PM
Hello, a similar issue was posted before, but it happens again, it can't invoke java from freemark template.
With a simple java class in default Alfresco 4.1.3, tomcat, the server can't recognize java.
When hit URL: http://localhost:8080/alfresco/service/demo/simple
Got this message:
"message" : "03230014 Wrapped Exception (with status template): 03230099 Error during processing of the template 'Expression demo is undefined on line 5, column 15 in simple.get.json.ftl.'. Please contact your system administrator.",
"exception" : "org.springframework.extensions.webscripts.WebScriptException - 03230014 Wrapped Exception (with status template): 03230099 Error during processing of the template 'Expression demo is undefined on line 5, column 15 in simple.get.json.ftl.'. Please contact your system administrator.",
1. My Java class:
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 SimpleWebScript extends DeclarativeWebScript {
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req,
Status status, Cache cache) {
// put all the objects that you need in renditions to the model map
Map<String, Object> model = new HashMap<String, Object>();
model.put("demo", "Happy coding!
");
System.out.println("hello1");
return model;
}
}
2. My bean descrption: web-scripts-application-context.xml
<beans>
<bean id="webscript.org.alfresco.demo.simple.get" class="org.alfresco.module.demoscripts.SimpleWebScript"
parent="webscript">
</bean>
<bean id="webscript.org.alfresco.demo.declarative.get"
class="org.alfresco.module.demoscripts.SimpleDeclarativeWebscript"
parent="webscript">
</bean>
</beans>
3.My webscript desc: 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="json">argument</format>
<family>Alfresco Java-Backed WebScripts Demo</family>
</webscript>
4. simple.get.json.ftl
{
"demo": "${demo}",
}
With a simple java class in default Alfresco 4.1.3, tomcat, the server can't recognize java.
When hit URL: http://localhost:8080/alfresco/service/demo/simple
Got this message:
"message" : "03230014 Wrapped Exception (with status template): 03230099 Error during processing of the template 'Expression demo is undefined on line 5, column 15 in simple.get.json.ftl.'. Please contact your system administrator.",
"exception" : "org.springframework.extensions.webscripts.WebScriptException - 03230014 Wrapped Exception (with status template): 03230099 Error during processing of the template 'Expression demo is undefined on line 5, column 15 in simple.get.json.ftl.'. Please contact your system administrator.",
1. My Java class:
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 SimpleWebScript extends DeclarativeWebScript {
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req,
Status status, Cache cache) {
// put all the objects that you need in renditions to the model map
Map<String, Object> model = new HashMap<String, Object>();
model.put("demo", "Happy coding!

System.out.println("hello1");
return model;
}
}
2. My bean descrption: web-scripts-application-context.xml
<beans>
<bean id="webscript.org.alfresco.demo.simple.get" class="org.alfresco.module.demoscripts.SimpleWebScript"
parent="webscript">
</bean>
<bean id="webscript.org.alfresco.demo.declarative.get"
class="org.alfresco.module.demoscripts.SimpleDeclarativeWebscript"
parent="webscript">
</bean>
</beans>
3.My webscript desc: 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="json">argument</format>
<family>Alfresco Java-Backed WebScripts Demo</family>
</webscript>
4. simple.get.json.ftl
{
"demo": "${demo}",
}
Labels:
- Labels:
-
Archive
1 REPLY 1

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2013 12:57 PM
<?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">
</bean>
<bean id="webscript.org.alfresco.demo.declarative.get"
class="org.alfresco.module.demoscripts.SimpleDeclarativeWebscript"
parent="webscript">
</bean>
</beans>
<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="json">argument</format>
<family>Alfresco Java-Backed WebScripts Demo</family>
</webscript>
<!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">
</bean>
<bean id="webscript.org.alfresco.demo.declarative.get"
class="org.alfresco.module.demoscripts.SimpleDeclarativeWebscript"
parent="webscript">
</bean>
</beans>
<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="json">argument</format>
<family>Alfresco Java-Backed WebScripts Demo</family>
</webscript>
