Java backed webscript doesn't show up at all

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2013 05:52 PM
I am following the alfresco wiki's guide to java backed webscripts and cannot get it to work. What's worse, I cannot get as far as generating errors in the logs or otherwise, or a webscript listing in <alfresco>/alfresco/service/index/all.
Other than the wiki example, I am not using an AMP but a jar for my classes. This is because I am bound to adding my webscripts to an existing app that currently builds to a jar.
As far as I understand, there are three major steps in creating a java backed webscript:
<ol><li>Create the java class</li>
<li>Register the bean</li>
<li>Place the descriptor</li></ol>
I implemented this as follows. File locations are relative to the jar's root.
<strong>nl/mark/alfresco/myservice/webscript/GetFooTypes.java</strong>
<strong>alfresco/extension/templates/webscripts/nl/mark/cacher/footype.desc.xml</strong>
<strong>alfresco/extension/mark-context.xml</strong>
Finally, this jar is placed in alfresco's WEB-INF/lib folder after which the server is restarted. However, the webscript is not available under its URL (404), and I find no mention of anything related in the (awefully clean) logs. It's also not listed in the webscripts index, not even as failed to load. I feel like I am messing up file locations.
Other than the wiki example, I am not using an AMP but a jar for my classes. This is because I am bound to adding my webscripts to an existing app that currently builds to a jar.
As far as I understand, there are three major steps in creating a java backed webscript:
<ol><li>Create the java class</li>
<li>Register the bean</li>
<li>Place the descriptor</li></ol>
I implemented this as follows. File locations are relative to the jar's root.
<strong>nl/mark/alfresco/myservice/webscript/GetFooTypes.java</strong>
package nl.mark.alfresco.myservice.webscript;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 GetFooTypes extends DeclarativeWebScript { @Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) { Map<String, Object> model = new HashMap<String, Object>(); model.put("types", "[\"foo\", \"bar\"]"); return model; }}
<strong>alfresco/extension/templates/webscripts/nl/mark/cacher/footype.desc.xml</strong>
<webscript> <shortname>Retrieve a list of foo types associated to a bar type.</shortname> <description>Returns an empty JSON array or a JSON array filled with foo types as Strings, named 'types'.</description> <url>/mark/cacher/footype?typecode={code}</url> <authentication>user</authentication> <family>Mark cacher</family></webscript>
<strong>alfresco/extension/mark-context.xml</strong>
<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'><beans> <!– Java backed webscripts –> <bean id="webscript.nl.mark.cacher.footype.get" class="nl.mark.alfresco.myservice.webscript.GetFooTypes" parent="webscript"> </bean></beans>
Finally, this jar is placed in alfresco's WEB-INF/lib folder after which the server is restarted. However, the webscript is not available under its URL (404), and I find no mention of anything related in the (awefully clean) logs. It's also not listed in the webscripts index, not even as failed to load. I feel like I am messing up file locations.
Labels:
- Labels:
-
Archive
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2013 05:53 AM
Your Java-Backed WebScript is a DeclarativeWebScript and this type of WebScript need to also have a FreeMarker template for the rendition of the output. If you need to manage request and response directly in the Java implementation you need to extend AbstractWebScript.
Please take a look at the sample project of Java-Backed Webscripts that allows you to see how to implement your own Java-Backed Web Scripts taking a look at a complete Maven project that implements the wiki examples:
https://code.google.com/p/alfresco-java-backed-webscripts-demo/
This project is also linked in the Alfresco Wiki page Java-Backed WebScripts Samples:
http://wiki.alfresco.com/wiki/Java-backed_Web_Scripts_Samples
Hope this helps
Please take a look at the sample project of Java-Backed Webscripts that allows you to see how to implement your own Java-Backed Web Scripts taking a look at a complete Maven project that implements the wiki examples:
https://code.google.com/p/alfresco-java-backed-webscripts-demo/
This project is also linked in the Alfresco Wiki page Java-Backed WebScripts Samples:
http://wiki.alfresco.com/wiki/Java-backed_Web_Scripts_Samples
Hope this helps


Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2013 07:07 AM
Hi Piergiorgio,
thanks for your reply! It's useful, because I could find very little information about DeclarativeWebscripts, no DeclarativeWebscript specific information, in fact. Odd, if you think how important they are.
However, I do have an associated ftl file. The example you linked is the one I too followed. I now edited my project to reflect it more accurately, however.
alfresco/extension/templates/webscripts/nl/mark/cacher/footype.desc.xml now looks like this:
footype.get.json.ftl in the same folder looks like this:
I also moved my bean registration out of the existing context file and placed it in alfresco/module/myservicecache-context.xml to reflect the example project.
All these paths are within the jar file. I'm thinking the problem may be there. After these changes, the result is still the same.
thanks for your reply! It's useful, because I could find very little information about DeclarativeWebscripts, no DeclarativeWebscript specific information, in fact. Odd, if you think how important they are.
However, I do have an associated ftl file. The example you linked is the one I too followed. I now edited my project to reflect it more accurately, however.
alfresco/extension/templates/webscripts/nl/mark/cacher/footype.desc.xml now looks like this:
<webscript> <shortname>Retrieve a list of foo types associated to a bar type.</shortname> <description>Returns an empty JSON array or a JSON array filled with foo types as Strings named 'types'.</description> <url>/mark/ztccache/footype.json</url> <authentication>user</authentication> <format default="json">extension</format> <family>mark myservice cacher</family></webscript>
footype.get.json.ftl in the same folder looks like this:
${types?string}
I also moved my bean registration out of the existing context file and placed it in alfresco/module/myservicecache-context.xml to reflect the example project.
<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'><beans> <!– Java backed webscripts –> <bean id="webscript.nl.mark.cacher.footype.get" class="nl.mark.alfresco.myservice.webscript.GetFooTypes" parent="webscript"> </bean></beans>
All these paths are within the jar file. I'm thinking the problem may be there. After these changes, the result is still the same.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2013 07:28 AM
My webscript descriptor was called footype.desc.get.xml where it should have been footype.get.desc.xml.
Although it will take me a while to look into my eyes in the mirror without shame again, I did learn here. Thanks for thinking along!
Although it will take me a while to look into my eyes in the mirror without shame again, I did learn here. Thanks for thinking along!
