AnsweredAssumed Answered

Java Class not invoking in web-scripts

Question asked by mazhar_shaukat on May 11, 2012
Latest reply on Jul 19, 2016 by risharommi
Hi,

I'm new to web-scripts. I'm trying to successfully run an example.
My Java Class is as follow;

package org.alfresco.module.demoscripts;

import java.io.IOException;

import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.extensions.webscripts.AbstractWebScript;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;

public class SimpleWebScript extends AbstractWebScript {

   @Override
   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 RuntimeException("Unable to serialize JSON");
       }

   }

}

Descriptor simple.get.desc.xml
<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>
  <family>Alfresco Java-Backed WebScripts Demo</family>
</webscript>

When I access it like this;
http://localhost:8080/alfresco/service/demo/simple
I get the following error:
org.springframework.extensions.webscripts.WebScriptException: 04110003 Web Script format '' is not registered

when I try following
http://localhost:8080/alfresco/service/demo/simple?format=json

I get this error:

org.springframework.extensions.webscripts.WebScriptException: 04110002 Cannot locate template processor for template org/alfresco/demo/simple.get.json

please help

Outcomes