use of org.springframework.web.servlet.mvc.method.RequestMappingInfo.BuilderConfiguration in project snow-owl by b2ihealthcare.
the class SnowOwlApiConfig method createRequestMappingHandlerMapping.
@Override
protected RequestMappingHandlerMapping createRequestMappingHandlerMapping() {
return new RequestMappingHandlerMapping() {
private StringValueResolver embeddedValueResolver;
@Override
public void setEmbeddedValueResolver(StringValueResolver resolver) {
super.setEmbeddedValueResolver(resolver);
this.embeddedValueResolver = resolver;
}
@Override
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 = getPrefix(handlerType);
if (prefix != null && !prefix.equals("/")) {
BuilderConfiguration config = new BuilderConfiguration();
config.setPathMatcher(getPathMatcher());
config.setSuffixPatternMatch(false);
info = RequestMappingInfo.paths(prefix).options(config).build().combine(info);
}
}
return info;
}
@Nullable
private RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) {
RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(element, RequestMapping.class);
RequestCondition<?> condition = (element instanceof Class ? getCustomTypeCondition((Class<?>) element) : getCustomMethodCondition((Method) element));
return (requestMapping != null ? createRequestMappingInfo(requestMapping, condition) : null);
}
private String getPrefix(Class<?> handlerType) {
for (Map.Entry<String, Predicate<Class<?>>> entry : getPathPrefixes().entrySet()) {
if (entry.getValue().test(handlerType)) {
String prefix = entry.getKey();
if (this.embeddedValueResolver != null) {
prefix = this.embeddedValueResolver.resolveStringValue(prefix);
}
return prefix;
}
}
return null;
}
};
}
Aggregations