1
我想使用駱駝公開一個RESTfull web服務。我已經使用URI模板來定義我的服務合約。我想知道如何根據URI模板將請求路由到我的ServiceProcessor的相關方法。RESTfull Web服務公開的駱駝最佳實踐
作爲一個例子,採取以下兩種操作:
@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;
}
}
感謝亞歷山大! – Dilunika