Java Code Examples for org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping

The following examples show how to use org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping. These examples are extracted from open source projects. 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 Project: spring-analysis-note   Source File: WebFluxConfigurationSupport.java    License: MIT License 6 votes vote down vote up
@Bean
public RequestMappingHandlerMapping requestMappingHandlerMapping(
		RequestedContentTypeResolver webFluxContentTypeResolver) {
	RequestMappingHandlerMapping mapping = createRequestMappingHandlerMapping();
	mapping.setOrder(0);
	mapping.setContentTypeResolver(webFluxContentTypeResolver);
	mapping.setCorsConfigurations(getCorsConfigurations());

	PathMatchConfigurer configurer = getPathMatchConfigurer();
	Boolean useTrailingSlashMatch = configurer.isUseTrailingSlashMatch();
	if (useTrailingSlashMatch != null) {
		mapping.setUseTrailingSlashMatch(useTrailingSlashMatch);
	}
	Boolean useCaseSensitiveMatch = configurer.isUseCaseSensitiveMatch();
	if (useCaseSensitiveMatch != null) {
		mapping.setUseCaseSensitiveMatch(useCaseSensitiveMatch);
	}
	Map<String, Predicate<Class<?>>> pathPrefixes = configurer.getPathPrefixes();
	if (pathPrefixes != null) {
		mapping.setPathPrefixes(pathPrefixes);
	}

	return mapping;
}
 
Example 2
@Test
public void requestMappingHandlerMapping() throws Exception {
	ApplicationContext context = loadConfig(WebFluxConfig.class);
	final Field field = ReflectionUtils.findField(PathPatternParser.class, "matchOptionalTrailingSeparator");
	ReflectionUtils.makeAccessible(field);

	String name = "requestMappingHandlerMapping";
	RequestMappingHandlerMapping mapping = context.getBean(name, RequestMappingHandlerMapping.class);
	assertNotNull(mapping);

	assertEquals(0, mapping.getOrder());

	PathPatternParser patternParser = mapping.getPathPatternParser();
	assertNotNull(patternParser);
	boolean matchOptionalTrailingSlash = (boolean) ReflectionUtils.getField(field, patternParser);
	assertTrue(matchOptionalTrailingSlash);

	name = "webFluxContentTypeResolver";
	RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class);
	assertSame(resolver, mapping.getContentTypeResolver());

	ServerWebExchange exchange = MockServerWebExchange.from(get("/path").accept(MediaType.APPLICATION_JSON));
	assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), resolver.resolveMediaTypes(exchange));
}
 
Example 3
@Test
public void customPathMatchConfig() {
	ApplicationContext context = loadConfig(CustomPatchMatchConfig.class);
	final Field field = ReflectionUtils.findField(PathPatternParser.class, "matchOptionalTrailingSeparator");
	ReflectionUtils.makeAccessible(field);

	String name = "requestMappingHandlerMapping";
	RequestMappingHandlerMapping mapping = context.getBean(name, RequestMappingHandlerMapping.class);
	assertNotNull(mapping);

	PathPatternParser patternParser = mapping.getPathPatternParser();
	assertNotNull(patternParser);
	boolean matchOptionalTrailingSlash = (boolean) ReflectionUtils.getField(field, patternParser);
	assertFalse(matchOptionalTrailingSlash);

	Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
	assertEquals(1, map.size());
	assertEquals(Collections.singleton(new PathPatternParser().parse("/api/user/{id}")),
			map.keySet().iterator().next().getPatternsCondition().getPatterns());
}
 
Example 4
@Bean
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
	RequestMappingHandlerMapping mapping = createRequestMappingHandlerMapping();
	mapping.setOrder(0);
	mapping.setContentTypeResolver(webFluxContentTypeResolver());
	mapping.setCorsConfigurations(getCorsConfigurations());

	PathMatchConfigurer configurer = getPathMatchConfigurer();
	Boolean useTrailingSlashMatch = configurer.isUseTrailingSlashMatch();
	if (useTrailingSlashMatch != null) {
		mapping.setUseTrailingSlashMatch(useTrailingSlashMatch);
	}
	Boolean useCaseSensitiveMatch = configurer.isUseCaseSensitiveMatch();
	if (useCaseSensitiveMatch != null) {
		mapping.setUseCaseSensitiveMatch(useCaseSensitiveMatch);
	}
	Map<String, Predicate<Class<?>>> pathPrefixes = configurer.getPathPrefixes();
	if (pathPrefixes != null) {
		mapping.setPathPrefixes(pathPrefixes);
	}

	return mapping;
}
 
Example 5
@Test
public void requestMappingHandlerMapping() throws Exception {
	ApplicationContext context = loadConfig(WebFluxConfig.class);
	final Field field = ReflectionUtils.findField(PathPatternParser.class, "matchOptionalTrailingSeparator");
	ReflectionUtils.makeAccessible(field);

	String name = "requestMappingHandlerMapping";
	RequestMappingHandlerMapping mapping = context.getBean(name, RequestMappingHandlerMapping.class);
	assertNotNull(mapping);

	assertEquals(0, mapping.getOrder());

	PathPatternParser patternParser = mapping.getPathPatternParser();
	assertNotNull(patternParser);
	boolean matchOptionalTrailingSlash = (boolean) ReflectionUtils.getField(field, patternParser);
	assertTrue(matchOptionalTrailingSlash);

	name = "webFluxContentTypeResolver";
	RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class);
	assertSame(resolver, mapping.getContentTypeResolver());

	ServerWebExchange exchange = MockServerWebExchange.from(get("/path").accept(MediaType.APPLICATION_JSON));
	assertEquals(Collections.singletonList(MediaType.APPLICATION_JSON), resolver.resolveMediaTypes(exchange));
}
 
Example 6
@Test
public void customPathMatchConfig() {
	ApplicationContext context = loadConfig(CustomPatchMatchConfig.class);
	final Field field = ReflectionUtils.findField(PathPatternParser.class, "matchOptionalTrailingSeparator");
	ReflectionUtils.makeAccessible(field);

	String name = "requestMappingHandlerMapping";
	RequestMappingHandlerMapping mapping = context.getBean(name, RequestMappingHandlerMapping.class);
	assertNotNull(mapping);

	PathPatternParser patternParser = mapping.getPathPatternParser();
	assertNotNull(patternParser);
	boolean matchOptionalTrailingSlash = (boolean) ReflectionUtils.getField(field, patternParser);
	assertFalse(matchOptionalTrailingSlash);

	Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
	assertEquals(1, map.size());
	assertEquals(Collections.singleton(new PathPatternParser().parse("/api/user/{id}")),
			map.keySet().iterator().next().getPatternsCondition().getPatterns());
}
 
Example 7
Source Project: yue-library   Source File: WebFluxRegistrationsConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
	if (!apiVersionProperties.isEnabled()) {
		return WebFluxRegistrations.super.getRequestMappingHandlerMapping();
	}
	
	log.info("【初始化配置-ApiVersionRequestMappingHandlerMapping】默认配置为true,当前环境为true:Restful API接口版本控制,执行初始化 ...");
	return new ApiVersionRequestMappingHandlerMapping(apiVersionProperties);
}
 
Example 8
Source Project: pf4j-spring-tutorial   Source File: PluginConfig.java    License: MIT License 5 votes vote down vote up
private void registerMvcEndpoints(PluginManager pm) {
    pm.getExtensions(PluginInterface.class).stream()
            .flatMap(g -> g.mvcControllers().stream())
            .forEach(r -> ((ConfigurableBeanFactory) beanFactory)
                    .registerSingleton(r.getClass().getName(), r));
    applicationContext
            .getBeansOfType(RequestMappingHandlerMapping.class)
            .forEach((k, v) -> v.afterPropertiesSet());
}
 
Example 9
Source Project: spring-analysis-note   Source File: WebFluxConfigurationSupport.java    License: MIT License 4 votes vote down vote up
/**
 * Override to plug a sub-class of {@link RequestMappingHandlerMapping}.
 */
protected RequestMappingHandlerMapping createRequestMappingHandlerMapping() {
	return new RequestMappingHandlerMapping();
}
 
Example 10
Source Project: spring-analysis-note   Source File: DispatcherHandlerErrorTests.java    License: MIT License 4 votes vote down vote up
@Bean
public RequestMappingHandlerMapping handlerMapping() {
	return new RequestMappingHandlerMapping();
}
 
Example 11
/**
 * Override to plug a sub-class of {@link RequestMappingHandlerMapping}.
 */
protected RequestMappingHandlerMapping createRequestMappingHandlerMapping() {
	return new RequestMappingHandlerMapping();
}
 
Example 12
@Bean
public RequestMappingHandlerMapping handlerMapping() {
	return new RequestMappingHandlerMapping();
}