org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping Java Examples

The following examples show how to use org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MvcUriComponentsBuilder.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * An alternative to {@link #fromMappingName(String)} that accepts a
 * {@code UriComponentsBuilder} representing the base URL. This is useful
 * when using MvcUriComponentsBuilder outside the context of processing a
 * request or to apply a custom baseUrl not matching the current request.
 * <p><strong>Note:</strong> This method extracts values from "Forwarded"
 * and "X-Forwarded-*" headers if found. See class-level docs.
 * @param builder the builder for the base URL; the builder will be cloned
 * and therefore not modified and may be re-used for further calls.
 * @param name the mapping name
 * @return a builder to prepare the URI String
 * @throws IllegalArgumentException if the mapping name is not found or
 * if there is no unique match
 * @since 4.2
 */
public static MethodArgumentBuilder fromMappingName(@Nullable UriComponentsBuilder builder, String name) {
	WebApplicationContext wac = getWebApplicationContext();
	Assert.notNull(wac, "No WebApplicationContext. ");
	Map<String, RequestMappingInfoHandlerMapping> map = wac.getBeansOfType(RequestMappingInfoHandlerMapping.class);
	List<HandlerMethod> handlerMethods = null;
	for (RequestMappingInfoHandlerMapping mapping : map.values()) {
		handlerMethods = mapping.getHandlerMethodsForMappingName(name);
		if (handlerMethods != null) {
			break;
		}
	}
	if (handlerMethods == null) {
		throw new IllegalArgumentException("Mapping not found: " + name);
	}
	else if (handlerMethods.size() != 1) {
		throw new IllegalArgumentException("No unique match for mapping " + name + ": " + handlerMethods);
	}
	else {
		HandlerMethod handlerMethod = handlerMethods.get(0);
		Class<?> controllerType = handlerMethod.getBeanType();
		Method method = handlerMethod.getMethod();
		return new MethodArgumentBuilder(builder, controllerType, method);
	}
}
 
Example #2
Source File: OpenApiResource.java    From springdoc-openapi with Apache License 2.0 6 votes vote down vote up
/**
 * Instantiates a new Open api resource.
 *
 * @param openAPIBuilderObjectFactory the open api builder object factory
 * @param requestBuilder the request builder
 * @param responseBuilder the response builder
 * @param operationParser the operation parser
 * @param requestMappingHandlerMapping the request mapping handler mapping
 * @param actuatorProvider the actuator provider
 * @param operationCustomizers the operation customizers
 * @param openApiCustomisers the open api customisers
 * @param springDocConfigProperties the spring doc config properties
 * @param springSecurityOAuth2Provider the spring security o auth 2 provider
 * @param routerFunctionProvider the router function provider
 * @param repositoryRestResourceProvider the repository rest resource provider
 */
@Autowired
public OpenApiResource(ObjectFactory<OpenAPIBuilder> openAPIBuilderObjectFactory, AbstractRequestBuilder requestBuilder,
		GenericResponseBuilder responseBuilder, OperationBuilder operationParser,
		RequestMappingInfoHandlerMapping requestMappingHandlerMapping,
		Optional<ActuatorProvider> actuatorProvider,
		Optional<List<OperationCustomizer>> operationCustomizers,
		Optional<List<OpenApiCustomiser>> openApiCustomisers,
		SpringDocConfigProperties springDocConfigProperties,
		Optional<SecurityOAuth2Provider> springSecurityOAuth2Provider,
		Optional<RouterFunctionProvider> routerFunctionProvider,
		Optional<RepositoryRestResourceProvider> repositoryRestResourceProvider) {
	super(DEFAULT_GROUP_NAME, openAPIBuilderObjectFactory, requestBuilder, responseBuilder, operationParser, operationCustomizers, openApiCustomisers, springDocConfigProperties,actuatorProvider);
	this.requestMappingHandlerMapping = requestMappingHandlerMapping;
	this.springSecurityOAuth2Provider = springSecurityOAuth2Provider;
	this.routerFunctionProvider = routerFunctionProvider;
	this.repositoryRestResourceProvider = repositoryRestResourceProvider;
}
 
Example #3
Source File: MultipleOpenApiResource.java    From springdoc-openapi with Apache License 2.0 6 votes vote down vote up
/**
 * Instantiates a new Multiple open api resource.
 *
 * @param groupedOpenApis the grouped open apis
 * @param defaultOpenAPIBuilder the default open api builder
 * @param requestBuilder the request builder
 * @param responseBuilder the response builder
 * @param operationParser the operation parser
 * @param requestMappingHandlerMapping the request mapping handler mapping
 * @param actuatorProvider the actuator provider
 * @param springDocConfigProperties the spring doc config properties
 * @param springSecurityOAuth2Provider the spring security o auth 2 provider
 * @param routerFunctionProvider the router function provider
 * @param repositoryRestResourceProvider the repository rest resource provider
 */
public MultipleOpenApiResource(List<GroupedOpenApi> groupedOpenApis,
		ObjectFactory<OpenAPIBuilder> defaultOpenAPIBuilder, AbstractRequestBuilder requestBuilder,
		GenericResponseBuilder responseBuilder, OperationBuilder operationParser,
		RequestMappingInfoHandlerMapping requestMappingHandlerMapping, Optional<ActuatorProvider> actuatorProvider,
		SpringDocConfigProperties springDocConfigProperties, Optional<SecurityOAuth2Provider> springSecurityOAuth2Provider,
		Optional<RouterFunctionProvider> routerFunctionProvider,
		Optional<RepositoryRestResourceProvider> repositoryRestResourceProvider) {

	this.groupedOpenApis = groupedOpenApis;
	this.defaultOpenAPIBuilder = defaultOpenAPIBuilder;
	this.requestBuilder = requestBuilder;
	this.responseBuilder = responseBuilder;
	this.operationParser = operationParser;
	this.requestMappingHandlerMapping = requestMappingHandlerMapping;
	this.actuatorProvider = actuatorProvider;
	this.springDocConfigProperties = springDocConfigProperties;
	this.springSecurityOAuth2Provider = springSecurityOAuth2Provider;
	this.routerFunctionProvider = routerFunctionProvider;
	this.repositoryRestResourceProvider=repositoryRestResourceProvider;
}
 
Example #4
Source File: MultipleOpenApiSupportConfiguration.java    From springdoc-openapi with Apache License 2.0 6 votes vote down vote up
/**
 * Multiple open api resource multiple open api resource.
 *
 * @param groupedOpenApis the grouped open apis 
 * @param defaultOpenAPIBuilder the default open api builder 
 * @param requestBuilder the request builder 
 * @param responseBuilder the response builder 
 * @param operationParser the operation parser 
 * @param requestMappingHandlerMapping the request mapping handler mapping 
 * @param actuatorProvider the actuator provider 
 * @param springDocConfigProperties the spring doc config properties 
 * @param springSecurityOAuth2Provider the spring security o auth 2 provider 
 * @param routerFunctionProvider the router function provider 
 * @param repositoryRestResourceProvider the repository rest resource provider 
 * @return the multiple open api resource
 */
@Bean
@ConditionalOnMissingBean
@Lazy(false)
MultipleOpenApiResource multipleOpenApiResource(List<GroupedOpenApi> groupedOpenApis,
		ObjectFactory<OpenAPIBuilder> defaultOpenAPIBuilder, AbstractRequestBuilder requestBuilder,
		GenericResponseBuilder responseBuilder, OperationBuilder operationParser,
		RequestMappingInfoHandlerMapping requestMappingHandlerMapping,
		Optional<ActuatorProvider> actuatorProvider,
		SpringDocConfigProperties springDocConfigProperties,
		Optional<SecurityOAuth2Provider> springSecurityOAuth2Provider,
		Optional<RouterFunctionProvider> routerFunctionProvider,
		Optional<RepositoryRestResourceProvider> repositoryRestResourceProvider) {
	return new MultipleOpenApiResource(groupedOpenApis,
			defaultOpenAPIBuilder, requestBuilder,
			responseBuilder, operationParser,
			requestMappingHandlerMapping, actuatorProvider,
			springDocConfigProperties,
			springSecurityOAuth2Provider,
			routerFunctionProvider,repositoryRestResourceProvider);
}
 
Example #5
Source File: SpringDocWebMvcConfiguration.java    From springdoc-openapi with Apache License 2.0 6 votes vote down vote up
/**
 * Open api resource open api resource.
 *
 * @param openAPIBuilderObjectFactory the open api builder object factory
 * @param requestBuilder the request builder
 * @param responseBuilder the response builder
 * @param operationParser the operation parser
 * @param requestMappingHandlerMapping the request mapping handler mapping
 * @param actuatorProvider the actuator provider
 * @param springDocConfigProperties the spring doc config properties
 * @param operationCustomizers the operation customizers
 * @param openApiCustomisers the open api customisers
 * @param springSecurityOAuth2Provider the spring security o auth 2 provider
 * @param routerFunctionProvider the router function provider
 * @param repositoryRestResourceProvider the repository rest resource provider
 * @return the open api resource
 */
@Bean
@ConditionalOnMissingBean
@Lazy(false)
OpenApiResource openApiResource(ObjectFactory<OpenAPIBuilder> openAPIBuilderObjectFactory, AbstractRequestBuilder requestBuilder,
		GenericResponseBuilder responseBuilder, OperationBuilder operationParser,
		RequestMappingInfoHandlerMapping requestMappingHandlerMapping,
		Optional<ActuatorProvider> actuatorProvider,
		SpringDocConfigProperties springDocConfigProperties,
		Optional<List<OperationCustomizer>> operationCustomizers,
		Optional<List<OpenApiCustomiser>> openApiCustomisers,
		Optional<SecurityOAuth2Provider> springSecurityOAuth2Provider,
		Optional<RouterFunctionProvider> routerFunctionProvider,
		Optional<RepositoryRestResourceProvider> repositoryRestResourceProvider) {
	return new OpenApiResource(openAPIBuilderObjectFactory, requestBuilder,
			responseBuilder, operationParser,
			requestMappingHandlerMapping, actuatorProvider, operationCustomizers,
			openApiCustomisers, springDocConfigProperties, springSecurityOAuth2Provider,
			routerFunctionProvider, repositoryRestResourceProvider);
}
 
Example #6
Source File: MvcUriComponentsBuilder.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * An alternative to {@link #fromMappingName(String)} that accepts a
 * {@code UriComponentsBuilder} representing the base URL. This is useful
 * when using MvcUriComponentsBuilder outside the context of processing a
 * request or to apply a custom baseUrl not matching the current request.
 * <p><strong>Note:</strong> This method extracts values from "Forwarded"
 * and "X-Forwarded-*" headers if found. See class-level docs.
 * @param builder the builder for the base URL; the builder will be cloned
 * and therefore not modified and may be re-used for further calls.
 * @param name the mapping name
 * @return a builder to prepare the URI String
 * @throws IllegalArgumentException if the mapping name is not found or
 * if there is no unique match
 * @since 4.2
 */
public static MethodArgumentBuilder fromMappingName(@Nullable UriComponentsBuilder builder, String name) {
	WebApplicationContext wac = getWebApplicationContext();
	Assert.notNull(wac, "No WebApplicationContext. ");
	Map<String, RequestMappingInfoHandlerMapping> map = wac.getBeansOfType(RequestMappingInfoHandlerMapping.class);
	List<HandlerMethod> handlerMethods = null;
	for (RequestMappingInfoHandlerMapping mapping : map.values()) {
		handlerMethods = mapping.getHandlerMethodsForMappingName(name);
		if (handlerMethods != null) {
			break;
		}
	}
	if (handlerMethods == null) {
		throw new IllegalArgumentException("Mapping not found: " + name);
	}
	else if (handlerMethods.size() != 1) {
		throw new IllegalArgumentException("No unique match for mapping " + name + ": " + handlerMethods);
	}
	else {
		HandlerMethod handlerMethod = handlerMethods.get(0);
		Class<?> controllerType = handlerMethod.getBeanType();
		Method method = handlerMethod.getMethod();
		return new MethodArgumentBuilder(builder, controllerType, method);
	}
}
 
Example #7
Source File: MvcUriComponentsBuilder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * An alternative to {@link #fromMappingName(String)} that accepts a
 * {@code UriComponentsBuilder} representing the base URL. This is useful
 * when using MvcUriComponentsBuilder outside the context of processing a
 * request or to apply a custom baseUrl not matching the current request.
 * <p><strong>Note:</strong> This method extracts values from "Forwarded"
 * and "X-Forwarded-*" headers if found. See class-level docs.
 * @param builder the builder for the base URL; the builder will be cloned
 * and therefore not modified and may be re-used for further calls.
 * @param name the mapping name
 * @return a builder to prepare the URI String
 * @throws IllegalArgumentException if the mapping name is not found or
 * if there is no unique match
 * @since 4.2
 */
public static MethodArgumentBuilder fromMappingName(UriComponentsBuilder builder, String name) {
	RequestMappingInfoHandlerMapping handlerMapping = getRequestMappingInfoHandlerMapping();
	List<HandlerMethod> handlerMethods = handlerMapping.getHandlerMethodsForMappingName(name);
	if (handlerMethods == null) {
		throw new IllegalArgumentException("Mapping mappingName not found: " + name);
	}
	if (handlerMethods.size() != 1) {
		throw new IllegalArgumentException("No unique match for mapping mappingName " +
				name + ": " + handlerMethods);
	}
	HandlerMethod handlerMethod = handlerMethods.get(0);
	Class<?> controllerType = handlerMethod.getBeanType();
	Method method = handlerMethod.getMethod();
	return new MethodArgumentBuilder(builder, controllerType, method);
}
 
Example #8
Source File: MvcUriComponentsBuilder.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * An alternative to {@link #fromMappingName(String)} that accepts a
 * {@code UriComponentsBuilder} representing the base URL. This is useful
 * when using MvcUriComponentsBuilder outside the context of processing a
 * request or to apply a custom baseUrl not matching the current request.
 * @param builder the builder for the base URL; the builder will be cloned
 * and therefore not modified and may be re-used for further calls.
 * @param name the mapping name
 * @return a builder to to prepare the URI String
 * @throws IllegalArgumentException if the mapping name is not found or
 * if there is no unique match
 * @since 4.2
 */
public static MethodArgumentBuilder fromMappingName(UriComponentsBuilder builder, String name) {
	RequestMappingInfoHandlerMapping handlerMapping = getRequestMappingInfoHandlerMapping();
	List<HandlerMethod> handlerMethods = handlerMapping.getHandlerMethodsForMappingName(name);
	if (handlerMethods == null) {
		throw new IllegalArgumentException("Mapping mappingName not found: " + name);
	}
	if (handlerMethods.size() != 1) {
		throw new IllegalArgumentException("No unique match for mapping mappingName " +
				name + ": " + handlerMethods);
	}
	HandlerMethod handlerMethod = handlerMethods.get(0);
	Class<?> controllerType = handlerMethod.getBeanType();
	Method method = handlerMethod.getMethod();
	return new MethodArgumentBuilder(builder, controllerType, method);
}
 
Example #9
Source File: OpenApiResource.java    From springdoc-openapi with Apache License 2.0 4 votes vote down vote up
/**
 * Instantiates a new Open api resource.
 *
 * @param groupName the group name
 * @param openAPIBuilderObjectFactory the open api builder object factory
 * @param requestBuilder the request builder
 * @param responseBuilder the response builder
 * @param operationParser the operation parser
 * @param requestMappingHandlerMapping the request mapping handler mapping
 * @param actuatorProvider the actuator provider
 * @param operationCustomizers the operation customizers
 * @param openApiCustomisers the open api customisers
 * @param springDocConfigProperties the spring doc config properties
 * @param springSecurityOAuth2Provider the spring security o auth 2 provider
 * @param routerFunctionProvider the router function provider
 * @param repositoryRestResourceProvider the repository rest resource provider
 */
public OpenApiResource(String groupName, ObjectFactory<OpenAPIBuilder> openAPIBuilderObjectFactory, AbstractRequestBuilder requestBuilder,
		GenericResponseBuilder responseBuilder, OperationBuilder operationParser,
		RequestMappingInfoHandlerMapping requestMappingHandlerMapping,
		Optional<ActuatorProvider> actuatorProvider,
		Optional<List<OperationCustomizer>> operationCustomizers,
		Optional<List<OpenApiCustomiser>> openApiCustomisers,
		SpringDocConfigProperties springDocConfigProperties,
		Optional<SecurityOAuth2Provider> springSecurityOAuth2Provider,
		Optional<RouterFunctionProvider> routerFunctionProvider,
		Optional<RepositoryRestResourceProvider> repositoryRestResourceProvider) {
	super(groupName, openAPIBuilderObjectFactory, requestBuilder, responseBuilder, operationParser, operationCustomizers, openApiCustomisers, springDocConfigProperties,actuatorProvider);
	this.requestMappingHandlerMapping = requestMappingHandlerMapping;
	this.springSecurityOAuth2Provider = springSecurityOAuth2Provider;
	this.routerFunctionProvider = routerFunctionProvider;
	this.repositoryRestResourceProvider = repositoryRestResourceProvider;
}