ufasoli
ufasoli

Reputation: 1068

Jersey @PreMatching and name binding in 1 provider

I need to implement a Jersey filter (ContainerRequestFilter) that needs to be called during pre-matching phase but only apply to some resources.

The pre-matching part can be done by annotating the class with the @PreMatching annotation and the "apply to some" functionality through Jersey's NameBinding mechanism.

What I would need it to combine the 2 features in 1 provider; now I'm pretty sure that this cannot be done since to me it seems contradictory (filter will be called before we can check if a given class is annotated) but still I want to be 100% sure of this since I would be skipping 1 step in the Jersey lifecycle and thus reducing the response time.

I'm using Jersey 2.6

Thanks

Upvotes: 3

Views: 1563

Answers (1)

joscarsson
joscarsson

Reputation: 4859

I can't specifically answer wether it is possible or not, but I wanted to comment on the "skipping 1 step to reduce response time": I would say you won't even need to consider that at all at this point. Aim at making your code easy to read and to understand (perhaps it will be a better structure to split in both filter and some feature class and share common code anyway).

IF you run into performance problems/long response times during test/early deploy, profile your app and see what actually takes time and focus on those areas first. I'm very confident the time is not spent where you think it is, and I'll buy you a beer if it actually ends up being this extra step in the lifecycle causing your (any) performance problems.

Upvotes: 1

Related Questions