users@jersey.java.net

[Jersey] Re: Manipulating HTTP headers in MessageBodyWriter

From: Maarten Boekhold <boekhold_at_gmx.com>
Date: Sun, 01 Mar 2015 13:15:47 +0400

Hi Marek,

Yes, in fact the documentation is quite clear about this. I'm not sure
why I overlooked that sentence. The only suggestion I have to make this
more clear is perhaps to reword this as:

"The message header map is transmitted on the first write to the output
stream. It is allowed to make modifications to this map, as long as this
is done before the first write to the output stream".

And perhaps put it in italic bold :)

Maarten

On 2015-02-25 16:40, Marek Potociar wrote:
> I wonder how we could make the API documentation more clear about this:
> https://jax-rs-spec.java.net/nonav/2.0-rev-a/apidocs/javax/ws/rs/ext/MessageBodyWriter.html#writeTo(T,%20java.lang.Class,%20java.lang.reflect.Type,%20java.lang.annotation.Annotation[],%20javax.ws.rs.core.MediaType,%20javax.ws.rs.core.MultivaluedMap,%20java.io.OutputStream)
> <https://jax-rs-spec.java.net/nonav/2.0-rev-a/apidocs/javax/ws/rs/ext/MessageBodyWriter.html#writeTo%28T,%20java.lang.Class,%20java.lang.reflect.Type,%20java.lang.annotation.Annotation%5B%5D,%20javax.ws.rs.core.MediaType,%20javax.ws.rs.core.MultivaluedMap,%20java.io.OutputStream%29>
>
> <quote>
> /The message header map is mutable but any changes must be made before
> writing to the output stream since the headers will be flushed prior
> to writing the message body./
> </quote>
>
> IOW, yes, you can update the header map and expect the updated map to
> be written as soon as you invoke your first write operation on the
> entity stream.
>
> Marek
>
>> On 25 Feb 2015, at 09:00, Maarten Boekhold <boekhold_at_gmx.com
>> <mailto:boekhold_at_gmx.com>> wrote:
>>
>> Hi,
>>
>> Looking at this again, and I'm actually a little confused as to how I
>> can manipulate the HTTP headers from here. Should I just update teh
>> MultivaluedMap<String, String> httpHeaders? If so, I assume that the
>> runtime will actually write out the contents of httpHeaders upon the
>> first call to entityStream.writeTo()?
>>
>> Maarten
>>
>> On 2015-02-24 20:29, Marek Potociar wrote:
>>> Yes, but ONLY BEFORE you write first few bytes into the output stream.
>>>
>>> Marek
>>>
>>>> On 22 Feb 2015, at 13:20, Maarten Boekhold <boekhold_at_gmx.com
>>>> <mailto:boekhold_at_gmx.com>> wrote:
>>>>
>>>> Hi,
>>>>
>>>> As per the subject: is this allowed/possible?
>>>>
>>>> Maarten
>>
>