Search in sources :

Example 1 with RequestMappingHandlerMapping

use of org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping in project spring-framework by spring-projects.

the class WebFluxConfigurationSupport method requestMappingHandlerMapping.

@Bean
public RequestMappingHandlerMapping requestMappingHandlerMapping(@Qualifier("webFluxContentTypeResolver") RequestedContentTypeResolver contentTypeResolver) {
    RequestMappingHandlerMapping mapping = createRequestMappingHandlerMapping();
    mapping.setOrder(0);
    mapping.setContentTypeResolver(contentTypeResolver);
    PathMatchConfigurer configurer = getPathMatchConfigurer();
    configureAbstractHandlerMapping(mapping, configurer);
    Map<String, Predicate<Class<?>>> pathPrefixes = configurer.getPathPrefixes();
    if (pathPrefixes != null) {
        mapping.setPathPrefixes(pathPrefixes);
    }
    return mapping;
}
Also used : RequestMappingHandlerMapping(org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping) Predicate(java.util.function.Predicate) Bean(org.springframework.context.annotation.Bean)

Example 2 with RequestMappingHandlerMapping

use of org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping in project spring-framework by spring-projects.

the class WebFluxConfigurationSupportTests method requestMappingHandlerMapping.

@Test
public void requestMappingHandlerMapping() {
    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);
    assertThat(mapping).isNotNull();
    assertThat(mapping.getOrder()).isEqualTo(0);
    PathPatternParser patternParser = mapping.getPathPatternParser();
    assertThat(patternParser).isNotNull();
    boolean matchOptionalTrailingSlash = (boolean) ReflectionUtils.getField(field, patternParser);
    assertThat(matchOptionalTrailingSlash).isTrue();
    name = "webFluxContentTypeResolver";
    RequestedContentTypeResolver resolver = context.getBean(name, RequestedContentTypeResolver.class);
    assertThat(mapping.getContentTypeResolver()).isSameAs(resolver);
    ServerWebExchange exchange = MockServerWebExchange.from(get("/path").accept(MediaType.APPLICATION_JSON));
    assertThat(resolver.resolveMediaTypes(exchange)).isEqualTo(Collections.singletonList(MediaType.APPLICATION_JSON));
}
Also used : Field(java.lang.reflect.Field) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) ServerWebExchange(org.springframework.web.server.ServerWebExchange) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) PathPatternParser(org.springframework.web.util.pattern.PathPatternParser) RequestMappingHandlerMapping(org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping) RequestedContentTypeResolver(org.springframework.web.reactive.accept.RequestedContentTypeResolver) Test(org.junit.jupiter.api.Test)

Example 3 with RequestMappingHandlerMapping

use of org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping in project spring-framework by spring-projects.

the class DelegatingWebFluxConfigurationIntegrationTests method requestMappingHandlerMappingUsesWebFluxInfrastructureByDefault.

@Test
void requestMappingHandlerMappingUsesWebFluxInfrastructureByDefault() {
    load(context -> {
    });
    RequestMappingHandlerMapping handlerMapping = this.context.getBean(RequestMappingHandlerMapping.class);
    assertThat(handlerMapping.getContentTypeResolver()).isSameAs(this.context.getBean("webFluxContentTypeResolver"));
}
Also used : RequestMappingHandlerMapping(org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping) Test(org.junit.jupiter.api.Test)

Example 4 with RequestMappingHandlerMapping

use of org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping in project spring-framework by spring-projects.

the class WebFluxConfigurationSupport method requestMappingHandlerMapping.

@Bean
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
    RequestMappingHandlerMapping mapping = createRequestMappingHandlerMapping();
    mapping.setOrder(0);
    mapping.setContentTypeResolver(webFluxContentTypeResolver());
    mapping.setCorsConfigurations(getCorsConfigurations());
    PathMatchConfigurer configurer = getPathMatchConfigurer();
    if (configurer.isUseSuffixPatternMatch() != null) {
        mapping.setUseSuffixPatternMatch(configurer.isUseSuffixPatternMatch());
    }
    if (configurer.isUseRegisteredSuffixPatternMatch() != null) {
        mapping.setUseRegisteredSuffixPatternMatch(configurer.isUseRegisteredSuffixPatternMatch());
    }
    if (configurer.isUseTrailingSlashMatch() != null) {
        mapping.setUseTrailingSlashMatch(configurer.isUseTrailingSlashMatch());
    }
    if (configurer.getPathMatcher() != null) {
        mapping.setPathMatcher(configurer.getPathMatcher());
    }
    if (configurer.getPathHelper() != null) {
        mapping.setPathHelper(configurer.getPathHelper());
    }
    return mapping;
}
Also used : RequestMappingHandlerMapping(org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping) Bean(org.springframework.context.annotation.Bean)

Example 5 with RequestMappingHandlerMapping

use of org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping in project spring-framework by spring-projects.

the class WebFluxConfigurationSupportTests method customPathMatchConfig.

@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);
    assertThat(mapping).isNotNull();
    PathPatternParser patternParser = mapping.getPathPatternParser();
    assertThat(patternParser).isNotNull();
    boolean matchOptionalTrailingSlash = (boolean) ReflectionUtils.getField(field, patternParser);
    assertThat(matchOptionalTrailingSlash).isFalse();
    Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
    assertThat(map.size()).isEqualTo(1);
    assertThat(map.keySet().iterator().next().getPatternsCondition().getPatterns()).isEqualTo(Collections.singleton(new PathPatternParser().parse("/api/user/{id}")));
}
Also used : Field(java.lang.reflect.Field) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) RequestMappingInfo(org.springframework.web.reactive.result.method.RequestMappingInfo) PathPatternParser(org.springframework.web.util.pattern.PathPatternParser) RequestMappingHandlerMapping(org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping) HandlerMethod(org.springframework.web.method.HandlerMethod) Test(org.junit.jupiter.api.Test)

Aggregations

RequestMappingHandlerMapping (org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping)6 Test (org.junit.jupiter.api.Test)4 Field (java.lang.reflect.Field)2 ApplicationContext (org.springframework.context.ApplicationContext)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 Bean (org.springframework.context.annotation.Bean)2 RequestedContentTypeResolver (org.springframework.web.reactive.accept.RequestedContentTypeResolver)2 PathPatternParser (org.springframework.web.util.pattern.PathPatternParser)2 Predicate (java.util.function.Predicate)1 HandlerMethod (org.springframework.web.method.HandlerMethod)1 RequestMappingInfo (org.springframework.web.reactive.result.method.RequestMappingInfo)1 ServerWebExchange (org.springframework.web.server.ServerWebExchange)1 MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)1