/** * Map the "jwkKeyPublish" method to our jwkPublishUrl. */ @Override protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { if (method.getName().equals("publishClientJwk") && getJwkPublishUrl() != null) { return new RequestMappingInfo( new PatternsRequestCondition(new String[] {getJwkPublishUrl()}, getUrlPathHelper(), getPathMatcher(), false, false), null, null, null, null, null, null); } else { return null; } }
/** * Checks if all conditions in this request mapping info match the provided request and returns * a potentially new request mapping info with conditions tailored to the current request. * <p>For example the returned instance may contain the subset of URL patterns that match to * the current request, sorted with best matching patterns on top. * @return a new instance in case all conditions match; or {@code null} otherwise */ @Override @Nullable public RequestMappingInfo getMatchingCondition(HttpServletRequest request) { RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(request); ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(request); HeadersRequestCondition headers = this.headersCondition.getMatchingCondition(request); ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(request); ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(request); if (methods == null || params == null || headers == null || consumes == null || produces == null) { return null; } PatternsRequestCondition patterns = this.patternsCondition.getMatchingCondition(request); if (patterns == null) { return null; } RequestConditionHolder custom = this.customConditionHolder.getMatchingCondition(request); if (custom == null) { return null; } return new RequestMappingInfo(this.name, patterns, methods, params, headers, consumes, produces, custom.getCondition()); }
private RequestMappingInfo withPrefix(RequestMappingInfo mapping) { if (!StringUtils.hasText(adminContextPath)) { return mapping; } PatternsRequestCondition patternsCondition = new PatternsRequestCondition( withNewPatterns(mapping.getPatternsCondition().getPatterns())); return new RequestMappingInfo(patternsCondition, mapping.getMethodsCondition(), mapping.getParamsCondition(), mapping.getHeadersCondition(), mapping.getConsumesCondition(), mapping.getProducesCondition(), mapping.getCustomCondition()); }
/** * Combine "this" request mapping info (i.e. the current instance) with another request mapping info instance. * <p>Example: combine type- and method-level request mappings. * @return a new request mapping info instance; never {@code null} */ @Override public RequestMappingInfo combine(RequestMappingInfo other) { String name = combineNames(other); PatternsRequestCondition patterns = this.patternsCondition.combine(other.patternsCondition); RequestMethodsRequestCondition methods = this.methodsCondition.combine(other.methodsCondition); ParamsRequestCondition params = this.paramsCondition.combine(other.paramsCondition); HeadersRequestCondition headers = this.headersCondition.combine(other.headersCondition); ConsumesRequestCondition consumes = this.consumesCondition.combine(other.consumesCondition); ProducesRequestCondition produces = this.producesCondition.combine(other.producesCondition); RequestConditionHolder custom = this.customConditionHolder.combine(other.customConditionHolder); return new RequestMappingInfo(name, patterns, methods, params, headers, consumes, produces, custom.getCondition()); }
RequestMappingInfo mapping = new RequestMappingInfo(patternsInfo, defaultMapping.getMethodsCondition(), paramsInfo, defaultMapping.getHeadersCondition(), defaultMapping.getConsumesCondition(), defaultMapping.getProducesCondition(), defaultMapping.getCustomCondition());
/** * Checks if all conditions in this request mapping info match the provided request and returns * a potentially new request mapping info with conditions tailored to the current request. * <p>For example the returned instance may contain the subset of URL patterns that match to * the current request, sorted with best matching patterns on top. * @return a new instance in case all conditions match; or {@code null} otherwise */ @Override @Nullable public RequestMappingInfo getMatchingCondition(HttpServletRequest request) { RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(request); ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(request); HeadersRequestCondition headers = this.headersCondition.getMatchingCondition(request); ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(request); ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(request); if (methods == null || params == null || headers == null || consumes == null || produces == null) { return null; } PatternsRequestCondition patterns = this.patternsCondition.getMatchingCondition(request); if (patterns == null) { return null; } RequestConditionHolder custom = this.customConditionHolder.getMatchingCondition(request); if (custom == null) { return null; } return new RequestMappingInfo(this.name, patterns, methods, params, headers, consumes, produces, custom.getCondition()); }
@Test public void getNameExplicit() { Method method = ClassUtils.getMethod(TestController.class, "handle"); HandlerMethod handlerMethod = new HandlerMethod(new TestController(), method); RequestMappingInfo rmi = new RequestMappingInfo("foo", null, null, null, null, null, null, null); HandlerMethodMappingNamingStrategy<RequestMappingInfo> strategy = new RequestMappingInfoHandlerMethodMappingNamingStrategy(); assertEquals("foo", strategy.getName(handlerMethod, rmi)); }
@Test public void getNameConvention() { Method method = ClassUtils.getMethod(TestController.class, "handle"); HandlerMethod handlerMethod = new HandlerMethod(new TestController(), method); RequestMappingInfo rmi = new RequestMappingInfo(null, null, null, null, null, null, null, null); HandlerMethodMappingNamingStrategy<RequestMappingInfo> strategy = new RequestMappingInfoHandlerMethodMappingNamingStrategy(); assertEquals("TC#handle", strategy.getName(handlerMethod, rmi)); }
/** * Combine "this" request mapping info (i.e. the current instance) with another request mapping info instance. * <p>Example: combine type- and method-level request mappings. * @return a new request mapping info instance; never {@code null} */ @Override public RequestMappingInfo combine(RequestMappingInfo other) { String name = combineNames(other); PatternsRequestCondition patterns = this.patternsCondition.combine(other.patternsCondition); RequestMethodsRequestCondition methods = this.methodsCondition.combine(other.methodsCondition); ParamsRequestCondition params = this.paramsCondition.combine(other.paramsCondition); HeadersRequestCondition headers = this.headersCondition.combine(other.headersCondition); ConsumesRequestCondition consumes = this.consumesCondition.combine(other.consumesCondition); ProducesRequestCondition produces = this.producesCondition.combine(other.producesCondition); RequestConditionHolder custom = this.customConditionHolder.combine(other.customConditionHolder); return new RequestMappingInfo(name, patterns, methods, params, headers, consumes, produces, custom.getCondition()); }
@Override public RequestMappingInfo build() { ContentNegotiationManager manager = this.options.getContentNegotiationManager(); PatternsRequestCondition patternsCondition = new PatternsRequestCondition( this.paths, this.options.getUrlPathHelper(), this.options.getPathMatcher(), this.options.useSuffixPatternMatch(), this.options.useTrailingSlashMatch(), this.options.getFileExtensions()); return new RequestMappingInfo(this.mappingName, patternsCondition, new RequestMethodsRequestCondition(this.methods), new ParamsRequestCondition(this.params), new HeadersRequestCondition(this.headers), new ConsumesRequestCondition(this.consumes, this.headers), new ProducesRequestCondition(this.produces, this.headers, manager), this.customCondition); } }
@Override public RequestMappingInfo build() { ContentNegotiationManager manager = this.options.getContentNegotiationManager(); PatternsRequestCondition patternsCondition = new PatternsRequestCondition( this.paths, this.options.getUrlPathHelper(), this.options.getPathMatcher(), this.options.useSuffixPatternMatch(), this.options.useTrailingSlashMatch(), this.options.getFileExtensions()); return new RequestMappingInfo(this.mappingName, patternsCondition, new RequestMethodsRequestCondition(this.methods), new ParamsRequestCondition(this.params), new HeadersRequestCondition(this.headers), new ConsumesRequestCondition(this.consumes, this.headers), new ProducesRequestCondition(this.produces, this.headers, manager), this.customCondition); } }
@Override protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { RequestMapping annot = AnnotationUtils.findAnnotation(method, RequestMapping.class); if (annot != null) { return new RequestMappingInfo( new PatternsRequestCondition(annot.value(), getUrlPathHelper(), getPathMatcher(), true, true), new RequestMethodsRequestCondition(annot.method()), new ParamsRequestCondition(annot.params()), new HeadersRequestCondition(annot.headers()), new ConsumesRequestCondition(annot.consumes(), annot.headers()), new ProducesRequestCondition(annot.produces(), annot.headers()), null); } else { return null; } } }
@Override protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { RequestMapping annotation = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class); if (annotation != null) { return new RequestMappingInfo( new PatternsRequestCondition(annotation.value(), getUrlPathHelper(), getPathMatcher(), true, true), new RequestMethodsRequestCondition(annotation.method()), new ParamsRequestCondition(annotation.params()), new HeadersRequestCondition(annotation.headers()), new ConsumesRequestCondition(annotation.consumes(), annotation.headers()), new ProducesRequestCondition(annotation.produces(), annotation.headers()), null); } else { return null; } } }
private void registerLinksMapping() { PatternsRequestCondition patterns = patternsRequestConditionForPattern(""); RequestMethodsRequestCondition methods = new RequestMethodsRequestCondition( RequestMethod.GET); ProducesRequestCondition produces = new ProducesRequestCondition( this.endpointMediaTypes.getProduced().toArray(StringUtils .toStringArray(this.endpointMediaTypes.getProduced()))); RequestMappingInfo mapping = new RequestMappingInfo(patterns, methods, null, null, null, produces, null); LinksHandler linksHandler = getLinksHandler(); registerMapping(mapping, linksHandler, ReflectionUtils.findMethod(linksHandler.getClass(), "links", HttpServletRequest.class, HttpServletResponse.class)); }
private RequestMappingInfo withNewPatterns(RequestMappingInfo mapping, String[] patterns) { PatternsRequestCondition patternsCondition = new PatternsRequestCondition( patterns, null, null, useSuffixPatternMatch(), useTrailingSlashMatch(), null); return new RequestMappingInfo(patternsCondition, mapping.getMethodsCondition(), mapping.getParamsCondition(), mapping.getHeadersCondition(), mapping.getConsumesCondition(), mapping.getProducesCondition(), mapping.getCustomCondition()); }
@Override protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { RequestMappingInfo info = super.getMappingForMethod(method, handlerType); if (info == null) { return null; } PatternsRequestCondition patternsCondition = customize(info.getPatternsCondition(), prefix); ProducesRequestCondition producesCondition = customize(info.getProducesCondition()); return new RequestMappingInfo(patternsCondition, info.getMethodsCondition(), info.getParamsCondition(), info.getHeadersCondition(), info.getConsumesCondition(), producesCondition, info.getCustomCondition()); }
private RequestMappingInfo createRequestMappingInfo(WebOperation operation) { WebOperationRequestPredicate predicate = operation.getRequestPredicate(); PatternsRequestCondition patterns = patternsRequestConditionForPattern( predicate.getPath()); RequestMethodsRequestCondition methods = new RequestMethodsRequestCondition( RequestMethod.valueOf(predicate.getHttpMethod().name())); ConsumesRequestCondition consumes = new ConsumesRequestCondition( StringUtils.toStringArray(predicate.getConsumes())); ProducesRequestCondition produces = new ProducesRequestCondition( StringUtils.toStringArray(predicate.getProduces())); return new RequestMappingInfo(null, patterns, methods, null, null, consumes, produces, null); }
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; }
@Override protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) { RequestMappingInfo info = super.getMappingForMethod(method, handlerType); if (info == null) { return null; } PatternsRequestCondition patternsCondition = customize(info.getPatternsCondition(), prefix); ProducesRequestCondition producesCondition = customize(info.getProducesCondition()); return new RequestMappingInfo(patternsCondition, info.getMethodsCondition(), info.getParamsCondition(), info.getHeadersCondition(), info.getConsumesCondition(), producesCondition, info.getCustomCondition()); }
private RequestMappingInfo createApiVersionInfo(ApiVersion annotation, RequestCondition<?> customCondition) { String[] values = annotation.value(); String[] patterns = new String[values.length]; for (int i = 0; i < values.length; i++) { // Build the URL prefix patterns[i] = prefix + values[i]; } return new RequestMappingInfo( new PatternsRequestCondition(patterns, getUrlPathHelper(), getPathMatcher(), useSuffixPatternMatch(), useTrailingSlashMatch(), getFileExtensions()), new RequestMethodsRequestCondition(), new ParamsRequestCondition(), new HeadersRequestCondition(), new ConsumesRequestCondition(), new ProducesRequestCondition(), customCondition); }