Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended ActionFilter to also enable filtering the response side #7465

Closed
wants to merge 1 commit into from
Closed

Extended ActionFilter to also enable filtering the response side #7465

wants to merge 1 commit into from

Conversation

uboness
Copy link
Contributor

@uboness uboness commented Aug 26, 2014

Enables filtering the actions on both sides - request and response. Also added a base class for filter implementations (cleans up filters that only need to filter one side)

if (i < this.action.filters.length) {
this.action.filters[i].process(actionName, request, listener, this);
} else if (i == this.action.filters.length) {
this.action.doExecute((Request) request, new FilteredActionListener<Response>(actionName, listener, new ResponseFilterChain(this.action.filters, logger)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that we also filter responses by creating a new response filter chain and filtered action listener, this inner class is not just a request filter chain... can we maybe merge the two at this point? Seems like in the end we either filters nothing or both (request and response) anyway...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging it means there's no proper handling for implementation that accidentally/intentionally call continueProcessing multiple times. Have two different chain instances keeps it clean and safe in that regard. The other option is to merge the code, but still create separate instances, but that's ugly and creates a mess (having single instance that behaves differently in different scenarios)... hence the two separate internal implementations - it's clean.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to agree with luca I think this entire recursive continueProcessing is very confusing. I wonder if we can solve this simply interatively by returning a boolean from process that way we can implement this as a simple loop? Maybe I am missing the big picture?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the recursive nature of the filters is actually not related to this specific issue here... but while on the subject, the goal here was to create a async filtering pipeline... if I understand you correctly (might be that I'm not), a loop will block.

As for this specific issue, the question was whether to use the same chain for both sides (request & response)... and we could... but that means we'll loose the handling of the "too many calls for continueProcessing" errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I am wrong but these filters have to be executed in a serial fashion one after another, right? So you can make this async if you need to on top of the blocking loop? I would like to see an example where this is used to understand the rational please :)

@javanna
Copy link
Member

javanna commented Aug 27, 2014

Left a few comments

@javanna javanna removed the review label Aug 27, 2014
* Enables filtering the execution of an action on the response side, either by sending a response through the
* {@link ActionListener} or by continuing the execution through the given {@link ActionFilterChain chain}
*/
void process(String action, ActionResponse response, ActionListener listener, ActionFilterChain chain);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general I think this method should be called apply rather than process?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree! I'd also add the ActionFilterChain#continueProcessing should be renamed to ActionFilterChain#proceed

Enables filtering the actions on both sides - request and response. Also added a base class for filter implementations (cleans up filters that only need to filter one side)

Also refactored the filter & filter chain methods to more intuitive names
@uboness
Copy link
Contributor Author

uboness commented Sep 3, 2014

@s1monw as we discussed, added a simple base class that relieves the implementation from dealing with filter chain. The base class is an abstract component as the way action filters are registered is via the modules (and the module binds them).

Also renamed the methods to have more intuitive names.

@s1monw
Copy link
Contributor

s1monw commented Sep 5, 2014

LGTM except of the _ in the method name please fix that one

@uboness
Copy link
Contributor Author

uboness commented Sep 6, 2014

merged in 333a39c

@uboness uboness closed this Sep 6, 2014
@clintongormley clintongormley changed the title Extended ActionFilter to also enable filtering the response side Internal: Extended ActionFilter to also enable filtering the response side Sep 8, 2014
@clintongormley clintongormley changed the title Internal: Extended ActionFilter to also enable filtering the response side Extended ActionFilter to also enable filtering the response side Jun 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants