0

I´m using JAX-RS Request filter where my endpoint annotation @Country contains some information of the country that my filter need to do some stuff.

@GET
@Path("/country")
@Country("ESP")
public Future<String> countryResource(Future<String> future) throws Exception {

So now my filter is invoked since this method contains the same filter

@Priority(3)
@Primary
@Provider
@Country
class CountryFilter extends ContainerRequestFilter {

    override def filter(context: ContainerRequestContext): Unit = {
        //Here I need to get the "ESP" from the endpoint annotation
    }
}

I'm not an expert of JAX-RS but I doubt is possible to know what information of the annotation of my endpoint has, but since the filter only is invoked in case a method add the annotation as well, I was just wondering if there was any magic here.

For now I was just using reflexion to look for all methods annotated as @Country and whose @Path it would be the same as the context.getUtiInfo of the ContainerRequestContext.

Is this the best and most efficient way to do it?.

Regards.

ETO
  • 6,970
  • 1
  • 20
  • 37
paul
  • 12,873
  • 23
  • 91
  • 153
  • 1
    Inject [ResourceInfo](https://stackoverflow.com/a/27863284/2587435) to get current class and method. Is that what you are asking? – Paul Samsotha Nov 14 '18 at 15:08
  • Brilliant and elegant solution!, thanks you my good sir! – paul Nov 14 '18 at 15:21
  • Im just going to close it as a duplicate because even though the questions were not exactly the same, the same solution covered both questions. Unless you want to write an answer, then I'll reopen it. – Paul Samsotha Nov 15 '18 at 05:52

0 Answers0