【问题标题】:alfresco webscript not executing code露天网页脚本不执行代码
【发布时间】:2016-06-01 09:43:50
【问题描述】:

我试图在露天运行基于 java 的 webscript。在我的第一步中,我只想使用响应输出流打印“hello world”。我面临的主要问题是代码没有被执行。我试图在代码中设置断点但它们没有触发,我只得到结果是普通的ftl。

abstratWebscript 响应是否应该优先于 ftl? 有人可以告诉我我做错了什么,或者这是否是 abstractwebscript 的自然行为?

这是java类:

package com.beam.gbsprocs.tag.webscript;
import java.io.IOException;
import java.io.PrintWriter;    

import org.springframework.extensions.webscripts.AbstractWebScript;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;

public class GbsprocsTagWebscript extends AbstractWebScript {



  @Override
  public void execute(WebScriptRequest req, WebScriptResponse res)
        throws IOException {

    PrintWriter out = new PrintWriter(res.getOutputStream());

    out.println("hello world");
    out.close();

  }

}

这是描述文件

<webscript>
<shortname>Perform GBSprocs  Tag completion</shortname>
<description>Export gives a json list of posible tag values </description>
<url>/gbsprocs/tag</url>
<authentication>user</authentication>
</webscript>

Bean 声明(版本增加):

  <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:util="http://www.springframework.org/schema/util"

   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
   http://www.springframework.org/schema/util
  http://www.springframework.org/schema/util/spring-util-2.5.xsd">

 <bean id="com.beam.gbsprocs.tag.webscript.GbsprocsTagWebscript.get"
    class="com.beam.gbsprocs.tag.webscript.GbsprocsTagWebscript"
      parent="webscript">


 </bean>

</beans>

ftl 看起来像:

Hello from ftl.

执行结果: rest client response

【问题讨论】:

  • 你的 webscript 类的 spring bean 定义在哪里?
  • 您的 Web 脚本如何知道要调用哪个 Java 类,您在哪里将 XML 描述符与 GbsprocsTagWebscript.java 连接起来?

标签: alfresco alfresco-webscripts


【解决方案1】:

使用 org.springframework.extensions.webscripts.DeclarativeWebScript 代替 AbstractWebScript

和@override 方法 protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) 将您的模型返回到 ftl

而且你还需要在你的课堂上添加 bean deffenition

【讨论】:

  • 我知道它可以这样工作,但我想知道是否可以使用 AbstractWebscript 来实现。 (我添加了我的 spring bean 定义以获取所有数据)
猜你喜欢
  • 2021-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-09
相关资源
最近更新 更多