【发布时间】:2011-09-28 22:05:25
【问题描述】:
RESTEasy (JAX-RS) 允许通过子资源进行动态调度。例如:
POST /customers/create
{"name":"Smith","country":"jp"}
我们可以有一个根资源来处理路径“/customers”,该方法使用没有 HTTP 方法但使用 @Path("/create") 注释的方法。此方法返回 JAX-RS 查看以继续处理请求的资源。但是,此资源必须处理“/customers/create”路径。
我有一种情况,可以创建不同类型的实体:
POST /customers/create
{"name":"Smith"}
POST /locations/create
{"name":"Chicago"}
我想添加基于请求正文中的附加属性创建任何类型实体的功能:
POST /entities/create
{"type":"customer","name":"Smith"}
本质上,我想将请求转发给处理“POST /customers/create”的代码。我可以编写为“POST /entities/create”调用并返回 Customer 资源的子资源定位器,但 JAX-RS 无法分派请求,因为 Customer 资源不处理路径“/entities/create”。转发请求时有没有办法可以将 URL 更改为 /customers/create?
此时我无法更改 API 以使“客户”成为“实体”的真正子资源。
【问题讨论】: