I am using Apach CXF as REST provider.
I want to gather data when I enter the webservice, gather data before I enter the resposne and add some calculation to the response. For this question and for simplicity, lets assume I want to get the starting time on entering, the finishing time before the response is sent and add the total time to the response.
Now, how do I do that? I created In and Out interceptors that works fine alone, but how do I use the data from the In interceptor in the Out interceptor?
Thanks
Idob
UPDATE:
I tried to set the data as contextual parameter with
message.setContextualProperty(key,value);
but I am getteing NULL on
message.getContextualProperty(key);
I also tried the same but just with
message.put(key,value) and message.get(key)
didn’t work.
Idea’s anyone?
Thank you,
Idob
You can store values on the
Exchange. CXF creates anExchangeobject for each request to act as a container for the in and out messages for the request/response pair and makes it accessible asmessage.getExchange()from both.In interceptor:
Out interceptor
(or vice-versa for client-side interceptors, where the out would store values and the in would retrieve them). Choose a key that you know won’t be used by other interceptors – a package-qualified name is a good choice. Note that, like
Message,Exchangeis aStringMapand has generic put/get methods taking aClassas the key that give you compile-time type safety and save you having to cast: