1

camel を使用して RESTfull Web サービスを公開したいと考えています。URI テンプレートを使用してサービス コントラクトを定義しました。URI テンプレートに基づいて、ServiceProcessor の関連するメソッドにリクエストをルーティングする方法を知りたいです。

例として、次の 2 つの操作を取り上げます。

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

1 に答える 1

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>
于 2013-06-27T05:44:19.017 に答える