02-09-2012 10:43 AM
package my.experiment.webscript;
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 MyExperimentWebscriptController extends DeclarativeWebScript {
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
Map<String, Object> model = new HashMap<String, Object>();
model.put("mykey", "Happy coding! :D");
return model;
}
}
<bean id="webscript.my.experiment.happycoding.get"
class="my.experiment.webscript.MyExperimentWebscriptController"
parent="webscript">
</bean>
<?xml version="1.0" encoding="UTF-8"?>
<webscript>
<shortname>My Happy coding Experiment</shortname>
<description>Demo on how to use a java backed declarative webscript</description>
<url>/my/experiment/happycoding</url>
<format default="xml">argument</format>
<authentication runas="admin">none</authentication>
<negotiate accept="text/xml">xml</negotiate>
<negotiate accept="application/json">json</negotiate>
</webscript>
<root>
<msg><![CDATA[Hello ${person.properties.userName}! ${mykey}]]></msg>
</root>
{
msg: "Hello ${person.properties.userName}! ${mykey}"
}
mvn clean package
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.extensions.surf</groupId>
<artifactId>spring-surf</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.extensions.surf</groupId>
<artifactId>spring-webscripts</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
# xml
wget -O- –header='Accept: text/xml' 'http://localhost:8080/alfresco/service/my/experiment/happycoding' 2> /dev/null
<root>
<msg><![CDATA[Hello admin! Happy coding! :D]]></msg>
</root>
# json
wget -O- –header='Accept: application/json' 'http://localhost:8080/alfresco/service/my/experiment/happycoding' 2> /dev/null
{
msg: "Hello admin! Happy coding! :D"
}
@Override
protected void executeFinallyImpl(WebScriptRequest req, Status status, Cache cache, Map<String, Object> model) {
// cleanup here
}
02-09-2012 11:39 AM
02-09-2012 04:26 PM
02-10-2012 03:30 AM
03-21-2012 04:33 AM
Again and again, the wiki is written by contributors of the Alfresco community as you have done now.
The Alfresco wiki is not the official Alfresco documentation.
the official alfresco documentation is outdated and wrongand i agree with mastro
Thank you for your contribution during these days I'll review the page to test all the implementations with Alfresco 4.
Hope that this could help you to understand the goal of each tool that Alfresco provides to the community :wink:
06-05-2012 11:10 AM
package org.kugelmass.alfresco.webscripts;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.repository.NodeService;
import org.apache.log4j.Logger;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
public class JavaBackedWebScriptExample extends DeclarativeWebScript {
// Get the log4j instance
private final Logger logger = Logger.getLogger(this.getClass().getName());
// NodeService bean, injected by spring using the public setter
private NodeService nodeService;
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
logger.debug("Hello!");
// This method must return a map like this, from which you can fetch the values later
// within the template
Map<String, Object> model = new HashMap<String, Object>();
model.put("test", "Hello!");
return model;
}
public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
}
public NodeService getNodeService() {
return nodeService;
}
}
<webscript>
<shortname>Java baked web script template</shortname>
<description>Java baked web script template</description>
<url>/kugelmass/sample</url>
<authentication>none</authentication>
<format default="html">argument</format>
</webscript>
{
"message": "${test}"
}
/index/family/{family}
/index/lifecycle/{lifecycle}
/index/package/{package}
/index/package/{package}/doc
/index/uri/{uri}
/installer
[b]/kugelmass/sample[/b]
/mimetypes
/modules/deploy
/office/callexternal
/office/docActions
/office/documentDetails
/office/getUsers
/office/myAlfresco
06-05-2012 11:14 AM
06-05-2012 11:15 AM
09-18-2012 09:44 AM
Troubleshooting
I am getting: Cannot locate template processor for template …
If you are extending the AbstractWebScript class then it is most likely that your bean definition file is either in the wrong place, or has the wrong content. Double check this by visiting the following link http://localhost:8080/share/page/script/org/alfresco/module/demoscripts/simple.get (for the first example) and look at the Implementation line. If the implementation is not the class you created, but is the default class (DeclaritiveWebScript), then your class is not being loaded properly. Stop Tomcat and remove your class. Then start tomcat again. If you do not see any class loading errors then that means your bean definition file is not correct. Move it to the correct location and restart tomcat until you are getting a class loading error. Then move your java class file (or jar) into the correct place and restart tomcat again. Visit the page above to make sure the implementation is correct.
Script Properties
Id: org/springframework/extensions/webscripts/org/alfresco/demo/simple.get
Short Name: The World's Simplest Webscript
Description: Hands back a little bit of JSON
Authentication: none
Transaction: none
Method: GET
URL Template: /demo/simple
Format Style: argument
Default Format: [undefined]
Negotiated Formats: [undefined]
Implementation: class org.springframework.extensions.webscripts.DeclarativeWebScript
Extensions: [undefined]
Store: classpath:alfresco/site-webscripts
[No implementation files]
Store: classpath:surf/webscripts
[No implementation files]
Store: classpath:webscripts
File: org/springframework/extensions/webscripts/org/alfresco/demo/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>
09-18-2012 10:04 AM
<bean id="webscript.getTypes.get" (you can change this as you like)
class="org.kugelmass.alfresco.webscripts.JavaBackedWebScriptExample"
parent="webscript">
<property name="dictionaryService" ref="DictionaryService"/> (if needed)
</bean>
In this way your code will be correctly loaded by Spring.Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.