cancel
Showing results for 
Search instead for 
Did you mean: 

unable to execute backup Webscript

vincent-kali
Star Contributor
Star Contributor
Hi all,
I'm trying to deploy a backend webscript based on the simple example found here https://wiki.alfresco.com/wiki/Java-backed_Web_Scripts_Samples#SimpleWebScript.java ("The World's Simplest Webscript").
But I can't make it working.
-> Web script is registered
-> the "The World's Simplest Webscript", is working fine


I'm getting the following error : (config is detailed below)

thanks for your help !

________________________


The Web Script /core/service/ks2/dlockws/lock has responded with a status of 500 - Internal Error.

500 Description:   An error inside the HTTP server which prevented it from fulfilling the request.

Message:   06220001 Cannot locate template processor for template org/alfresco/ks2/dlockws/lock.get.html
   
Exception:   org.springframework.extensions.webscripts.WebScriptException - 06220001 Cannot locate template processor for template org/alfresco/ks2/dlockws/lock.get.html
   
   org.springframework.extensions.webscripts.AbstractWebScript.renderTemplate(AbstractWebScript.java:904)
   org.springframework.extensions.webscripts.DeclarativeWebScript.renderFormatTemplate(DeclarativeWebScript.java:267)
   org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:147)
   org.alfresco.repo.web.scripts.RepositoryContainer$3.execute(RepositoryContainer.java:429)
   org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:452)
   org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:491)
   org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:529)
   org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:341)
   org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:378)
   org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)
   org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

…..
________________________


my class: (jar file <Alfresco>/tomcat/webapps/alfresco/WEB-INF/lib )

package org.alfresco.module.ks2.dlockws;

import ….

public class lock extends org.springframework.extensions.webscripts.DeclarativeWebScript {
   
    public void executeImpl (WebScriptRequest req, WebScriptResponse res)
        throws IOException
    {
       
       …
       
       try
       {
          
         if (req.getParameter("a") == null || req.getParameter("a").length() == 0)
         {
            
            status.setCode(HttpServletResponse.SC_BAD_REQUEST);
            status.setMessage("no parameter");
            status.setRedirect(true);
            return;
         }
         else
         {
            status.setCode(HttpServletResponse.SC_OK );
            message = "param a=" + req.getParameter("a");
            status.setMessage(message);
            status.setRedirect(true);
            return;         
         }
       }
       catch(Exception e)
       {
          //throw new WebScriptException("Unable to serialize JSON");
          status.setCode(HttpServletResponse.SC_FORBIDDEN);
          status.setMessage("Invalid username & password");
          status.setException(e);
          status.setRedirect(true);
      }
    }

   ……
}

________________________


lock.get.desc.xml content: (file in <Alfresco>/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/module/ks2/dlockws )



<webscript>
  <shortname>lock</shortname>
  <description>dLock Web Service, methode lock</description>
  <url>/ks2/dlockws/lock</url>
  <authentication>admin</authentication>
  <family>ks2 Web Scripts</family>
</webscript>

________________________

web script declaration: (in file <Alfresco>/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/web-scripts-application-context.xml

<bean id="webscript.org.alfresco.ks2.dlockws.lock.get"
      class="org.alfresco.module.ks2.dlockws.lock"
      parent="webscript">
</bean>

_________________________










4 REPLIES 4

vincent-kali
Star Contributor
Star Contributor
solved: I was extending the DeclarativeWebScript class without a freemarker template. It seems that the only way to work without freemarker template is by extending the AbstractWebScript class.
If somebody can confirm that ?
Thanks,
Vincent

Declarativewebscript and Abstractwebscript both are the helper classes provided by the alfresco webscript framework for developing java backed webscripts in alfresco. Declarativewebscript provides execution assistance for the webscript and allows to building up the model object as required to render in the FTL template, possible to redirection based on error status codes etc. Webscript controller java class has to extend DeclarativeWebscript and override executeImpl method for using it. ftl template is required in this case.

About AbstractWebScript, it gives full control to the extending controller class to render the response and hence ftl template not required. DeclarativeWebscript is a good example of using this control provided by AbstractWebScript. It extends AbstractWebScript only and provides the mechanism to render the response through model object.
In the scenarios like streaming the content extending AbstractWebScript class can be used. However, generally for creating java backed webscript, DeclarativeWebscript is used.

Hope this helps.

kaynezhang
World-Class Innovator
World-Class Innovator
Yes ,if you extend the DeclarativeWebScript class, a freemarker template is needed.
Although you can extend the AbstractWebScript class without freemarker template,I don't think it is a good approcach,because  under certain circumstances template is still needed (for exmaple if your webscript need to support redirection).
So I suggest you still extend the DeclarativeWebScript class and provide a freemarker template.

vincent-kali
Star Contributor
Star Contributor
OK, thanks