All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pm.japi.spring.handler.WebMvcRequestHandler Maven / Gradle / Ivy

The newest version!
package com.pm.japi.spring.handler;

import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.condition.NameValueExpression;
import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;

import java.lang.annotation.Annotation;
import java.util.Optional;
import java.util.Set;

public class WebMvcRequestHandler {

    private final RequestMappingInfo requestMapping;
    private final HandlerMethod handlerMethod;

    public WebMvcRequestHandler(RequestMappingInfo requestMapping, HandlerMethod handlerMethod) {
        this.requestMapping = requestMapping;
        this.handlerMethod = handlerMethod;
    }

    public HandlerMethod getHandlerMethod() {
        return handlerMethod;
    }

    public Class declaringClass() {
        return handlerMethod.getBeanType();
    }

    public boolean isAnnotatedWith(Class annotation) {
        return null != AnnotationUtils.findAnnotation(handlerMethod.getMethod(), annotation);
    }

    public PatternsRequestCondition getPatternsCondition() {
        return requestMapping.getPatternsCondition();
    }


    public String getName() {
        return handlerMethod.getMethod().getName();
    }

    public Set supportedMethods() {
        return requestMapping.getMethodsCondition().getMethods();
    }

    public Set produces() {
        return requestMapping.getProducesCondition().getProducibleMediaTypes();
    }

    public Set consumes() {
        return requestMapping.getConsumesCondition().getConsumableMediaTypes();
    }

    public Set> headers() {
        return requestMapping.getHeadersCondition().getExpressions();
    }

    public Set> params() {
        return requestMapping.getParamsCondition().getExpressions();
    }

    public  Optional findAnnotation(Class annotation) {
        return Optional.ofNullable(AnnotationUtils.findAnnotation(handlerMethod.getMethod(), annotation));
    }


    public  Optional findControllerAnnotation(Class annotation) {
        return Optional.ofNullable(AnnotationUtils.findAnnotation(handlerMethod.getBeanType(), annotation));
    }

    public RequestMappingInfo getRequestMapping() {
        return requestMapping;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy