Search in sources :

Example 61 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project spring-framework by spring-projects.

the class BodyInsertersTests method ofFormData.

@Test
public void ofFormData() throws Exception {
    MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
    body.set("name 1", "value 1");
    body.add("name 2", "value 2+1");
    body.add("name 2", "value 2+2");
    body.add("name 3", null);
    BodyInserter<MultiValueMap<String, String>, ClientHttpRequest> inserter = BodyInserters.fromFormData(body);
    MockClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, URI.create("http://example.com"));
    Mono<Void> result = inserter.insert(request, this.context);
    StepVerifier.create(result).expectComplete().verify();
    StepVerifier.create(request.getBody()).consumeNextWith(dataBuffer -> {
        byte[] resultBytes = new byte[dataBuffer.readableByteCount()];
        dataBuffer.read(resultBytes);
        assertArrayEquals("name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3".getBytes(StandardCharsets.UTF_8), resultBytes);
    }).expectComplete().verify();
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) MockClientHttpRequest(org.springframework.mock.http.client.reactive.test.MockClientHttpRequest) ClientHttpRequest(org.springframework.http.client.reactive.ClientHttpRequest) MockClientHttpRequest(org.springframework.mock.http.client.reactive.test.MockClientHttpRequest) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Test(org.junit.Test)

Example 62 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project spring-framework by spring-projects.

the class DefaultClientResponseTests method cookies.

@Test
public void cookies() throws Exception {
    ResponseCookie cookie = ResponseCookie.from("foo", "bar").build();
    MultiValueMap<String, ResponseCookie> cookies = new LinkedMultiValueMap<>();
    cookies.add("foo", cookie);
    when(mockResponse.getCookies()).thenReturn(cookies);
    assertSame(cookies, defaultClientResponse.cookies());
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ResponseCookie(org.springframework.http.ResponseCookie) Test(org.junit.Test)

Example 63 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project spring-framework by spring-projects.

the class RequestMappingInfoHandlerMapping method parseMatrixVariables.

/**
	 * Parse the given string with matrix variables. An example string would look
	 * like this {@code "q1=a;q1=b;q2=a,b,c"}. The resulting map would contain
	 * keys {@code "q1"} and {@code "q2"} with values {@code ["a","b"]} and
	 * {@code ["a","b","c"]} respectively.
	 * @param matrixVariables the unparsed matrix variables string
	 * @return a map with matrix variable names and values (never {@code null})
	 */
private static MultiValueMap<String, String> parseMatrixVariables(String matrixVariables) {
    MultiValueMap<String, String> result = new LinkedMultiValueMap<>();
    if (!StringUtils.hasText(matrixVariables)) {
        return result;
    }
    StringTokenizer pairs = new StringTokenizer(matrixVariables, ";");
    while (pairs.hasMoreTokens()) {
        String pair = pairs.nextToken();
        int index = pair.indexOf('=');
        if (index != -1) {
            String name = pair.substring(0, index);
            String rawValue = pair.substring(index + 1);
            for (String value : StringUtils.commaDelimitedListToStringArray(rawValue)) {
                result.add(name, value);
            }
        } else {
            result.add(pair, "");
        }
    }
    return result;
}
Also used : StringTokenizer(java.util.StringTokenizer) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Example 64 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project spring-framework by spring-projects.

the class RequestHeaderMapMethodArgumentResolverTests method resolveMultiValueMapArgument.

@Test
public void resolveMultiValueMapArgument() throws Exception {
    String name = "foo";
    String value1 = "bar";
    String value2 = "baz";
    ServerWebExchange exchange = MockServerHttpRequest.get("/").header(name, value1, value2).toExchange();
    MultiValueMap<String, String> expected = new LinkedMultiValueMap<>(1);
    expected.add(name, value1);
    expected.add(name, value2);
    Mono<Object> mono = resolver.resolveArgument(paramMultiValueMap, null, exchange);
    Object result = mono.block();
    assertTrue(result instanceof MultiValueMap);
    assertEquals("Invalid result", expected, result);
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Test(org.junit.Test)

Example 65 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project spring-framework by spring-projects.

the class WebMvcStompWebSocketEndpointRegistration method getMappings.

public final MultiValueMap<HttpRequestHandler, String> getMappings() {
    MultiValueMap<HttpRequestHandler, String> mappings = new LinkedMultiValueMap<>();
    if (this.registration != null) {
        SockJsService sockJsService = this.registration.getSockJsService();
        for (String path : this.paths) {
            String pattern = path.endsWith("/") ? path + "**" : path + "/**";
            SockJsHttpRequestHandler handler = new SockJsHttpRequestHandler(sockJsService, this.webSocketHandler);
            mappings.add(handler, pattern);
        }
    } else {
        for (String path : this.paths) {
            WebSocketHttpRequestHandler handler;
            if (this.handshakeHandler != null) {
                handler = new WebSocketHttpRequestHandler(this.webSocketHandler, this.handshakeHandler);
            } else {
                handler = new WebSocketHttpRequestHandler(this.webSocketHandler);
            }
            HandshakeInterceptor[] interceptors = getInterceptors();
            if (interceptors.length > 0) {
                handler.setHandshakeInterceptors(Arrays.asList(interceptors));
            }
            mappings.add(handler, path);
        }
    }
    return mappings;
}
Also used : SockJsHttpRequestHandler(org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) WebSocketHttpRequestHandler(org.springframework.web.socket.server.support.WebSocketHttpRequestHandler) SockJsHttpRequestHandler(org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler) HttpRequestHandler(org.springframework.web.HttpRequestHandler) SockJsService(org.springframework.web.socket.sockjs.SockJsService) HandshakeInterceptor(org.springframework.web.socket.server.HandshakeInterceptor) OriginHandshakeInterceptor(org.springframework.web.socket.server.support.OriginHandshakeInterceptor) WebSocketHttpRequestHandler(org.springframework.web.socket.server.support.WebSocketHttpRequestHandler)

Aggregations

LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)76 Test (org.junit.Test)40 HttpHeaders (org.springframework.http.HttpHeaders)20 MultiValueMap (org.springframework.util.MultiValueMap)19 Map (java.util.Map)9 HttpEntity (org.springframework.http.HttpEntity)9 RestTemplate (org.springframework.web.client.RestTemplate)9 ClassPathResource (org.springframework.core.io.ClassPathResource)8 MediaType (org.springframework.http.MediaType)7 URI (java.net.URI)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 Resource (org.springframework.core.io.Resource)5 HashMap (java.util.HashMap)4 FileItem (org.apache.commons.fileupload.FileItem)4 Credential (org.apereo.cas.authentication.Credential)4 IdmAuditDto (eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto)3 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)3 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)3 X509CertificateCredential (org.apereo.cas.adaptors.x509.authentication.principal.X509CertificateCredential)3