users@jax-rs-spec.java.net

[jax-rs-spec users] [jsr339-experts] Re: Re: Re: FilterAction and FilterContext

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Tue, 29 Nov 2011 17:38:45 +0100

On 11/29/2011 05:03 PM, Bill Burke wrote:
>
>
> On 11/29/11 10:47 AM, Sergey Beryozkin wrote:
>> On 29/11/11 15:39, Marek Potociar wrote:
>>> That's another viable option IMO.
>>>
>>> Although I still prefer the filter to actively return the continuation
>>> as it's more in line with the simpler, functional
>>> programming style (like it or not, JAX-RS filter IS a function) as
>>> well as because I find it personally more robust,
>>> readable and less error prone (as it eliminates potential
>>> illegal/unintended context states) e.g.:
>>>
>>> public void preFilter(ctx) {
>>>
>>> if (stop) {
>>> context.stop(response);
>>> // bug - forgot the return
>>> }
>>>
>>> context.continue(request);
>>> // what now? is the above going to produce an exception or just continue?
>>> }
>>
>> The whole idea about using an input parameter to indicate a course of
>> action is just a broken, broken, broken idea, apologies for getting into
>> the loop here.
>
> I agree. Whenever I see myself with a method returning a State enum I feel I've done something wrong and the method
> needs to be refactored.
>

Seems to me we all three can agree on that. Sadly, it also seems to me that we are not talking about my proposal
anymore. Just to remind you couple of sentences from my proposal:

"I would propose to convert FilterAction to an opaque interface that is returned from the filter. Instances of the
interface would be produced by a call to the provided FilterContext instance ..."

What I am shooting for is to make filter return the complete continuation, including all the necessary data (req, resp,
...). How you implement the continuation and what data would it contain is completely up to you. Perhaps your
FilterContext impl class can directly implement the FA interface and just return this after updating itself, perhaps you
may want to add a new non-static inner class to your context impl, or perhaps you want to do it in another completely
cool and efficient way...

My main point here is: I do *not* propose to return enum instance. I propose to replace the enum with a continuation
interface.

Marek