2013-06-26 3 views
1

Я хочу открыть веб-сервис RESTfull с помощью верблюда. Я использовал шаблоны URI для определения моих контрактов на обслуживание. Я хочу знать, как мне направлять запросы к соответствующему методу моего ServiceProcessor на основе шаблона URI.Рекомендации лучших верблюдов для веб-сервиса RESTfull

В качестве примера возьмем следующие две операции:

 @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; 
    } 
} 

ответ

1

cxfrs конечной потребитель обеспечивает специальный обмен заголовок operationName, содержащий имя метода обслуживания (registerCustomerregisterAccount, и т.д.).

Вы могли бы решить, что делать с запросом, используя этот заголовок, как следующее:

<from uri="cxfrs://bean://customerCareServer" /> 
<choice> 
    <when> 
     <simple>${header.operationName} == 'registerCustomer'</simple> 
     <!-- registerCustomer request processing --> 
    </when> 
    <when> 
     <simple>${header.operationName} == 'registerAccount'</simple> 
     <!-- registerAccount request processing --> 
    </when> 
    .... 
</choice> 
+0

спасибо Александру !!! – Dilunika