org.springframework.web.reactive.HandlerMapping Java Examples

The following examples show how to use org.springframework.web.reactive.HandlerMapping. 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: SimpleUrlHandlerMappingTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("resource")
public void handlerMappingJavaConfig() throws Exception {
	AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
	wac.register(WebConfig.class);
	wac.refresh();

	HandlerMapping handlerMapping = (HandlerMapping) wac.getBean("handlerMapping");
	Object mainController = wac.getBean("mainController");
	Object otherController = wac.getBean("otherController");

	testUrl("/welcome.html", mainController, handlerMapping, "");
	testUrl("/welcome.x", otherController, handlerMapping, "welcome.x");
	testUrl("/welcome/", otherController, handlerMapping, "welcome");
	testUrl("/show.html", mainController, handlerMapping, "");
	testUrl("/bookseats.html", mainController, handlerMapping, "");
}
 
Example #2
Source File: WebSocketConfig.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 6 votes vote down vote up
@Bean
HandlerMapping webSocketMapping(CommentService commentService) {
	Map<String, WebSocketHandler> urlMap = new HashMap<>();
	urlMap.put("/topic/comments.new", commentService);

	Map<String, CorsConfiguration> corsConfigurationMap =
		new HashMap<>();
	CorsConfiguration corsConfiguration = new CorsConfiguration();
	corsConfiguration.addAllowedOrigin("http://localhost:8080");
	corsConfigurationMap.put(
		"/topic/comments.new", corsConfiguration);

	SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
	mapping.setOrder(10);
	mapping.setUrlMap(urlMap);
	mapping.setCorsConfigurations(corsConfigurationMap);

	return mapping;
}
 
Example #3
Source File: DispatcherHandlerHandleMethodInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
                          Object ret) throws Throwable {
    ServerWebExchange exchange = (ServerWebExchange) allArguments[0];
    AbstractSpan span = (AbstractSpan) objInst.getSkyWalkingDynamicField();

    return ((Mono) ret).doFinally(s -> {
        try {
            Object pathPattern = exchange.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
            if (pathPattern != null) {
                span.setOperationName(((PathPattern) pathPattern).getPatternString());
            }
            HttpStatus httpStatus = exchange.getResponse().getStatusCode();
            // fix webflux-2.0.0-2.1.0 version have bug. httpStatus is null. not support
            if (httpStatus != null) {
                Tags.STATUS_CODE.set(span, Integer.toString(httpStatus.value()));
                if (httpStatus.isError()) {
                    span.errorOccurred();
                }
            }
        } finally {
            span.asyncFinish();
        }
    });

}
 
Example #4
Source File: WebSocketConfig.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 6 votes vote down vote up
@Bean
HandlerMapping webSocketMapping(CommentService commentService,
								InboundChatService inboundChatService,
								OutboundChatService outboundChatService) {
	SimpleUrlHandlerMapping mapping =
		configureUrlMappings(commentService, inboundChatService, outboundChatService);

	Map<String, CorsConfiguration> corsConfigurationMap = new HashMap<>();
	CorsConfiguration corsConfiguration = new CorsConfiguration();
	corsConfiguration.addAllowedOrigin(chatConfigProperties.getOrigin());

	mapping.getUrlMap().keySet().forEach(route ->
		corsConfigurationMap.put(route, corsConfiguration)
	);

	mapping.setCorsConfigurations(corsConfigurationMap);

	return mapping;
}
 
Example #5
Source File: TraceWebFilter.java    From spring-cloud-sleuth with Apache License 2.0 6 votes vote down vote up
private void terminateSpan(@Nullable Throwable t) {
	Object attribute = this.exchange
			.getAttribute(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE);
	addClassMethodTag(attribute, this.span);
	addClassNameTag(attribute, this.span);
	Object pattern = this.exchange
			.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
	String httpRoute = pattern != null ? pattern.toString() : "";
	addResponseTagsForSpanWithoutParent(this.exchange,
			this.exchange.getResponse(), this.span);
	WrappedResponse response = new WrappedResponse(
			this.exchange.getResponse(),
			this.exchange.getRequest().getMethodValue(), httpRoute);
	this.handler.handleSend(response, t, this.span);
	if (log.isDebugEnabled()) {
		log.debug("Handled send of " + this.span);
	}
}
 
Example #6
Source File: ResourceWebHandler.java    From spring-analysis-note with MIT License 6 votes vote down vote up
protected Mono<Resource> getResource(ServerWebExchange exchange) {
	String name = HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE;
	PathContainer pathWithinHandler = exchange.getRequiredAttribute(name);

	String path = processPath(pathWithinHandler.value());
	if (!StringUtils.hasText(path) || isInvalidPath(path)) {
		return Mono.empty();
	}
	if (isInvalidEncodedPath(path)) {
		return Mono.empty();
	}

	Assert.state(this.resolverChain != null, "ResourceResolverChain not initialized");
	Assert.state(this.transformerChain != null, "ResourceTransformerChain not initialized");

	return this.resolverChain.resolveResource(exchange, path, getLocations())
			.flatMap(resource -> this.transformerChain.transform(exchange, resource));
}
 
Example #7
Source File: SimpleUrlHandlerMappingTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("resource")
public void handlerMappingJavaConfig() throws Exception {
	AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
	wac.register(WebConfig.class);
	wac.refresh();

	HandlerMapping handlerMapping = (HandlerMapping) wac.getBean("handlerMapping");
	Object mainController = wac.getBean("mainController");
	Object otherController = wac.getBean("otherController");

	testUrl("/welcome.html", mainController, handlerMapping, "");
	testUrl("/welcome.x", otherController, handlerMapping, "welcome.x");
	testUrl("/welcome/", otherController, handlerMapping, "welcome");
	testUrl("/show.html", mainController, handlerMapping, "");
	testUrl("/bookseats.html", mainController, handlerMapping, "");
}
 
Example #8
Source File: SimpleUrlHandlerMappingTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private void testUrl(String url, Object bean, HandlerMapping handlerMapping, String pathWithinMapping) {
	MockServerHttpRequest request = MockServerHttpRequest.method(HttpMethod.GET, URI.create(url)).build();
	ServerWebExchange exchange = MockServerWebExchange.from(request);
	Object actual = handlerMapping.getHandler(exchange).block();
	if (bean != null) {
		assertNotNull(actual);
		assertSame(bean, actual);
		//noinspection OptionalGetWithoutIsPresent
		PathContainer path = exchange.getAttribute(PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
		assertNotNull(path);
		assertEquals(pathWithinMapping, path.value());
	}
	else {
		assertNull(actual);
	}
}
 
Example #9
Source File: WebSocketIT.java    From vertx-spring-boot with Apache License 2.0 6 votes vote down vote up
@Bean
public HandlerMapping handlerMapping() {
    Map<String, WebSocketHandler> map = new HashMap<>();
    map.put("/echo", this::echoHandler);
    map.put("/sink", this::sinkHandler);
    map.put("/double-producer", this::doubleProducerHandler);
    map.put("/close", this::closeHandler);

    SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
    mapping.setUrlMap(map);
    mapping.setOrder(-1);

    CorsConfiguration cors = new CorsConfiguration();
    cors.addAllowedOrigin("http://snowdrop.dev");
    mapping.setCorsConfigurations(Collections.singletonMap("/sink", cors));

    return mapping;
}
 
Example #10
Source File: RequestMappingInfoHandlerMappingTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test  // SPR-9098
public void handleMatchUriTemplateVariablesDecode() {
	RequestMappingInfo key = paths("/{group}/{identifier}").build();
	URI url = URI.create("/group/a%2Fb");
	ServerWebExchange exchange = MockServerWebExchange.from(method(HttpMethod.GET, url));

	this.handlerMapping.handleMatch(key, handlerMethod, exchange);

	String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
	@SuppressWarnings("unchecked")
	Map<String, String> uriVariables = (Map<String, String>) exchange.getAttributes().get(name);

	assertNotNull(uriVariables);
	assertEquals("group", uriVariables.get("group"));
	assertEquals("a/b", uriVariables.get("identifier"));
}
 
Example #11
Source File: RequestMappingInfoHandlerMappingTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test  // SPR-9098
public void handleMatchUriTemplateVariablesDecode() {
	RequestMappingInfo key = paths("/{group}/{identifier}").build();
	URI url = URI.create("/group/a%2Fb");
	ServerWebExchange exchange = MockServerWebExchange.from(method(HttpMethod.GET, url));

	this.handlerMapping.handleMatch(key, handlerMethod, exchange);

	String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
	@SuppressWarnings("unchecked")
	Map<String, String> uriVariables = (Map<String, String>) exchange.getAttributes().get(name);

	assertNotNull(uriVariables);
	assertEquals("group", uriVariables.get("group"));
	assertEquals("a/b", uriVariables.get("identifier"));
}
 
Example #12
Source File: WebSocketMessagingHandlerConfiguration.java    From jetlinks-community with Apache License 2.0 6 votes vote down vote up
@Bean
public HandlerMapping webSocketMessagingHandlerMapping(MessagingManager messagingManager,
                                       UserTokenManager userTokenManager,
                                       ReactiveAuthenticationManager authenticationManager) {


    WebSocketMessagingHandler messagingHandler=new WebSocketMessagingHandler(
        messagingManager,
        userTokenManager,
        authenticationManager
    );
    final Map<String, WebSocketHandler> map = new HashMap<>(1);
    map.put("/messaging/**", messagingHandler);

    final SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
    mapping.setOrder(Ordered.HIGHEST_PRECEDENCE);
    mapping.setUrlMap(map);
    return mapping;
}
 
Example #13
Source File: ResourceWebHandler.java    From java-technology-stack with MIT License 6 votes vote down vote up
protected Mono<Resource> getResource(ServerWebExchange exchange) {
	String name = HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE;
	PathContainer pathWithinHandler = exchange.getRequiredAttribute(name);

	String path = processPath(pathWithinHandler.value());
	if (!StringUtils.hasText(path) || isInvalidPath(path)) {
		return Mono.empty();
	}
	if (isInvalidEncodedPath(path)) {
		return Mono.empty();
	}

	Assert.state(this.resolverChain != null, "ResourceResolverChain not initialized");
	Assert.state(this.transformerChain != null, "ResourceTransformerChain not initialized");

	return this.resolverChain.resolveResource(exchange, path, getLocations())
			.flatMap(resource -> this.transformerChain.transform(exchange, resource));
}
 
Example #14
Source File: SimpleUrlHandlerMappingTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
private void testUrl(String url, Object bean, HandlerMapping handlerMapping, String pathWithinMapping) {
	MockServerHttpRequest request = MockServerHttpRequest.method(HttpMethod.GET, URI.create(url)).build();
	ServerWebExchange exchange = MockServerWebExchange.from(request);
	Object actual = handlerMapping.getHandler(exchange).block();
	if (bean != null) {
		assertNotNull(actual);
		assertSame(bean, actual);
		//noinspection OptionalGetWithoutIsPresent
		PathContainer path = exchange.getAttribute(PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
		assertNotNull(path);
		assertEquals(pathWithinMapping, path.value());
	}
	else {
		assertNull(actual);
	}
}
 
Example #15
Source File: ServiceInstanceLogStreamAutoConfigurationTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Test
void servicesAreNotCreatedWithoutLoggingOnClasspath() {
	contextRunner
		.withClassLoader(new FilteredClassLoader(ApplicationLogStreamPublisher.class))
		.withUserConfiguration(LoggingConfiguration.class)
		.run(context -> assertThat(context)
			.doesNotHaveBean(StreamingLogWebSocketHandler.class)
			.doesNotHaveBean(WebSocketHandlerAdapter.class)
			.doesNotHaveBean(HandlerMapping.class)
			.doesNotHaveBean(LogStreamPublisher.class)
			.doesNotHaveBean(ApplicationLogStreamPublisher.class));
}
 
Example #16
Source File: ServiceInstanceLogStreamAutoConfiguration.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Bean
public HandlerMapping logsHandlerMapping(StreamingLogWebSocketHandler webSocketHandler) {
	Map<String, WebSocketHandler> map = new HashMap<>();
	map.put("/logs/**/stream", webSocketHandler);

	SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
	handlerMapping.setOrder(1);
	handlerMapping.setUrlMap(map);
	return handlerMapping;
}
 
Example #17
Source File: PathVariableMapMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void resolveArgument() throws Exception {
	Map<String, String> uriTemplateVars = new HashMap<>();
	uriTemplateVars.put("name1", "value1");
	uriTemplateVars.put("name2", "value2");
	this.exchange.getAttributes().put(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);

	Mono<Object> mono = this.resolver.resolveArgument(this.paramMap, new BindingContext(), this.exchange);
	Object result = mono.block();

	assertEquals(uriTemplateVars, result);
}
 
Example #18
Source File: ServiceInstanceLogStreamAutoConfigurationTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Test
void servicesAreNotCreatedWithoutRequiredBeansOnClasspath() {
	contextRunner
		.run(context -> assertThat(context)
			.doesNotHaveBean(StreamingLogWebSocketHandler.class)
			.doesNotHaveBean(WebSocketHandlerAdapter.class)
			.doesNotHaveBean(HandlerMapping.class)
			.doesNotHaveBean(LogStreamPublisher.class)
			.doesNotHaveBean(ApplicationLogStreamPublisher.class));
}
 
Example #19
Source File: ReservationServiceApplication.java    From bootiful-reactive-microservices with Apache License 2.0 5 votes vote down vote up
@Bean
HandlerMapping hm() {
	SimpleUrlHandlerMapping simpleUrlHandlerMapping = new SimpleUrlHandlerMapping();
	simpleUrlHandlerMapping.setOrder(10);
	simpleUrlHandlerMapping.setUrlMap(Collections.singletonMap("/ws/greetings", this.wsh()));
	return simpleUrlHandlerMapping;
}
 
Example #20
Source File: Application.java    From spring-reactive-playground with Apache License 2.0 5 votes vote down vote up
@Bean
public HandlerMapping handlerMapping() {

	Map<String, WebSocketHandler> map = new HashMap<>();
	map.put("/websocket/echo", new EchoWebSocketHandler());

	SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
	mapping.setUrlMap(map);
	return mapping;
}
 
Example #21
Source File: PathVariableMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void resolveArgumentWrappedAsOptional() throws Exception {
	Map<String, String> uriTemplateVars = new HashMap<>();
	uriTemplateVars.put("name", "value");
	this.exchange.getAttributes().put(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);

	ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
	initializer.setConversionService(new DefaultFormattingConversionService());
	BindingContext bindingContext = new BindingContext(initializer);

	Mono<Object> mono = this.resolver.resolveArgument(this.paramOptional, bindingContext, this.exchange);
	Object result = mono.block();
	assertEquals(Optional.of("value"), result);
}
 
Example #22
Source File: PathVariableMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void resolveArgumentNotRequired() throws Exception {
	Map<String, String> uriTemplateVars = new HashMap<>();
	uriTemplateVars.put("name", "value");
	this.exchange.getAttributes().put(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);

	BindingContext bindingContext = new BindingContext();
	Mono<Object> mono = this.resolver.resolveArgument(this.paramNotRequired, bindingContext, this.exchange);
	Object result = mono.block();
	assertEquals("value", result);
}
 
Example #23
Source File: PathVariableMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void resolveArgument() throws Exception {
	Map<String, String> uriTemplateVars = new HashMap<>();
	uriTemplateVars.put("name", "value");
	this.exchange.getAttributes().put(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);

	BindingContext bindingContext = new BindingContext();
	Mono<Object> mono = this.resolver.resolveArgument(this.paramNamedString, bindingContext, this.exchange);
	Object result = mono.block();
	assertEquals("value", result);
}
 
Example #24
Source File: MatrixVariablesMapMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private MultiValueMap<String, String> getMatrixVariables(String pathVarName) {
	Map<String, MultiValueMap<String, String>> matrixVariables =
			this.exchange.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE);

	MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
	matrixVariables.put(pathVarName, params);

	return params;
}
 
Example #25
Source File: MatrixVariablesMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private MultiValueMap<String, String> getVariablesFor(String pathVarName) {
	Map<String, MultiValueMap<String, String>> matrixVariables =
			this.exchange.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE);

	MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
	matrixVariables.put(pathVarName, params);
	return params;
}
 
Example #26
Source File: RedirectViewTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void expandUriTemplateVariablesFromExchangeAttribute() {
	String url = "http://url.somewhere.com?foo={foo}";
	Map<String, String> attributes = Collections.singletonMap("foo", "bar");
	this.exchange.getAttributes().put(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, attributes);
	RedirectView view = new RedirectView(url);
	view.render(new HashMap<>(), MediaType.TEXT_HTML, exchange).block();
	assertEquals(URI.create("http://url.somewhere.com?foo=bar"), this.exchange.getResponse().getHeaders().getLocation());
}
 
Example #27
Source File: ResourceHandlerRegistryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void mapPathToLocation() throws Exception {
	MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
	exchange.getAttributes().put(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE,
			PathContainer.parsePath("/testStylesheet.css"));

	ResourceWebHandler handler = getHandler("/resources/**");
	handler.handle(exchange).block(Duration.ofSeconds(5));

	StepVerifier.create(exchange.getResponse().getBody())
			.consumeNextWith(buf -> assertEquals("test stylesheet content",
					DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8)))
			.expectComplete()
			.verify();
}
 
Example #28
Source File: SimpleUrlHandlerMappingTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("resource")
public void handlerMappingXmlConfig() throws Exception {
	ClassPathXmlApplicationContext wac = new ClassPathXmlApplicationContext("map.xml", getClass());
	wac.refresh();

	HandlerMapping handlerMapping = wac.getBean("mapping", HandlerMapping.class);
	Object mainController = wac.getBean("mainController");

	testUrl("/pathmatchingTest.html", mainController, handlerMapping, "pathmatchingTest.html");
	testUrl("welcome.html", null, handlerMapping, null);
	testUrl("/pathmatchingAA.html", mainController, handlerMapping, "pathmatchingAA.html");
	testUrl("/pathmatchingA.html", null, handlerMapping, null);
	testUrl("/administrator/pathmatching.html", mainController, handlerMapping, "");
	testUrl("/administrator/test/pathmatching.html", mainController, handlerMapping, "test/pathmatching.html");
	testUrl("/administratort/pathmatching.html", null, handlerMapping, null);
	testUrl("/administrator/another/bla.xml", mainController, handlerMapping, "");
	testUrl("/administrator/another/bla.gif", null, handlerMapping, null);
	testUrl("/administrator/test/testlastbit", mainController, handlerMapping, "test/testlastbit");
	testUrl("/administrator/test/testla", null, handlerMapping, null);
	testUrl("/administrator/testing/longer/bla", mainController, handlerMapping, "bla");
	testUrl("/administrator/testing/longer2/notmatching/notmatching", null, handlerMapping, null);
	testUrl("/shortpattern/testing/toolong", null, handlerMapping, null);
	testUrl("/XXpathXXmatching.html", mainController, handlerMapping, "XXpathXXmatching.html");
	testUrl("/pathXXmatching.html", mainController, handlerMapping, "pathXXmatching.html");
	testUrl("/XpathXXmatching.html", null, handlerMapping, null);
	testUrl("/XXpathmatching.html", null, handlerMapping, null);
	testUrl("/show12.html", mainController, handlerMapping, "show12.html");
	testUrl("/show123.html", mainController, handlerMapping, "");
	testUrl("/show1.html", mainController, handlerMapping, "show1.html");
	testUrl("/reallyGood-test-is-this.jpeg", mainController, handlerMapping, "reallyGood-test-is-this.jpeg");
	testUrl("/reallyGood-tst-is-this.jpeg", null, handlerMapping, null);
	testUrl("/testing/test.jpeg", mainController, handlerMapping, "testing/test.jpeg");
	testUrl("/testing/test.jpg", null, handlerMapping, null);
	testUrl("/anotherTest", mainController, handlerMapping, "anotherTest");
	testUrl("/stillAnotherTest", null, handlerMapping, null);
	testUrl("outofpattern*ye", null, handlerMapping, null);
}
 
Example #29
Source File: WebConfig.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@Bean
    public HandlerMapping handlerMapping() {
        Map<String, WebSocketHandler> map = new HashMap<>();
        map.put("/echo", new EchoWebSocketHandler());
	    map.put("/posts", new PostsWebSocketHandler(this.posts));
//			map.put("/custom-header", new CustomHeaderHandler());

        SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
        mapping.setUrlMap(map);
        return mapping;
    }
 
Example #30
Source File: RequestMappingInfoHandlerMappingTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void handleMatchUriTemplateVariables() {
	ServerWebExchange exchange = MockServerWebExchange.from(get("/1/2"));

	RequestMappingInfo key = paths("/{path1}/{path2}").build();
	this.handlerMapping.handleMatch(key, handlerMethod, exchange);

	String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
	Map<String, String> uriVariables = (Map<String, String>) exchange.getAttributes().get(name);

	assertNotNull(uriVariables);
	assertEquals("1", uriVariables.get("path1"));
	assertEquals("2", uriVariables.get("path2"));
}