/** * Uses method and type-level @{@link RequestMapping} annotations to create * the RequestMappingInfo. * @return the created RequestMappingInfo, or {@code null} if the method * does not have a {@code @RequestMapping} annotation. * @see #getCustomMethodCondition(Method) * @see #getCustomTypeCondition(Class) */ @Override @Nullable protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { RequestMappingInfo info = createRequestMappingInfo(method); if (info != null) { RequestMappingInfo typeInfo = createRequestMappingInfo(handlerType); if (typeInfo != null) { info = typeInfo.combine(info); } String prefix = getPathPrefix(handlerType); if (prefix != null) { info = RequestMappingInfo.paths(prefix).build().combine(info); } } return info; }
@Override protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { RequestMappingInfo requestMappingInfo = createRequestMappingInfo(method); if (requestMappingInfo != null) { RequestMappingInfo typeInfo = createRequestMappingInfo(handlerType); if (typeInfo != null) { requestMappingInfo = typeInfo.combine(requestMappingInfo); } } return requestMappingInfo; }
/** * Uses method and type-level @{@link RequestMapping} annotations to create * the RequestMappingInfo. * @return the created RequestMappingInfo, or {@code null} if the method * does not have a {@code @RequestMapping} annotation. * @see #getCustomMethodCondition(Method) * @see #getCustomTypeCondition(Class) */ @Override @Nullable protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { RequestMappingInfo info = createRequestMappingInfo(method); if (info != null) { RequestMappingInfo typeInfo = createRequestMappingInfo(handlerType); if (typeInfo != null) { info = typeInfo.combine(info); } String prefix = getPathPrefix(handlerType); if (prefix != null) { info = RequestMappingInfo.paths(prefix).build().combine(info); } } return info; }
private static class PathTweakingRequestMappingHandlerMapping extends RequestMappingHandlerMapping { @Override protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { RequestMappingInfo methodMapping = super.getMappingForMethod(method, handlerType); if (methodMapping == null) return null; List<String> superclassUrlPatterns = new ArrayList<String>(); boolean springPath = false; for (Class<?> clazz = handlerType; clazz != Object.class; clazz = clazz.getSuperclass()) if (clazz.isAnnotationPresent(RequestMapping.class)) if (springPath) superclassUrlPatterns.add(clazz.getAnnotation(RequestMapping.class).value()[0]);// TODO handle other elements in the array if necessary else springPath = true; if (!superclassUrlPatterns.isEmpty()) { RequestMappingInfo superclassRequestMappingInfo = new RequestMappingInfo("", new PatternsRequestCondition(String.join("", superclassUrlPatterns)), null, null, null, null, null, null);// TODO implement specific method, consumes, produces, etc depending on your merging policies return superclassRequestMappingInfo.combine(methodMapping); } else return methodMapping; } }
@Override protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { RequestMappingInfo info = super.getMappingForMethod(method, handlerType); if (info == null) return null; ApiVersion methodAnnotation = AnnotationUtils.findAnnotation(method, ApiVersion.class); if (methodAnnotation != null) { RequestCondition<?> methodCondition = getCustomMethodCondition(method); // Concatenate our ApiVersion with the usual request mapping info = createApiVersionInfo(methodAnnotation, methodCondition).combine(info); } else { ApiVersion typeAnnotation = AnnotationUtils.findAnnotation(handlerType, ApiVersion.class); if (typeAnnotation != null) { RequestCondition<?> typeCondition = getCustomTypeCondition(handlerType); // Concatenate our ApiVersion with the usual request mapping info = createApiVersionInfo(typeAnnotation, typeCondition).combine(info); } } return info; }
@Override protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { RequestMappingInfo info = super.getMappingForMethod(method, handlerType); if (info == null) { return null; } VersionMapping methodAnnotation = AnnotationUtils.findAnnotation(method, VersionMapping.class); if (methodAnnotation != null) { RequestCondition<?> methodCondition = getCustomMethodCondition(method); // Concatenate our VersionMapping with the usual request mapping info = createRequestMappingInfo(methodAnnotation, methodCondition).combine(info); } else { VersionMapping typeAnnotation = AnnotationUtils.findAnnotation(handlerType, VersionMapping.class); if (typeAnnotation != null) { RequestCondition<?> typeCondition = getCustomTypeCondition(handlerType); // Concatenate our VersionMapping with the usual request mapping info = createRequestMappingInfo(typeAnnotation, typeCondition).combine(info); } } return info; }
@Override protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { RequestMappingInfo info = null; if (requestMapping != null) { info = createRequestMappingInfo(requestMapping, getCustomMethodCondition(method), method); RequestMapping typeAnnotation = AnnotationUtils.findAnnotation(handlerType, RequestMapping.class); if (typeAnnotation != null) { RequestCondition<?> typeCondition = getCustomTypeCondition(handlerType); info = createRequestMappingInfo(typeAnnotation, typeCondition, method).combine(info); } } return info; }
protected RequestMappingInfo createPrimitiveRequestMappingInfo(Method method, Class<?> handlerType, RequestMapping requestMapping) { RequestMappingInfo info = this.createRequestMappingInfo(method); if (info != null) { String mappingStr = calcRouterStrNew(handlerType.getName()); RequestMappingInfo typeInfo = new RequestMappingInfo(new PatternsRequestCondition(new String[]{mappingStr}), null, null, null, null, null, null); if (typeInfo != null) { info = typeInfo.combine(info); } } return info; }