Example usage for org.springframework.web.servlet.mvc.method RequestMappingInfo getHeadersCondition

List of usage examples for org.springframework.web.servlet.mvc.method RequestMappingInfo getHeadersCondition

Introduction

In this page you can find the example usage for org.springframework.web.servlet.mvc.method RequestMappingInfo getHeadersCondition.

Prototype

public HeadersRequestCondition getHeadersCondition() 

Source Link

Document

Return the "headers" condition of this RequestMappingInfo ; or instance with 0 header expressions (never null ).

Usage

From source file:de.codecentric.boot.admin.web.PrefixHandlerMapping.java

private RequestMappingInfo withPrefix(RequestMappingInfo mapping) {
    List<String> newPatterns = getPatterns(mapping);

    PatternsRequestCondition patterns = new PatternsRequestCondition(
            newPatterns.toArray(new String[newPatterns.size()]));
    return new RequestMappingInfo(patterns, mapping.getMethodsCondition(), mapping.getParamsCondition(),
            mapping.getHeadersCondition(), mapping.getConsumesCondition(), mapping.getProducesCondition(),
            mapping.getCustomCondition());
}

From source file:org.springbyexample.mvc.method.annotation.ServiceHandlerMapping.java

/**
 * Register handler./*from  w ww.j a  va 2  s.c o  m*/
 */
private void registerHandler(Class<?> marshallingServiceClass, Method method) {
    ApplicationContext ctx = getApplicationContext();

    RestResource restResource = AnnotationUtils.findAnnotation(marshallingServiceClass, RestResource.class);
    Class<?> serviceClass = restResource.service();

    RestRequestResource restRequestResource = AnnotationUtils.findAnnotation(method, RestRequestResource.class);
    boolean export = (restRequestResource != null ? restRequestResource.export() : true);
    boolean relative = (restRequestResource != null ? restRequestResource.relative() : true);

    if (export) {
        Class<?> handlerServiceClass = serviceClass;
        String methodName = method.getName();
        Class<?>[] paramTypes = method.getParameterTypes();

        if (restRequestResource != null) {
            // explicit service specified
            if (restRequestResource.service() != ServiceValueConstants.DEFAULT_SERVICE_CLASS) {
                handlerServiceClass = restRequestResource.service();
            }

            // explicit method name specified
            if (StringUtils.hasText(restRequestResource.methodName())) {
                methodName = restRequestResource.methodName();
            }
        }

        Object handler = ctx.getBean(handlerServiceClass);
        Method serviceMethod = ClassUtils.getMethod(handlerServiceClass, methodName, paramTypes);
        RequestMappingInfo mapping = getMappingForMethod(method, marshallingServiceClass);

        if (relative) {
            List<String> patterns = new ArrayList<String>();

            for (String pattern : mapping.getPatternsCondition().getPatterns()) {
                // add REST resource path prefix to URI,
                // if relative path is just '/' add an empty string
                patterns.add(restResource.path() + (!"/".equals(pattern) ? pattern : ""));
            }

            // create a new mapping based on the patterns (patterns are unmodifiable in existing RequestMappingInfo)
            mapping = new RequestMappingInfo(
                    new PatternsRequestCondition(patterns.toArray(ArrayUtils.EMPTY_STRING_ARRAY),
                            getUrlPathHelper(), getPathMatcher(), useSuffixPatternMatch(),
                            useTrailingSlashMatch()),
                    mapping.getMethodsCondition(), mapping.getParamsCondition(), mapping.getHeadersCondition(),
                    mapping.getConsumesCondition(), mapping.getProducesCondition(),
                    mapping.getCustomCondition());
        }

        // need to set param types to use in createHandlerMethod before calling registerHandlerMethod
        restBridgedMethod = BridgeMethodResolver.findBridgedMethod(method);

        // mapping is key, HandlerMethod is value
        registerHandlerMethod(handler, serviceMethod, mapping);

        processConverters(restRequestResource, mapping, serviceMethod);
    }
}