【发布时间】:2019-03-13 12:32:43
【问题描述】:
我想向标准 Intershop ProductResource 引入一个新的子资源 不会丢失产品资源上下文。
例如,在我的资源代码中,我想了解 REST 客户端所指的产品/product/SOME/my-sub-resource
我该怎么做?
【问题讨论】:
标签: intershop
我想向标准 Intershop ProductResource 引入一个新的子资源 不会丢失产品资源上下文。
例如,在我的资源代码中,我想了解 REST 客户端所指的产品/product/SOME/my-sub-resource
我该怎么做?
【问题讨论】:
标签: intershop
“Cookbook - REST Framework”中有一个食谱:
将资源添加到现有 REST API https://support.intershop.com/kb/index.php/Display/28269L
【讨论】:
com.intershop.component.rest.capi.resource.AbstractRestResource
<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>
<instance with="YOUR_NAME" name="YOUR_INSTANCE_NAME">
<fulfill requirement="name" value="YOUR_SUBRESOUCE_NAME" />
</instance>
subResource 到intershop.WebShop.RESTAPI.ProductResource 实例<fulfill requirement="subResource"
of="intershop.WebShop.RESTAPI.ProductResource"
with="YOUR_INSTANCE_NAME"/>
之后,您的资源在/product/SKU/YOUR_SUBRESOURCE_NAME 下可用。确保您的 impl 类有一个公共方法,并且该方法带有 javax.ws.rs.GET 和 javax.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
}
【讨论】: