【问题标题】:Liferay: how add new JSONWebService methodLiferay:如何添加新的 JSONWebService 方法
【发布时间】:2013-04-07 13:47:54
【问题描述】:

我需要通过 json 请求获取 DDL 记录。 Liferay 核心没有这样的服务。仅 getRecordSet。

我编写 DDLRecordSetService Hook 来添加新方法getRecords(recordSetId)。 我的代码:

public class ExtDDLRecordSetLocalServiceImpl extends DDLRecordSetServiceWrapper {


   public ExtDDLRecordSetLocalServiceImpl(DDLRecordSetService ddlRecordSetService) {
       super(ddlRecordSetService);
   }

   public com.liferay.portlet.dynamicdatalists.model.DDLRecordSet getRecordSet(long recordSetId) throws com.liferay.portal.kernel.exception.PortalException, com.liferay.portal.kernel.exception.SystemException{

       System.out.println("------override getRecordSet ");
      DDLRecordSet set = super.getRecordSet(recordSetId+10);
        return set;
   }

   @JSONWebService
   public List<DDLRecord> getRecords(long recordSetId) throws SystemException, PortalException {
        System.out.println("------override getRecords");
        return   getRecordSet(recordSetId).getRecords();
   }

}

我可以覆盖 getRecordSet(),但我无法通过 URL 访问 getRecordSet() 方法。

我明白了:

{"exception":"No JSON web service action associated with path /ddlrecordset/get-records and method GET for /"}

如何添加可以通过 JSONWebService 返回记录集的新 DDLRecordSetService?

【问题讨论】:

    标签: tomcat liferay liferay-6 portal


    【解决方案1】:

    DDL 的内置 JSON 服务比获取记录集更丰富。尝试将浏览器指向门户的 Web 服务 api 页面。登录后,

    /api/jsonws

    DDLRecord 上有 7 个方法,DDLRecordSet 有 8 个方法。

    在我看来,标准 API 可以满足您的需求。

    如果不是这样,那么……

    JSON Web 服务方法是在服务构建器运行时创建的。这会将您的方法反向工程为 JSON、SOAP 等的正确对象。

    由于您从未运行过服务构建器,因此逆向工程永远不会发生。我怀疑在 Liferay 核心资源上运行 SB 是否是您的想法(无论如何,这都是不可取的,imo。)

    我的建议是使用 Service Builder 创建您自己的服务,从而为您想要公开的服务对象创建您自己的 API。另见this question

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-16
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 2015-08-10
      • 2012-06-09
      相关资源
      最近更新 更多