cancel
Showing results for 
Search instead for 
Did you mean: 

Problems deploying SimpleWebScript

fmarchioni
Champ in-the-making
Champ in-the-making
Hi all !
I'd like to test the SimpleWebScript.java example found in the documentation.
I have compiled the class and added it under webapps\alfresco\WEB-INF\classes,
then I have updated module-context.xml with the Bean definition
finally declared the Web Script
<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>
</webscript>

Now when I try to invoke the script

http://localhost:8080/alfresco/service/demo/simple

I get the following error:

Message: Web Script format 'null' is not registered 
  
Exception: org.alfresco.web.scripts.WebScriptException - Web Script format 'null' is not registered 


I have tried changing the format to "html", then I get a different error…seems it's missing the response document…

Message: IO Error during processing of the template 'org/alfresco/sample/simple.get.html.ftl'. Please contact your system administrator. 
  
Exception: java.io.FileNotFoundException - Template org/alfresco/sample/simple.get.html.ftl not found. 


Can anybody help me to fix it ?
thanks a lot
Francesco
6 REPLIES 6

fmarchioni
Champ in-the-making
Champ in-the-making
Still nothing…I'm going a bit mad with this….. Smiley Sad
I think that the error is due to the fact that Alfresco cannot link the web script with the Java class………please can anybody clarify where should I put my Java Class (extending AbstractWebScript) and where my simple.get.desc.xml, supposing my Alfresco HOME is "C:\AlfrescoCommunity"……
Thanks
Francesco

ram3n
Champ in-the-making
Champ in-the-making
I'm getting the same error message.  Any help would be great!  thanks.

marco_sindoni
Champ in-the-making
Champ in-the-making
Same problem. Solved setting correct information in web-scripts-application-context.xml. Step by step:

1) Webscript class must extends AbstractWebScript. My TestWebScript class returns a very simple JSON string:


package test.webscript;

import java.io.IOException;

import org.alfresco.web.scripts.AbstractWebScript;
import org.alfresco.web.scripts.WebScriptException;
import org.alfresco.web.scripts.WebScriptRequest;
import org.alfresco.web.scripts.WebScriptResponse;
import org.json.JSONException;
import org.json.JSONObject;

public class TestWebscript extends AbstractWebScript {

   
   public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException {
      
      try {
         // build a json object
         JSONObject obj = new JSONObject();

         // put some data on it
         obj.put("field1", "data1");

         // build a JSON string and send it back
         String jsonString = obj.toString();
         res.getWriter().write(jsonString);
         
      } catch (JSONException e) {
         throw new WebScriptException("Unable to serialize JSON");
      }
      
   }
}

2) Modify web-scripts-application-context.xml in <ALF_HOME>\tomcat\webapps\alfresco\WEB-INF\classes\alfresco, adding at the end:


<bean id="webscript.org.alfresco.mywebscript.test1.get"
class="test.webscript.TestWebscript" parent="webscript">
</bean>

My test.webscript.TestWebscript class is packaged into a jar copied in <ALF_HOME>\tomcat\webapps\alfresco\WEB-INF\lib. Is important to understand the bean id:

webscript.org.alfresco.mywebscript.test1.get

This id must always begin with 'webscript'. Then, org.alfresco.mywebscript represents (in dotted notation) the phisical path to find 'test1.get.desc.xml', starting in <ALF_HOME>\tomcat\webapps\alfresco\WEB-INF\classes\alfresco\templates\webscripts. So, webscript.org.alfresco.mywebscript.test1.get means: there is a test1.get.desc.xml webscript definition file, in folder <ALF_HOME>\tomcat\webapps\alfresco\WEB-INF\classes\alfresco\templates\webscripts\org\alfresco\mywebscript

3) My test1.get.desc.xml looks like this:


<webscript>
  <shortname>Alfresco Test WebScript</shortname>
  <description>Hands back a little bit of JSON</description>
  <url>/mywebscript/test1</url>
  <authentication>none</authentication>
  <format default="">argument</format>
</webscript>

Note that url element is the webscript path and name, as defined at point 2)

Finally, pointing browser to http://localhost:8080/alfresco/service/mywebscript/test1 I get a response page with JSON string ({"field1":"data1"} for this example)

Hope this helps

Bye, Marco

faisal
Champ in-the-making
Champ in-the-making
Thanx a lot… this solved my problem… I was struggling to deploy thease java backed web scripts as welll…

thomaskaemmerli
Champ in-the-making
Champ in-the-making
Hallo marco.sindoni,

I tryed your solution. I added my Class to
C:\Alfresco\tomcat\webapps\alfresco\WEB-INF\classes\TestWebscript.class
Then I modivied \tomcat\webapps\alfresco\WEB-INF\classes\alfresco\web-scripts-application-context.xml
like you are described it.
At least i added via Alfrescoshare the file test1.get.desc.xml.
But I get still the error:

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

Message:   05210010 Web Script format '' is not registered
   
Exception:   org.springframework.extensions.webscripts.WebScriptException - 05210010 Web Script format '' is not registered
   
   org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:58)
   org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:437)
   org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:619)
   org.alfresco.repo.web.scripts.RepositoryContainer.executeScriptInternal(RepositoryContainer.java:326)
   org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:280)
   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:727)
   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
   org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
   org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)
   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
   org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
   org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
   org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2466)
   org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2455)
   java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
   java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
   org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
   java.lang.Thread.run(Unknown Source)
   
Server:   Community v5.0.0 (d r99759-b2) schema 8.022
Time:   21.06.2015 19:44:51


Do you know where's the problem in my solution.

Thanks for reply

If you copied the class as it is, you should respect the package declaration:
Add the Class to
C:\Alfresco\tomcat\webapps\alfresco\WEB-INF\classes\test\webscript\TestWebscript.class

create test and webscript folders if they do not already exist