Search in sources :

Example 41 with MultiValueMap

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

the class MapToMapConverterTests method multiValueMapToMultiValueMap.

@Test
@SuppressWarnings("unchecked")
public void multiValueMapToMultiValueMap() throws Exception {
    DefaultConversionService.addDefaultConverters(conversionService);
    MultiValueMap<String, Integer> source = new LinkedMultiValueMap<>();
    source.put("a", Arrays.asList(1, 2, 3));
    source.put("b", Arrays.asList(4, 5, 6));
    TypeDescriptor targetType = new TypeDescriptor(getClass().getField("multiValueMapTarget"));
    MultiValueMap<String, String> converted = (MultiValueMap<String, String>) conversionService.convert(source, targetType);
    assertThat(converted.size(), equalTo(2));
    assertThat(converted.get("a"), equalTo(Arrays.asList("1", "2", "3")));
    assertThat(converted.get("b"), equalTo(Arrays.asList("4", "5", "6")));
}
Also used : TypeDescriptor(org.springframework.core.convert.TypeDescriptor) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Test(org.junit.Test)

Example 42 with MultiValueMap

use of org.springframework.util.MultiValueMap in project spring-data-document-examples by spring-projects.

the class FormHttpMessageConverter method writeParts.

private void writeParts(OutputStream os, MultiValueMap<String, Object> parts, byte[] boundary) throws IOException {
    for (Map.Entry<String, List<Object>> entry : parts.entrySet()) {
        String name = entry.getKey();
        for (Object part : entry.getValue()) {
            writeBoundary(boundary, os);
            HttpEntity entity = getEntity(part);
            writePart(name, entity, os);
            writeNewLine(os);
        }
    }
}
Also used : HttpEntity(org.springframework.http.HttpEntity) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Example 43 with MultiValueMap

use of org.springframework.util.MultiValueMap in project pinpoint by naver.

the class HttpRemoteService method createPost.

private HttpPost createPost(String url, MultiValueMap<String, String> params) throws UnsupportedEncodingException {
    HttpPost post = new HttpPost(url);
    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    for (Map.Entry<String, List<String>> entry : params.entrySet()) {
        String key = entry.getKey();
        for (String value : entry.getValue()) {
            nvps.add(new BasicNameValuePair(key, value));
        }
    }
    post.setEntity(new UrlEncodedFormEntity(nvps));
    return post;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) MultiValueMap(org.springframework.util.MultiValueMap) Map(java.util.Map) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Example 44 with MultiValueMap

use of org.springframework.util.MultiValueMap in project spring-security-oauth by spring-projects.

the class AbstractRefreshTokenSupportTests method refreshAccessToken.

private OAuth2AccessToken refreshAccessToken(String refreshToken) {
    MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
    formData.add("grant_type", "refresh_token");
    formData.add("client_id", "my-trusted-client");
    formData.add("refresh_token", refreshToken);
    formData.add("scope", "read");
    HttpHeaders headers = getTokenHeaders("my-trusted-client");
    @SuppressWarnings("rawtypes") ResponseEntity<Map> response = http.postForMap(tokenPath(), headers, formData);
    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertTrue("Wrong cache control: " + response.getHeaders().getFirst("Cache-Control"), response.getHeaders().getFirst("Cache-Control").contains("no-store"));
    @SuppressWarnings("unchecked") OAuth2AccessToken newAccessToken = DefaultOAuth2AccessToken.valueOf(response.getBody());
    return newAccessToken;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) MultiValueMap(org.springframework.util.MultiValueMap) Map(java.util.Map) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Example 45 with MultiValueMap

use of org.springframework.util.MultiValueMap in project spring-security-oauth by spring-projects.

the class HttpTestUtils method postForStatus.

private ResponseEntity<Void> postForStatus(RestOperations client, String path, HttpHeaders headers, MultiValueMap<String, String> formData) {
    HttpHeaders actualHeaders = new HttpHeaders();
    actualHeaders.putAll(headers);
    actualHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    return client.exchange(getUrl(path), HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(formData, actualHeaders), (Class<Void>) null);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) MultiValueMap(org.springframework.util.MultiValueMap)

Aggregations

MultiValueMap (org.springframework.util.MultiValueMap)48 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)34 Test (org.junit.Test)18 Map (java.util.Map)17 HttpHeaders (org.springframework.http.HttpHeaders)17 List (java.util.List)10 HttpEntity (org.springframework.http.HttpEntity)9 RestTemplate (org.springframework.web.client.RestTemplate)7 URI (java.net.URI)4 LinkedHashMap (java.util.LinkedHashMap)4 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)4 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ResponseEntity (org.springframework.http.ResponseEntity)3 HttpRequestHandler (org.springframework.web.HttpRequestHandler)3 DefaultHandshakeHandler (org.springframework.web.socket.server.support.DefaultHandshakeHandler)3 HttpSessionHandshakeInterceptor (org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor)3 WebSocketHttpRequestHandler (org.springframework.web.socket.server.support.WebSocketHttpRequestHandler)3 SockJsHttpRequestHandler (org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler)3