【发布时间】:2013-06-26 11:38:10
【问题描述】:
我想使用骆驼公开一个 RESTfull 网络服务。我使用 URI 模板来定义我的服务合同。我想知道如何根据 URI 模板将请求路由到我的 ServiceProcessor 的相关方法。
以如下两个操作为例:
@GET
@Path("/customers/{customerId}/")
public Customer loadCustomer(@PathParam("customerId") final String customerId){
return null;
}
@GET
@Path("/customers/{customerId}/accounts/")
List<Account> loadAccountsForCustomer(@PathParam("customerId") final String customerId){
return null;
}
以下是我使用的路线:
<osgi:camelContext xmlns="http://camel.apache.org/schema/spring">
<route trace="true" id="PaymentService">
<from uri="`enter code here`cxfrs://bean://customerCareServer" />
<process ref="customerCareProcessor" />
</route>
</osgi:camelContext>
有什么方法可以将 uri 标头 (Exchange.HTTP_PATH) 匹配到我的服务定义中的现有模板 uri?
以下是我的服务的服务合同:
@Path("/customercare/")
public class CustomerCareService {
@POST
@Path("/customers/")
public void registerCustomer(final Customer customer){
}
@POST
@Path("/customers/{customerId}/accounts/")
public void registerAccount(@PathParam("customerId") final String customerId, final Account account){
}
@PUT
@Path("/customers/")
public void updateCustomer(final Customer customer){
}
@PUT
@Path("/accounts/")
public void updateAccount(final Account account){
}
@GET
@Path("/customers/{customerId}/")
public Customer loadCustomer(@PathParam("customerId") final String customerId){
return null;
}
@GET
@Path("/customers/{customerId}/accounts/")
List<Account> loadAccountsForCustomer(@PathParam("customerId") final String customerId){
return null;
}
@GET
@Path("/accounts/{accountNumber}")
Account loadAccount(@PathParam("accountNumber") final String accountNumber){
return null;
}
}
【问题讨论】:
标签: rest apache-camel