Search in sources :

Example 1 with HttpRequestPathHelper

use of org.springframework.web.server.support.HttpRequestPathHelper in project spring-framework by spring-projects.

the class RequestMappingInfoHandlerMappingTests method handleMatchMatrixVariablesDecoding.

@Test
public void handleMatchMatrixVariablesDecoding() throws Exception {
    HttpRequestPathHelper urlPathHelper = new HttpRequestPathHelper();
    urlPathHelper.setUrlDecode(false);
    this.handlerMapping.setPathHelper(urlPathHelper);
    ServerWebExchange exchange = get("/").toExchange();
    handleMatch(exchange, "/path{filter}", "/path;mvar=a%2fb");
    MultiValueMap<String, String> matrixVariables = getMatrixVariables(exchange, "filter");
    Map<String, String> uriVariables = getUriTemplateVariables(exchange);
    assertNotNull(matrixVariables);
    assertEquals(Collections.singletonList("a/b"), matrixVariables.get("mvar"));
    assertEquals(";mvar=a/b", uriVariables.get("filter"));
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) HttpRequestPathHelper(org.springframework.web.server.support.HttpRequestPathHelper) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 2 with HttpRequestPathHelper

use of org.springframework.web.server.support.HttpRequestPathHelper in project spring-framework by spring-projects.

the class RequestMappingInfoHandlerMappingTests method handleMatchUriTemplateVariablesDecode.

// SPR-9098
@Test
public void handleMatchUriTemplateVariablesDecode() throws Exception {
    RequestMappingInfo key = paths("/{group}/{identifier}").build();
    URI url = URI.create("/group/a%2Fb");
    ServerWebExchange exchange = MockServerHttpRequest.method(HttpMethod.GET, url).toExchange();
    HttpRequestPathHelper pathHelper = new HttpRequestPathHelper();
    pathHelper.setUrlDecode(false);
    String lookupPath = pathHelper.getLookupPathForRequest(exchange);
    this.handlerMapping.setPathHelper(pathHelper);
    this.handlerMapping.handleMatch(key, lookupPath, 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"));
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) HttpRequestPathHelper(org.springframework.web.server.support.HttpRequestPathHelper) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) URI(java.net.URI) Map(java.util.Map) MultiValueMap(org.springframework.util.MultiValueMap) Test(org.junit.Test)

Aggregations

CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Test (org.junit.Test)2 ServerWebExchange (org.springframework.web.server.ServerWebExchange)2 HttpRequestPathHelper (org.springframework.web.server.support.HttpRequestPathHelper)2 URI (java.net.URI)1 Map (java.util.Map)1 MultiValueMap (org.springframework.util.MultiValueMap)1