On Oct 13, 2009, at 10:51 AM, Zoltan Arnold NAGY wrote:
> Paul Sandoz wrote:
>>
>> On Oct 9, 2009, at 4:06 PM, Zoltan Arnold NAGY wrote:
>>
>>> Hi,
>>>
>>> Okay, I've managed to hash the entity on the client side. Now I'm
>>> having problem the server side.. :)
>>>
>>>
>>> I've created a filter which implements ContainerRequestFilter.
>>> Inside that, I'm trying to do this:
>>> try {
>>> byte[] bytes =
>>> IOUtils.toByteArray(request.getEntityInputStream());
>>> log.info("" + bytes.length);
>>> } catch(IOException e) {
>>> e.printStackTrace();
>>> }
>>>
>>
>> You are consuming the request, thus there are no more bytes to
>> read, hence the odd error from the JAXB unmarshaller.
>>
>> You need to do:
>>
>> request.setEntityInputStream(new ByteArrayInputStream(bytes));
> Sounds a bit twisted. :) If that's the case, when does that stream
> gets written to?
>
We are referring to a in-bound *request* received by the server. There
is no writing only reading.
What the above does is buffer the request entity so it can be re-read.
> Isn't the actual entity part of the incoming request?
Yes. And in your filter you consumed the request (read all the
bytes). Jersey never buffers the request entity for performance
reasons.
So if a filter needs to consume the request entity to say validate a
hash then it will need to ensure that it buffers the request so it is
available for further filters or the application to consume.
Paul.
> And by request I mean a PUT/POST request (we might
> differ about the terminology, thus the misunderstanding).
>
> Thanks,
> Zoltan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>