Example usage for org.springframework.web.method HandlerMethod getMethodAnnotation

List of usage examples for org.springframework.web.method HandlerMethod getMethodAnnotation

Introduction

In this page you can find the example usage for org.springframework.web.method HandlerMethod getMethodAnnotation.

Prototype

@Nullable
public <A extends Annotation> A getMethodAnnotation(Class<A> annotationType) 

Source Link

Document

Return a single annotation on the underlying method traversing its super methods if no annotation can be found on the given method itself.

Usage

From source file:org.jutge.joc.porra.recaptcha.interceptor.ReCaptchaInterceptor.java

private static ReCaptchaConsumer getReCaptchaConsumerAnnotation(final Object handler) {
    if (handler instanceof HandlerMethod) {
        final HandlerMethod handlerMethod = (HandlerMethod) handler;
        return handlerMethod.getMethodAnnotation(ReCaptchaConsumer.class);
    }/*from   w  w  w .ja va2  s.com*/
    return null;
}

From source file:de.otto.mongodb.profiler.web.CacheInterceptor.java

protected boolean noCache(HandlerMethod handler) {

    return handler.getMethodAnnotation(NoCache.class) != null
            || AnnotationUtils.findAnnotation(handler.getBeanType(), NoCache.class) != null;
}

From source file:de.thm.arsnova.web.DeprecatedApiInterceptorHandler.java

private DeprecatedApi getDeprecatedApiAnnotation(final Object handler) {
    if (!(handler instanceof HandlerMethod)) {
        return null;
    }//from  ww w .  j a v a  2  s .  co  m

    final HandlerMethod handlerMethod = (HandlerMethod) handler;
    return handlerMethod.getMethodAnnotation(DeprecatedApi.class);
}

From source file:springfox.documentation.swagger.readers.operation.OperationHiddenReader.java

@Override
public void apply(OperationContext context) {

    HandlerMethod handlerMethod = context.getHandlerMethod();
    ApiOperation methodAnnotation = handlerMethod.getMethodAnnotation(ApiOperation.class);
    if (null != methodAnnotation) {
        context.operationBuilder().hidden(methodAnnotation.hidden());
    }/*from  w w  w .  j av a  2s .c  o  m*/
}

From source file:springfox.documentation.swagger.readers.operation.OperationNotesReader.java

@Override
public void apply(OperationContext context) {

    HandlerMethod handlerMethod = context.getHandlerMethod();
    ApiOperation methodAnnotation = handlerMethod.getMethodAnnotation(ApiOperation.class);
    if (null != methodAnnotation && StringUtils.hasText(methodAnnotation.notes())) {
        context.operationBuilder().notes(methodAnnotation.notes());
    }// w w  w  . ja va  2  s  .c o  m
}

From source file:com.kodgemisi.common.thymeleaf.ThymeleafLayoutInterceptor.java

private Layout getMethodOrTypeAnnotation(HandlerMethod handlerMethod) {
    Layout layout = handlerMethod.getMethodAnnotation(Layout.class);
    if (layout == null) {
        return handlerMethod.getBeanType().getAnnotation(Layout.class);
    }/*  w  w  w .  ja v  a 2s  .c o m*/
    return layout;
}

From source file:com.zuoxiaolong.blog.common.authorization.AuthorizationInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    HandlerMethod handlerMethod = (HandlerMethod) handler;
    CheckLogin checkLogin = handlerMethod.getMethodAnnotation(CheckLogin.class);
    if (checkLogin != null) {
        checkLogin(request);//w  w w  .  ja va 2  s.c  om
    }
    checkLogin = handlerMethod.getBeanType().getDeclaredAnnotation(CheckLogin.class);
    if (checkLogin != null) {
        checkLogin(request);
    }
    return super.preHandle(request, response, handler);
}

From source file:springfox.documentation.swagger.readers.operation.OperationNicknameIntoUniqueIdReader.java

@Override
public void apply(OperationContext context) {

    HandlerMethod handlerMethod = context.getHandlerMethod();
    ApiOperation methodAnnotation = handlerMethod.getMethodAnnotation(ApiOperation.class);
    if (null != methodAnnotation && StringUtils.hasText(methodAnnotation.nickname())) {
        // Populate the value of nickname annotation into uniqueId
        context.operationBuilder().uniqueId(methodAnnotation.nickname());
        context.operationBuilder().codegenMethodNameStem(methodAnnotation.nickname());
    }//from   www  .j  a v  a 2  s.  co m
}

From source file:de.thm.arsnova.web.CacheControlInterceptorHandler.java

private CacheControl getCacheControlAnnotation(final Object handler) {
    if (!(handler instanceof HandlerMethod)) {
        return null;
    }/*w  w  w. j a  v a  2  s .c  o m*/

    final HandlerMethod handlerMethod = (HandlerMethod) handler;
    return handlerMethod.getMethodAnnotation(CacheControl.class);
}

From source file:com.hypersocket.json.ControllerInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    if (handler instanceof HandlerMethod) {

        HandlerMethod method = (HandlerMethod) handler;

        if (method.getMethodAnnotation(AuthenticationRequired.class) != null
                || method.getMethodAnnotation(AuthenticationRequiredButDontTouchSession.class) != null) {

            if (!(method.getBean() instanceof AuthenticatedController)) {
                if (log.isErrorEnabled()) {
                    log.error(/* ww  w  .  ja va 2  s . c om*/
                            "Use of @AuthenticationRequired annotation is restricted to subclass of AuthenticatedController");
                }
                throw new IllegalArgumentException(
                        "Use of @AuthenticationRequired annotation is restricted to subclass of AuthenticatedController");
            }

            AuthenticatedController contrl = (AuthenticatedController) method.getBean();

            if (method.getMethodAnnotation(AuthenticationRequiredButDontTouchSession.class) != null) {
                contrl.getSessionUtils().getSession(request);
            } else {
                contrl.getSessionUtils().touchSession(request, response);
            }
        }
    }

    return true;

}