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

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

Introduction

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

Prototype

@Nullable
public RequestCondition<?> getCustomCondition() 

Source Link

Document

Return the "custom" condition of this RequestMappingInfo , or 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 w  w  .  j  a  v  a2  s  .  c om
 */
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);
    }
}