Hi,
that's what I am doing currently, but I would have preferred avoiding
doing that since there are a lot of other resources and other calls for
which it's perfectly useless to do that check. Using the DynamicFeature,
this would allow me to only bind that filter to appropriate resources
and sub-resources.
But maybe that's just not worth it.
Kr,
Guillaume
On 2015-04-29 13:34, Marek Potociar wrote:
> I thought that you would bind your filters to all methods and then use UriInfo information from the filter code. That way you will use it from within a request scope.
>
> Marek
>
> On 28 Apr 2015, at 10:28, guillaume.polet_at_bluepimento.eu wrote:
>
> Hi Marek,
>
> unfortunately we cannot use UriInfo outside the scope of a request. I tried and throws an IllegalStateException. This is also confirmed by the javadoc
>
> All methods throw {_at_code java.lang.IllegalStateException} if called outside the scope of a request (e.g. from a provider constructor).
>
> Any other ideas?
>
> Guillaume
>
> On 27.04.2015 16:43, Marek Potociar wrote: You can try injecting javax.ws.rs.core.UriInfo in your dynamic feature and then check the result of UriInfo.getMatchedResources()...
>
> Marek
>
> On 25 Apr 2015, at 10:15, Guillaume Polet <guillaume.polet_at_bluepimento.eu> wrote:
>
> Hi,
>
> How can I bind a filter to all the method of a Resource as well as to all the methods of its sub-resources?
>
> For example, if I have the following 2 resources: import javax.inject.Singleton;
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
> import javax.ws.rs.PathParam;
> import javax.ws.rs.Produces;
> import javax.ws.rs.core.MediaType;
> import javax.ws.rs.core.Response;
>
> import org.glassfish.jersey.server.model.Resource;
>
> @Path("/myresource/{id: \\d+ [1]}")
> @Produces(MediaType.APPLICATION_JSON)
> @Singleton
> class RootResource {
>
> @GET
> @Produces(MediaType.APPLICATION_JSON)
> public Response get(@PathParam("id") Long id) {
> return Response.ok().build();
> }
>
> @Path("/sub")
> public Resource getSubResource() {
> return Resource.from(SubResource.class);
> }
> }
>
> @Produces(MediaType.APPLICATION_JSON)
> @Singleton
> class SubResource {
> @GET
> @Path("/{subid: \\d+ [1]}")
> public Response get(@PathParam("id") Long id, @PathParam("subid") Long subid) {
> return Response.ok().build();
> }
> }
>
> I would like to filter RootResource.get(Long) and SubResource.get(Long, Long). But if I have other resources, those should not be filtered.
>
> Using the DynamicFeature, we only have info on the Class and Method. Is there an easy way to find if that method is actually a sub-resource of a given resource (I would like this to work also on sub-sub-resources, sub-sub-sub-resources, etc...)
>
> The alternative is to write a global filter and check if the RootResource is amongst the set of matched resources, but it's a bit less efficient I guess.
>
> Cheers,
> Guillaume
--
Guillaume Polet
Mob: +32 489 46 39 45
Blue Pimento Services s.p.r.l.
Rue Laid Burniat, 3
B-1348 Louvain-la-neuve
☎ +32 10 390 014
Fax +32 10 390 001
Visit our web site: www.bluepimento.eu [2]
Links:
------
[1] smb://d+
[2] http://www.bluepimento.eu