dev@jsr311.java.net

Re: JSR311: Re: Some proposals / questions for JSR 311

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Wed, 30 Jan 2008 12:15:18 -0500

On Jan 30, 2008, at 10:28 AM, Marc Hadley wrote:
>
>> Request.evaluatePreconditions()
>> RFC 2616, Section 10.3.5 requires, that the headers Content-
>> Location, Expires, Cache-Control and/or vary must be under some
>> conditions. How it s possible with the current spec? Perhaps the
>> method should return a ResponseBuilder instead of a Response. So
>> the application developer can add it.
>>
> Good suggestion. I think its possible for an implementation to
> create a Vary header if the selectVariant method was previously
> called but I can't see any way for it to know the values of the
> other headers. I'll make this change and add a reference to the
> above section to highlight the need to add these headers if
> appropriate.
>
This is trickier than I thought.

Returning ResponseBuilder makes it difficult to examine the response
code and headers set by the method since it doesn't have any getters.
You can call the build() method to get a Response but unfortunately
doing so resets the builder to a blank state so you then have to start
with a new builder if you want to add to the metadata.

I can see three ways forward:

(i) Make ResponseBuilder.build() not reset the state of the builder.
We'd then need to decide whether a returned Response is linked to the
builder (i.e. a subsequent change to the builder changes the values
returned by the response) or whether it is not linked which I guess
would require some kind of copy-on-write approach.
(ii) Add a method to Response that creates a new builder from a
response instance. Again we'd need to decide whether the resulting
builder was linked to the response that spawned it or not.
(iii) Add getters to ResponseBuilder. I think the logical conclusion
of this would be to merge Response and ResponseBuilder in some way
since, if we add getters to ResponseBuilder, there seems to be little
need for Response.

My current preference is for (i) with the returned Response unlinked
from the ResponseBuilder (copy-on-write for efficiency).

Thoughts ?
Marc.

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.