cancel
Showing results for 
Search instead for 
Did you mean: 

Java Backed Web Scripts

toze
Champ in-the-making
Champ in-the-making
Hi!
Where i can see a full tutorial how to create and deploy Java Backed Web Scripts in Alfresco 4?
I made that in Alfresco 3, but now i know there are changes!
Can anyone provide a good tutorial please?
thanks in advance!
20 REPLIES 20

toze
Champ in-the-making
Champ in-the-making
Didn't worked

abarisone
Star Contributor
Star Contributor
I noticed that the response template is:
CreateFoldersMigration.get.json‍
If I'm not wrong the response file name should be in the form CreateFoldersMigration.<HTTP method>.<response format>, so try naming the response file as CreateFoldersMigration.get.json.ftl

toze
Champ in-the-making
Champ in-the-making
The response?

I have the description file. I need other file? In what location?

abarisone
Star Contributor
Star Contributor
Usually, an 'ordinary' webscript needs 3 files:

1) a desc xml field that contains configuration
2) a js file with doing the backend work (like a controller that provides you the filled model)
3) a ftl file that helps you to show the results

When you build up a Java backed webscript, you replace the point 2) with a Java implementation but you still need to have the other two files.

Look at https://wiki.alfresco.com/wiki/Web_Scripts#How_Do_I_Create_a_Web_Script.3F for more info.
Hope this helps.

jlangdon
Champ in-the-making
Champ in-the-making
I'm trying to follow the simplest tutorial here:
http://wiki.alfresco.com/wiki/Java-backed_Web_Scripts_Samples

There's no mention of an ftl template.  It gives the impression that none is needed, and that the web script will simply return json.  Can someone clarify?  Also, can someone tell me how to structure the AMP file?  The tutorial tells me where the files should end up, but shouldn't that happen by way of the amping process?  I don't want to edit files in the webapps/alfresco directory.  Also, the tutorial has me editing the existing web-scripts-application-context.xml file, but isn't that in alfresco.war?  I don't want to modify that except by amping.  Any help is appreciated.  Thanks.

openpj
Elite Collaborator
Elite Collaborator
First I think that you need to take a look at the examples Google Code project:
http://code.google.com/p/alfresco-java-backed-webscripts-demo/

This is the same project mentioned in the wiki page here:
http://wiki.alfresco.com/wiki/Java-backed_Web_Scripts_Samples#The_Demo_Web_Scripts

There's no mention of an ftl template. It gives the impression that none is needed, and that the web script will simply return json. Can someone clarify?
If you don't want to define an FTL template in output, because you have a Java library that can generate the output, then you have to implement an AbstractWebScript that allows you to manage directly the response object of the HTTP request without defining any FTL template.

So you have two types of Java-Backed WebScripts: AbstractWebScript and DeclarativeWebScript.

The AbstractWebScript, as described above, allows you to manage the response in the execute method like any other MVC framework. For this type of implementation you only need to provide the descriptor and the Java controller class that in this case will also manage the output.

The DeclarativeWebScript follows all the pattern defined, this means that you need to define the descriptor, the Java controller and the FTL template.

Also, can someone tell me how to structure the AMP file? The tutorial tells me where the files should end up, but shouldn't that happen by way of the amping process?
You can take a look at the Google Code project to understand how to build your own amp simply using the same approach.

Hope this helps  :wink:

jlangdon
Champ in-the-making
Champ in-the-making
I figured this out after finding the download of the amp file at http://code.google.com/p/alfresco-java-backed-webscripts-demo/.

It's true that you don't need an ftl file.

Here's the structure of the amp file:
- config
  - alfresco
    - extension
      - templates
        - webscripts
          - org
            - alfresco
              - demo
                - simple.get.desc.xml
    - extension
      - module
        - mymoduleid
          - log4j.properties
          - module-context.xml
- lib
  - mymodule.jar
- module.properties

There's a lot here that isn't mentioned in the tutorial.  In some places, the tutorial has you directly editing files in the deployed alfresco/webapps directory, which I think should be avoided.

Note that the bean definition goes in module-context.xml.

"mymoduleid" is whatever you put in module.id in the module.properties file (no mention of this in the tutorial).

The structure of mymodule.jar is:
- META-INF
  - MANIFEST.MF
- org
  - alfresco
    - module
      - demoscripts
        - SimpleWebScript.class

I hope this is helpful.

amitabhandari1
Champ in-the-making
Champ in-the-making
Hi,

Refer http://wiki.alfresco.com/wiki/AMP_Files   for  AMP help.
You can independently also  deploy webscript.
1. Create custom-webscript-context.xml file and add your webscript bean there.
2. You can create ftl file and keep it blank if you don't want to use webscript for presentation.

Thanks,

abarisone
Star Contributor
Star Contributor
Hi,
in order to have more info about webscripts in general and about java backed ones, you could refer to this useful doc by jpotts
http://ecmarchitect.com/images/articles/alfresco-webscripts/web-script-article.pdf

isastre
Champ in-the-making
Champ in-the-making
Hi,

I am trying to deploy the amp with all the examples but I am having some problems as I am using:
Alfresco Enterprise v4.0.1
(897) schema 5028
Spring Surf and Spring WebScripts - v1.0.0
(Release 1044)

The error message that I am getting when executing the ./apply_amps.sh is "07310000 The module (Alfresco Java-Backed WebScripts Samples) cannot be installed on a repo version greater than 2.1"

I know I can change the module.properties inside the .amp and add some comments in:
# The following optional properties can be used to prevent the module from being added
# to inappropriate versions of the WAR file.
#module.repo.version.min=2.0

#module.repo.version.max=2.1


so the amp will be deployed but I am not sure it will work properly.

Is there any updated version of the .amp? If not can you please help me to change the .amp so it will works with my Alfresco version?

Many thanks,