【问题标题】:java backed webscript doesn't show up at alljava支持的webscript根本不显示
【发布时间】:2013-06-27 08:20:21
【问题描述】:

我正在关注 alfresco wiki 的 java 支持的 webscripts 指南,但无法使其正常工作。更糟糕的是,我无法在日志或其他方面产生错误,或者在 /alfresco/service/index/all 中列出 webscript。

除了 wiki 示例之外,我没有使用 AMP,而是使用 jar 用于我的课程。这是因为我必须将我的 webscripts 添加到当前构建到 jar 中的现有应用程序中。

据我了解,创建 java 支持的 webscript 主要分为三个步骤:

  1. 创建java类
  2. 注册 bean
  3. 放置描述符

我实现了如下。文件位置相对于 jar 的根目录。 nl/mark/alfresco/myservice/webscript/GetFooTypes.java

package nl.mark.alfresco.myservice.webscript;

import java.util.HashMap;
import java.util.Map;

import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;

public class GetFooTypes extends DeclarativeWebScript {
    @Override
    protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("types", "[\"foo\", \"bar\"]");
        return model;
    }
}

alfresco/extension/templates/webscripts/nl/mark/cacher/footype.desc.xml

<webscript>
    <shortname>Retrieve a list of foo types associated to a bar type.</shortname>
    <description>Returns an empty JSON array or a JSON array filled with foo types as Strings, named 'types'.</description>
    <url>/mark/cacher/footype?typecode={code}</url>
    <authentication>user</authentication>
    <family>Mark cacher</family>
</webscript>

alfresco/extension/mark-context.xml

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
    <!-- Java backed webscripts -->
    <bean id="webscript.nl.mark.cacher.footype.get" class="nl.mark.alfresco.myservice.webscript.GetFooTypes"
        parent="webscript">
    </bean>
</beans>

mark-context.xml 文件还包含其他注册,这些注册已正确提取。

最后,这个 jar 被放置在 alfresco 的 WEB-INF/lib 文件夹中,然后重启服务器。但是,该网页脚本在其 URL (404) 下不可用,并且我发现在(非常干净的)日志中没有提及任何相关内容。它也没有在 webscripts 索引中列出,甚至没有加载失败。我觉得我弄乱了文件位置。

【问题讨论】:

  • 快速猜测(这里没有运行 Alfresco):将描述符重命名为“footype.get.desc.xml”

标签: java spring rest alfresco


【解决方案1】:

完整的文件夹和文件名

alfresco/extension/templates/webscripts/nl/mark/cacher/footype.get.desc.xml

定义,

nl/mark/cacher的一个包,

一个 footype 的服务 id,

与 HTTP GET 方法的绑定

<bean id="webscript.nl.mark.cacher.footype.get" 
      class="nl.mark.alfresco.myservice.webscript.GetFooTypes"
      parent="webscript">
</bean>

前缀 webscript 由 Web 脚本引擎拾取。 结束获取由 Web 脚本引擎拾取。它告诉 Web 脚本引擎要处理哪种 HTTP 方法。在这种情况下,HTTP GET

所以在您的代码中,您错过了文件描述符文件名中的 .get

参考: http://wiki.alfresco.com/wiki/Web_Scripts http://wiki.alfresco.com/wiki/Java-backed_Web_Scripts_Samples

【讨论】:

  • 我在问题中犯了一个错误,描述符实际上命名为footype.desc.get.xml。确实,这仍然是错误的。解决方案:footype.get.desc.xml 如你所说。坚持了一天多,我想我现在要去扼杀一些东西:P。谢谢!
  • Spring bean ID 应该是webscript.nl.mark.cacher.footype.get,就像问题中提供的配置一样。您缺少服务 ID。
【解决方案2】:

我觉得描述文件应该命名为footype.get.desc.xml

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 2014-04-20
    • 1970-01-01
    • 1970-01-01
    • 2014-05-03
    相关资源
    最近更新 更多