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:24:53 +0100

On 11/29/2011 04:47 PM, 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.
> Here I am writing my JAX-RS 2 impl:
>
> FilterContextImpl.stop( return FilterAction.STOP ):
>
> FilterAction action = filter.preFilter()
> if (action == FilterAction.STOP {
> // sucks, I already returned FilterAction.STOP from my filter impl
> }

First of all, the API is for making users, not implementors life easier.

Secondly, I have a strong feeling you misread my proposal. Otherwise you would have noticed that stop action takes a
Response as an input parameter, which means you cannot simply use enum to represent it, not can you implement the method
the way you implemented it above.

>
> how about this piece:
>
>> public void preFilter(ctx) {
>>
>> if (stop) {
>> context.stop(response);
> // ooops
>> return FilterAction.CONTINUE
>> }
>>
>> }
>
> I'm just seeing a bad dream I guess
> Sergey
>

Who is promoting to use the code above? Certainly not me.

Marek

>
>>
>> Marek
>>
>>
>> On 11/29/2011 04:22 PM, Bill Burke wrote:
>>>
>>>
>>> On 11/29/11 8:43 AM, Marek Potociar wrote:
>>>> public class MyFilter implements RequestFilter {
>>>>
>>>> public FilterAction preFilter(FilterContext context) {
>>>> // ... do some request processing
>>>> if (stopProcessing) {
>>>> return context.stop(response);
>>>> }
>>>>
>>>> return context.continue(request);
>>>> }
>>>> }
>>>>
>>>
>>> Why do you need FilterAction if these methods would be available on FilterContext?
>>>
>>>
>>> it could be just:
>>>
>>> public void preFilter(ctx) {
>>>
>>> if (stop) {
>>> context.stop(response);
>>> return;
>>> }
>>>
>>> context.continue(request);
>>>
>>> }
>>>
>
>