如何将新的子资源添加到标准的Intershop AbstractResourceObject

问题描述 投票:2回答:2

我想在标准的Intershop产品资源中引入新的子资源,而不会丢失产品资源上下文。

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

我怎样才能做到这一点 ?

intershop
2个回答
1
投票

“Cookbook - REST框架”中有一个配方:

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


1
投票
  1. 您需要添加一个扩展com.intershop.component.rest.capi.resource.AbstractRestResource的新java类
  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
}

© www.soinside.com 2019 - 2024. All rights reserved.