cancel
Showing results for 
Search instead for 
Did you mean: 

Java Backed Webscript problem in

nagababu
Champ in-the-making
Champ in-the-making
Hi,

I created execute script rule in alfresco and I kept my javascript file in Company Home>Data Dictionary>script folder.

My Rule is as follows:

All Items > Executes script 'dataFilesScript.js' > Items are created or entered this folder >Finish 


1). My Js script is as follows.

var simplehttpresult = "";

try {
   
   simplehttpresult = SimpleHttpConnection.getContentAsString("http://172.16.5.243:8085/alfresco/service/demo/simple");
}catch(ex){
   error = String(ex)
}

2).I add following lines in web-scripts-application-context.xml

<bean id="webscript.org.alfresco.demo.simple.get"
      class="org.alfresco.module.demoscripts.SimpleWebScript"
      parent="webscript">
     <property name="repository" ref="repositoryHelper" />
      <property name="serviceRegistry" ref="ServiceRegistry" />

  </bean>

3).My simple.get.desc.xml file

<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>

4). I add following lines script-services-context.xml


<bean id="httpUtilsScript" parent="baseJavaScriptExtension"
        class="org.um.alfresco.SimpleHttpConnection">
        <property name="extensionName">
            <value>SimpleHttpConnection</value>
        </property>    
    </bean>

5).My Java file is as follows.

public class SimpleWebScript 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");
       }
    }   
}

When my rule is executed. It's working fine in Alfresco 4.0 but it is not working in other versions such as 4.1.3, 4.2.a, 4.2.c…
In Alfresco 4.2.C My action code is calling only once when the service is started. When the rule is executed second time onwords Java backed code is not executing. Is it required to do any other configuration settings in alfresco versions beyond 4.0.


Please suggest…..

Thanks In Advance.
1 REPLY 1

mitpatoliya
Star Collaborator
Star Collaborator
Strange any errors in the logs?
Also is there any authentication related java code you have used because there might be change in the API's
Also have you compiled your script with the respective SDK of new version in which you are deploying?