
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2016 04:55 PM
I am new with alfresco. I have created a share extension where I want to create a Java backed webscript.
I used https://wiki.alfresco.com/wiki/Java-backed_Web_Scripts_Samples to create Java backed webscript.
Add the following bean in custom-slingshot-application-context.xml
<bean id="webframework.store.webscripts.custom" class="org.alfresco.web.scripts.ClassPathStore">
<property name="mustExist"><value>true</value></property>
<property name="classPath"><value>config/alfresco/web-extension/site-webscripts</value></property>
</bean>
http://127.0.0.1:8081/share/service/com/retreive-data/simple
I get the following error:
retreive-data-share/target/amp-war/WEB-INF/lib/retreive-data-share-1.0-SNAPSHOT.jar!/alfresco/web-extension/custom-slingshot-application-context.xml]; nested exception is java.lang.ClassNotFoundException: org.alfresco.web.scripts.ClassPathStore
Caused by: java.lang.ClassNotFoundException: org.alfresco.web.scripts.ClassPathStore
/src/main/amp/config/alfresco/web-extension/site-webscripts/com/retreive-data/simple.get.desc.xml
<webscript>
<shortname>The World's Simplest Webscript</shortname>
<description>Hands back a little bit of JSON</description>
<url>/com/tenthline/retreive-data/simple</url>
<authentication>none</authentication>
<format default="">argument</format>
<family>Alfresco Java-Backed WebScripts Demo</family>
</webscript>
/src/main/amp/config/alfresco/web-extension/site-webscripts/com/retreive-data/simple.get.json.ftl
<#escape x as jsonUtils.encodeJSONString(x)>
{
"field1": "${field1}"
}
</#escape>
And also the there are xml files, I dont know where could I use them for Java Backed webscript
/src/main/amp/config/alfresco/web-extension/monitor-websites-share-slingshot-application-context.xml
/src/main/resources/alfresco/web-extension/custom-slingshot-application-context.xml
/src/main/resources/alfresco/web-extension/share-config-custom.xml.sample
/src/main/resources/META-INF/share-config-custom.xml.sample
Thanks advance for your help
dj
- Labels:
-
Archive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2016 09:46 AM
Your class looks fine, so it must be the Spring context file that is not correct.
I suspect it is your bean ID. As it says in my tutorial, the syntax for the bean ID is:
webscript.package.service-id.method
But yours is "webscript.sudo". Alfresco has no way of knowing which web script you intend to use that class with unless that ID follows the convention. You need to change it to:
webscript.sudo.sudorename.get
Be sure to restart Alfresco after that change.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2016 11:04 AM
The tutorial covers repo tier web scripts but it should be the same for Share tier web scripts.
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2016 11:01 AM
Hi Jeff Potts,
I followed the principle and structure of your tutorial and that of the official Alfresco document tutorial, but still get the following error.
<blockcode>
2016-10-05 16:34:25,500 ERROR [freemarker.runtime] [http-apr-8080-exec-2] Error executing FreeMarker template
FreeMarker template error:
The following has evaluated to null or missing:
==> data [in template "sudo/sudorename.get.html.ftl" at line 6, column 22]
Tip: If the failing expression is known to be legally null/missing, either specify a default value with myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthessis: (myOptionVar.foo)!myDefault, (myOptionVar.foo)??
The failing instruction (FTL stack trace):
----------
==> ${data} [in template "sudo/sudorename.get.html.ftl" at line 6, column 20]
----------
</blockcode>
The webscript is fully registered and only when I invoke it do I get that error message. The Java class is a simple class to return a text (business logic to be done later).
My files:
tomcat\webapps\alfresco\WEB-INF\classes\za\gov\parliament\sudowebscripts\SudoChildNode.class
<blockcode>
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map<String, Object> model = new HashMap<String, Object>();
model.put("data", "Data retrieved");
logger.debug("Sudo webscript execution complete");
return model;
}
</blockcode>
tomcat\shared\classes\alfresco\extension\templates\webscripts\sudo\sudorename.get.desc.xml
tomcat\shared\classes\alfresco\extension\templates\webscripts\sudo\sudorename.get.html.xml
tomcat\shared\classes\alfresco\extension\sudorename-context.xml
<blockcode>
<?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.sudo" class="za.gov.parliament.sudowebscripts.SudoChildNode" parent="webscript" />
</beans>
</blockcode>
In all the above is there something that I am missing?
Using Alfresco 5.2 201609 Nightly build
Much thanks.
~Vusani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2016 05:01 PM
Can you provide the full class signature of your Java class so I can see what it extends/implements?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2016 03:15 AM
Hi @Jeff
Here is the full class:
package za.gov.parliament.sudowebscripts;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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 SudoChildNode extends DeclarativeWebScript
{
private Log logger = LogFactory.getLog(SudoChildNode.class);
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map<String, Object> model = new HashMap<String, Object>();
model.put("data", "Data retrieved");
logger.debug("Sudo webscript execution complete");
return model;
}
}
Much Thanks
~Vusani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2016 09:46 AM
Your class looks fine, so it must be the Spring context file that is not correct.
I suspect it is your bean ID. As it says in my tutorial, the syntax for the bean ID is:
webscript.package.service-id.method
But yours is "webscript.sudo". Alfresco has no way of knowing which web script you intend to use that class with unless that ID follows the convention. You need to change it to:
webscript.sudo.sudorename.get
Be sure to restart Alfresco after that change.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2016 10:29 AM
Much thanks,
Indeed it was the bean ID, made the change and worked. It was an oversight while I was working through the tutorial.
~Vusani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2016 10:42 AM
Awesome, glad you got it working!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2016 10:50 PM
And you'd better check if a variable exists in FreeMarker template before using it,like this
<#if data??>
${data}
</#if>
Or display a default text when the variable is null ,like this
${(data)!"default text"}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2016 09:58 AM
Your issue is due to reasons given by Jeff and and kyne. Error is because you are trying print value of "data" which is null and you do not have any null check in your ftl.
Reason your data is null is because your java class is not getting called.
