我在露天创建了执行脚本规则,并将我的 javascript 文件保存在 Company Home>Data Dictionary>script 文件夹中。
我的规则如下:
所有项目>执行脚本'dataFilesScript.js'>项目已创建或进入此文件夹>完成
1)。我的 Js 脚本如下。
var simplehttpresult = "";
try {
simplehttpresult = SimpleHttpConnection.getContentAsString("http://myip:myport/alfresco/service/demo/simple");
}catch(ex){
error = String(ex)
}
2).我在 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).我的 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>
4)。我添加以下行 script-services-context.xml
<bean id="httpUtilsScript" parent="baseJavaScriptExtension"
class="org.um.alfresco.SimpleHttpConnection">
<property name="extensionName">
<value>SimpleHttpConnection</value>
</property>
</bean>
5).我的Java文件如下。
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");
}
}
}
.当我的规则被执行时。它在 Alfresco 4.0 中运行良好,但不适用于 4.2.c。在 Alfresco 4.2.C 中,我的操作代码仅被调用一次...在 4.2.C 中需要任何其他配置设置请建议.....