Hi Anthony
On 05/07/12 11:17, Muller, Anthony wrote:
Hello,

I have a use case when I need to intercept some REST calls to lock a used 
resource (underlying code doesn't support concurrent access). I wish to use an 
CXF interceptor to implement the lock mechanism (something else can help ?)

Example of concurrent calls:
Client 1 : [POST]<baseurl>/books/1234/chapters/ -->  Book « 1234 » must be 
locked to avoid concurrent modifications
Client 2 : [POST]<baseurl>/books/1234/chapters/56/paragraph -->  Webservice 
must wait because book « 1234 » is currently locked

So, I wish to add a CXF interceptor on URL starting by « /books/{bookId}/... », 
but I don't see how can I do...

(In my case, I can not use Servlet API...)


I think the simplest way is to create a class implementing both RequestHandler and ResponseHandler interfaces and have a '@Context UriInfo' injected (which is thread safe).

You can use UriInfo.getPath() method to get values like 'books/1234/chapters', etc. Perhaps, even simpler, is to do RequestHandler'message.get(Message.REQUEST_URI)', where 'message' is of type Message and is available as a method parameter.

This implementation will 'lock' by updating the concurrent cache of some sort (Colm done few Ehcache based implementations in CXF for example) in its handleRequest method and 'unlock' in its handleResponse if it is 'books/1234/chapters'. It can be registered as a jaxrs:provider



Hope that helps :-)

Sergey

Can you help ?

Thanks and regards,
Anthony


Reply via email to