我想在标准的Intershop产品资源中引入新的子资源,而不会丢失产品资源上下文。
例如,在我的资源代码中,我想知道REST客户端所指的产品/product/SOME/my-sub-resource
我怎样才能做到这一点 ?
“Cookbook - REST框架”中有一个配方:
将资源添加到现有REST API https://support.intershop.com/kb/index.php/Display/28269L
com.intershop.component.rest.capi.resource.AbstractRestResource
的新java类<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
}