You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Esteban Wagner <wa...@gmail.com> on 2013/01/24 11:17:23 UTC

Message Content Reading in JAX-RS Filter

Hi,

I am implementing a jax-rs filter, and I need to read the associated
content of the message.

So I am doing this:

 message.getContent(InputStream.class);

The problem is that then in the pipeline the JacksonJsonProvider gets
called in order to deserialize the content and as the input stream has
already been read it generates an Exception:

*No content to map to Object due to end of input.*



Which would be the most effective way to handle this?

1) Copy the inputStream into another input stream and replace the Message
input stream with this one so its available to read on Deserialization?

2) Move the jax-rs filter into a CXF filter to the READ phase so it would
already have the deserialized object on the message?

3) ???

Many Thanks,

Esteban.

Re: Message Content Reading in JAX-RS Filter

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 24/01/13 10:47, Sergey Beryozkin wrote:
> Hi
> On 24/01/13 10:17, Esteban Wagner wrote:
>> Hi,
>>
>> I am implementing a jax-rs filter, and I need to read the associated
>> content of the message.
>>
>> So I am doing this:
>>
>> message.getContent(InputStream.class);
>>
>> The problem is that then in the pipeline the JacksonJsonProvider gets
>> called in order to deserialize the content and as the input stream has
>> already been read it generates an Exception:
>>
>> *No content to map to Object due to end of input.*
>>
>>
>>
>> Which would be the most effective way to handle this?
>>
>> 1) Copy the inputStream into another input stream and replace the Message
>> input stream with this one so its available to read on Deserialization?
>>
> If you need to pre-process it before JacksonJsonProvider reads it then
> yes, CXF CachedOutputStream can be useful for this;
>
> global/pre-match or post-match ContainerRequestFilter (JAX-RS 2.0,
> starting from CXF 2.7.0) can also be used for this or ReaderInterceptors
> - note I've just spotted I may be not calling post-match
> ContainerRequestFilter at the right time, so if you were to work with
> ContainerRequestFilter - don't use post-match one for now
>
Fixed it - will also work as expected in the soon to be released CXF

Sergey


>> 2) Move the jax-rs filter into a CXF filter to the READ phase so it would
>> already have the deserialized object on the message?
>>
> If it is acceptable to work with the deserialized object than yes, also
> you can register a custom invoker which will see this object.
>
>
> thanks, Sergey
>> 3) ???
>>
>> Many Thanks,
>>
>> Esteban.
>>
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Re: Message Content Reading in JAX-RS Filter

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 24/01/13 10:17, Esteban Wagner wrote:
> Hi,
>
> I am implementing a jax-rs filter, and I need to read the associated
> content of the message.
>
> So I am doing this:
>
>   message.getContent(InputStream.class);
>
> The problem is that then in the pipeline the JacksonJsonProvider gets
> called in order to deserialize the content and as the input stream has
> already been read it generates an Exception:
>
> *No content to map to Object due to end of input.*
>
>
>
> Which would be the most effective way to handle this?
>
> 1) Copy the inputStream into another input stream and replace the Message
> input stream with this one so its available to read on Deserialization?
>
If you need to pre-process it before JacksonJsonProvider reads it then 
yes, CXF CachedOutputStream can be useful for this;

global/pre-match or post-match ContainerRequestFilter (JAX-RS 2.0, 
starting from CXF 2.7.0) can also be used for this or ReaderInterceptors 
- note I've just spotted I may be not calling post-match 
ContainerRequestFilter at the right time, so if you were to work with 
ContainerRequestFilter - don't use post-match one for now

> 2) Move the jax-rs filter into a CXF filter to the READ phase so it would
> already have the deserialized object on the message?
>
If it is acceptable to work with the deserialized object than yes, also 
you can register a custom invoker which will see this object.


thanks, Sergey
> 3) ???
>
> Many Thanks,
>
> Esteban.
>