mercredi 9 novembre 2016

Java reflection: annotation not found even if it's present

I'm using reflection for find a method in a class and the get the annotation "PermessiNecessari" that describe the type of the operation (CREATE, DELETE,...)

public interface VlpgmoduliManagerFacadeRemote 
   extends InterfacciaFacadeRemote<Vlpgmoduli>{

  @POST 
  @javax.ws.rs.Path("getpermessimoduligruppo")
  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  @Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN})
  @PermessiNecessari(operation = STANDARD_OP.READ)
  public GridResponse<Vlpgmoduli> getPermessiModuliGruppo(MultivaluedMap<String, String> formParams, 
        String callback) 
        throws BadRequestException;
...

This is a piece of the searching-method :

facadeinterface = Class.forName(pm); // get the interface
Method metodo = getMetodoClasse(facadeinterface, metodoRest); // find method with @Path annotation
if(metodo != null){
   PermessiNecessari rp = metodo.getAnnotation(PermessiNecessari.class);

   if(rp != null){ // caso metodo con permessi
       return checkPermessiModulo(m, rp);
   }

   if(metodo.isAnnotationPresent(NonProtetto.class)){ 
       return true;
   }
   LOG.log(Level.WARNING, "Metodo trovato : {0}/{1}, ma non annotato!", new Object[]{metodoRest,metodo});

The method is found via @Path annotation, but when i want to get "PermessiNecessari" annotation, this annotation is not found!

PS : in other classes this system works fine.





Aucun commentaire:

Enregistrer un commentaire