You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Fabio Martelli <fa...@gmail.com> on 2013/10/08 11:36:32 UTC

rest service method interceptor

Hi, I'm working on Apache Syncope in order to provide centralized 
notification and audit mechanisms.
I was thinking to inercept each rest service call in order to be able to 
provide this feature.

As you can imagine, a lot of info are required to discriminate request 
and response.
In particular I need to know:
1. the called service method (handled java method);
2. the provided parameters (maybe castable to the corresponding java 
objects);
3. the result (returned object or exception).

Is there someone that can point me in the right direction.
Thank you in advance.

Best reagrds,
F.

Re: rest service method interceptor

Posted by Sergey Beryozkin <sb...@gmail.com>.
One possible approach is to use ClientRequestFilter with both 
ResourceInfo & UriInfo,

The former will give you a target method and its parameters, which in 
turn can give you the names of Path/Query/Matrix parameters from the 
param annotations, UriInfo can then be used to extract individual values.

This won't give you an access to the parameter representing the 
deserialized InputStream (the request body), if any - but you can access 
InputStream and replace it with a buffered stream if needed from 
ContanerRequestFilter

Cheers, Sergey

On 08/10/13 12:26, Sergey Beryozkin wrote:
> Actually, that probably won;t help enough on the in side, as you need an
> access to the actual parameter instances.
>
> I guess a custom CXF Invoker is where you can get the most info:
>
> http://cxf.apache.org/docs/jax-rs-filters.html#JAX-RSFilters-Custominvokers,
>
>
> or you may still work with ContainerRequestFilter, but add some
> CXF-specific code into it (may in its extension),
>
> Message m = PhaseInterceptorChain.getCurrentMessage();
> List<Object> methodParams = MessageContentsList getContentsList(m);
>
> I wonder if JAX-RS should get ResourceInfo interface extended a bit
>
> Thanks, Sergey
>
>
>
> On 08/10/13 12:14, Sergey Beryozkin wrote:
>> Hi
>> On 08/10/13 10:36, Fabio Martelli wrote:
>>> Hi, I'm working on Apache Syncope in order to provide centralized
>>> notification and audit mechanisms.
>>> I was thinking to inercept each rest service call in order to be able to
>>> provide this feature.
>>>
>>> As you can imagine, a lot of info are required to discriminate request
>>> and response.
>>> In particular I need to know:
>>> 1. the called service method (handled java method);
>>> 2. the provided parameters (maybe castable to the corresponding java
>>> objects);
>>> 3. the result (returned object or exception).
>>>
>>> Is there someone that can point me in the right direction.
>>
>> Can you try JAX-RS 2.0 ContainerRequestFilter with the injected
>>
>> RequestInfo:
>>
>> https://jax-rs-spec.java.net/nonav/2.0/apidocs/javax/ws/rs/container/ResourceInfo.html
>>
>>
>>
>> (add it as as a @Context-annotated field to your filter implementation).
>>
>> On the outbound side, ContainerResponseFilter (and its context) will
>> give you an access to the response object
>>
>> HTH, Sergey
>>
>>> Thank you in advance.
>>>
>>> Best reagrds,
>>> F.
>>
>


Re: rest service method interceptor

Posted by Sergey Beryozkin <sb...@gmail.com>.
Actually, that probably won;t help enough on the in side, as you need an 
access to the actual parameter instances.

I guess a custom CXF Invoker is where you can get the most info:

http://cxf.apache.org/docs/jax-rs-filters.html#JAX-RSFilters-Custominvokers,

or you may still work with ContainerRequestFilter, but add some 
CXF-specific code into it (may in its extension),

Message m = PhaseInterceptorChain.getCurrentMessage();
List<Object> methodParams = MessageContentsList getContentsList(m);

I wonder if JAX-RS should get ResourceInfo interface extended a bit

Thanks, Sergey



On 08/10/13 12:14, Sergey Beryozkin wrote:
> Hi
> On 08/10/13 10:36, Fabio Martelli wrote:
>> Hi, I'm working on Apache Syncope in order to provide centralized
>> notification and audit mechanisms.
>> I was thinking to inercept each rest service call in order to be able to
>> provide this feature.
>>
>> As you can imagine, a lot of info are required to discriminate request
>> and response.
>> In particular I need to know:
>> 1. the called service method (handled java method);
>> 2. the provided parameters (maybe castable to the corresponding java
>> objects);
>> 3. the result (returned object or exception).
>>
>> Is there someone that can point me in the right direction.
>
> Can you try JAX-RS 2.0 ContainerRequestFilter with the injected
>
> RequestInfo:
>
> https://jax-rs-spec.java.net/nonav/2.0/apidocs/javax/ws/rs/container/ResourceInfo.html
>
>
> (add it as as a @Context-annotated field to your filter implementation).
>
> On the outbound side, ContainerResponseFilter (and its context) will
> give you an access to the response object
>
> HTH, Sergey
>
>> Thank you in advance.
>>
>> Best reagrds,
>> F.
>


Re: rest service method interceptor

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 08/10/13 10:36, Fabio Martelli wrote:
> Hi, I'm working on Apache Syncope in order to provide centralized
> notification and audit mechanisms.
> I was thinking to inercept each rest service call in order to be able to
> provide this feature.
>
> As you can imagine, a lot of info are required to discriminate request
> and response.
> In particular I need to know:
> 1. the called service method (handled java method);
> 2. the provided parameters (maybe castable to the corresponding java
> objects);
> 3. the result (returned object or exception).
>
> Is there someone that can point me in the right direction.

Can you try JAX-RS 2.0 ContainerRequestFilter with the injected

RequestInfo:

https://jax-rs-spec.java.net/nonav/2.0/apidocs/javax/ws/rs/container/ResourceInfo.html 


(add it as as a @Context-annotated field to your filter implementation).

On the outbound side, ContainerResponseFilter (and its context) will 
give you an access to the response object

HTH, Sergey

> Thank you in advance.
>
> Best reagrds,
> F.