【问题标题】:How to add new sub resource to a standard Intershop AbstractResourceObject如何将新的子资源添加到标准 Intershop AbstractResourceObject
【发布时间】:2019-03-13 12:32:43
【问题描述】:

我想向标准 Intershop ProductResource 引入一个新的子资源 不会丢失产品资源上下文。

例如,在我的资源代码中,我想了解 REST 客户端所指的产品/product/SOME/my-sub-resource

我该怎么做?

【问题讨论】:

    标签: intershop


    【解决方案1】:

    “Cookbook - REST Framework”中有一个食谱:

    将资源添加到现有 REST API https://support.intershop.com/kb/index.php/Display/28269L

    【讨论】:

      【解决方案2】:
      1. 你需要添加一个新的java类扩展com.intershop.component.rest.capi.resource.AbstractRestResource
      2. 在组件文件中注册实现
      <implementation name="YOUR_NAME"
          implements="AbstractRestResource"
          class="YOUR_FQNAME_TO_IMPL_CLASS"
          factory="JavaBeanFactory">
          <requires name="name" contract="String" cardinality="1..1" />
          <requires name="subResource" contract="RestResource" cardinality="0..n" />
      </implementation>
      
      1. 在组件文件中实例化实现
      <instance with="YOUR_NAME" name="YOUR_INSTANCE_NAME">
          <fulfill requirement="name" value="YOUR_SUBRESOUCE_NAME" />
      </instance>
      
      1. 添加为subResourceintershop.WebShop.RESTAPI.ProductResource 实例
      <fulfill requirement="subResource" 
          of="intershop.WebShop.RESTAPI.ProductResource" 
          with="YOUR_INSTANCE_NAME"/>
      

      之后,您的资源在/product/SKU/YOUR_SUBRESOURCE_NAME 下可用。确保您的 impl 类有一个公共方法,并且该方法带有 javax.ws.rs.GETjavax.ws.rs.Produces 注释

      @GET
      @Produces("application/json")
      public SomeRO get()
      {
          ApplicationBO applicationBO = provider.get();
          ProductBORepository productBORep = applicationBO.getRepository(ProductBORepositoryExtension.EXTENSION_ID);
          ProductBO product = productBORep.getProductBOBySKU(getParent().getName());
          // Do the stuff you want with the product
      }
      
      

      【讨论】:

        猜你喜欢
        • 2021-09-21
        • 1970-01-01
        • 2015-04-15
        • 2023-03-27
        • 1970-01-01
        • 2015-03-14
        • 1970-01-01
        • 2019-04-05
        • 2013-05-14
        相关资源
        最近更新 更多