vendredi 27 novembre 2015

Add annotation to all the controllers in play framework using global class or java reflection

In an existing project we want to introduce swagger for rest api documentation. We cant modify each and every controller and method. so , looking for a decorator which will automatically add the annotation to all the controller class and also which will add annotation for methods depending on the request type. Tried with java reflections but couldnt find any option to add annotation .

public <A> A getControllerInstance(Class<A> clazz) {
    Annotation[] annotations = clazz.getAnnotations();
    // This check is used to suppress any annotation if it is not injected
    // using spring DI. Example Security.Authenticated.
    if (clazz.isAnnotationPresent(Component.class))
        return ctx.getBean(clazz);
    else
        return null;
}

public Action onRequest(Request request, Method actionMethod) {
    System.out.println("before each request..." + request.toString());
    Object[] obj = actionMethod.getAnnotations();

    return super.onRequest(request, actionMethod);
}





Aucun commentaire:

Enregistrer un commentaire