List of usage examples for org.springframework.util MultiValueMap getFirst
@Nullable V getFirst(K key);
From source file:org.jasig.cas.support.rest.TicketsResource.java
/** * Obtain credential from the request. Could be overridden by subclasses. * * @param requestBody raw entity request body * @return the credential instance//from w w w . ja v a 2 s .c om */ protected Credential obtainCredential(final MultiValueMap<String, String> requestBody) { return new UsernamePasswordCredential(requestBody.getFirst("username"), requestBody.getFirst("password")); }
From source file:org.springframework.http.converter.FormHttpMessageConverterTests.java
@Test public void readForm() throws Exception { String body = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3"; MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.ISO_8859_1)); inputMessage.getHeaders()/*from w w w.java 2 s . c o m*/ .setContentType(new MediaType("application", "x-www-form-urlencoded", StandardCharsets.ISO_8859_1)); MultiValueMap<String, String> result = this.converter.read(null, inputMessage); assertEquals("Invalid result", 3, result.size()); assertEquals("Invalid result", "value 1", result.getFirst("name 1")); List<String> values = result.get("name 2"); assertEquals("Invalid result", 2, values.size()); assertEquals("Invalid result", "value 2+1", values.get(0)); assertEquals("Invalid result", "value 2+2", values.get(1)); assertNull("Invalid result", result.getFirst("name 3")); }
From source file:org.springframework.integration.config.MessagingGatewayRegistrar.java
/** * TODO until SPR-11709 will be resolved. * For any empty values, traverses back up the meta-annotation hierarchy to * see if a value has been overridden to empty, and replaces the first such value found. * @param valuesHierarchy The values hierarchy in order. * @param annotationAttributes The current attribute values. */// w w w . ja va 2 s. co m private void replaceEmptyOverrides(List<MultiValueMap<String, Object>> valuesHierarchy, Map<String, Object> annotationAttributes) { for (Entry<String, Object> entry : annotationAttributes.entrySet()) { Object value = entry.getValue(); if (!MessagingAnnotationUtils.hasValue(value)) { // see if we overrode a value that was higher in the annotation chain for (MultiValueMap<String, Object> metaAttributesMap : valuesHierarchy) { Object newValue = metaAttributesMap.getFirst(entry.getKey()); if (MessagingAnnotationUtils.hasValue(newValue)) { annotationAttributes.put(entry.getKey(), newValue); break; } } } } }
From source file:org.springframework.social.weibo.connect.WeiboOAuth2Template.java
@Override @SuppressWarnings("unchecked") protected AccessGrant postForAccessGrant(String accessTokenUrl, MultiValueMap<String, String> parameters) { List<String> params = new ArrayList<>(); for (String key : parameters.keySet()) { params.add(key + "=" + parameters.getFirst(key)); }/*from www . ja va2 s. c o m*/ String url = accessTokenUrl + "?" + params.stream().collect(Collectors.joining("&")); if (logger.isDebugEnabled()) { logger.debug("url = " + url); } MultiValueMap<String, String> response = getRestTemplate().postForObject(url, null, MultiValueMap.class); String expires = response.getFirst("expires_in"); String accessToken = response.getFirst("access_token"); if (logger.isDebugEnabled()) { logger.debug("access token value = " + accessToken); } return new AccessGrant(accessToken, null, null, expires != null ? Long.valueOf(expires) : null); }
From source file:org.springframework.social.yahoo.connect.YahooOAuth2Template.java
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) protected AccessGrant postForAccessGrant(String accessTokenUrl, MultiValueMap<String, String> parameters) { HttpHeaders headers = new HttpHeaders(); String auth = parameters.getFirst("client_id") + ":" + parameters.getFirst("client_secret"); byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("US-ASCII"))); String authHeader = "Basic " + new String(encodedAuth); headers.set("Authorization", authHeader); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>( parameters, headers);//from w w w.java2s .co m ResponseEntity<Map> responseEntity = getRestTemplate().exchange(accessTokenUrl, HttpMethod.POST, requestEntity, Map.class); Map<String, Object> responseMap = responseEntity.getBody(); return extractAccessGrant(responseMap); }
From source file:org.springframework.web.multipart.commons.CommonsMultipartResolverTests.java
private void doTestFiles(MultipartHttpServletRequest request) throws IOException { Set<String> fileNames = new HashSet<>(); Iterator<String> fileIter = request.getFileNames(); while (fileIter.hasNext()) { fileNames.add(fileIter.next());// w ww. j a v a 2 s .c om } assertEquals(3, fileNames.size()); assertTrue(fileNames.contains("field1")); assertTrue(fileNames.contains("field2")); assertTrue(fileNames.contains("field2x")); CommonsMultipartFile file1 = (CommonsMultipartFile) request.getFile("field1"); CommonsMultipartFile file2 = (CommonsMultipartFile) request.getFile("field2"); CommonsMultipartFile file2x = (CommonsMultipartFile) request.getFile("field2x"); Map<String, MultipartFile> fileMap = request.getFileMap(); assertEquals(3, fileMap.size()); assertTrue(fileMap.containsKey("field1")); assertTrue(fileMap.containsKey("field2")); assertTrue(fileMap.containsKey("field2x")); assertEquals(file1, fileMap.get("field1")); assertEquals(file2, fileMap.get("field2")); assertEquals(file2x, fileMap.get("field2x")); MultiValueMap<String, MultipartFile> multiFileMap = request.getMultiFileMap(); assertEquals(3, multiFileMap.size()); assertTrue(multiFileMap.containsKey("field1")); assertTrue(multiFileMap.containsKey("field2")); assertTrue(multiFileMap.containsKey("field2x")); List<MultipartFile> field1Files = multiFileMap.get("field1"); assertEquals(2, field1Files.size()); assertTrue(field1Files.contains(file1)); assertEquals(file1, multiFileMap.getFirst("field1")); assertEquals(file2, multiFileMap.getFirst("field2")); assertEquals(file2x, multiFileMap.getFirst("field2x")); assertEquals("type1", file1.getContentType()); assertEquals("type2", file2.getContentType()); assertEquals("type2", file2x.getContentType()); assertEquals("field1.txt", file1.getOriginalFilename()); assertEquals("field2.txt", file2.getOriginalFilename()); assertEquals("field2x.txt", file2x.getOriginalFilename()); assertEquals("text1", new String(file1.getBytes())); assertEquals("text2", new String(file2.getBytes())); assertEquals(5, file1.getSize()); assertEquals(5, file2.getSize()); assertTrue(file1.getInputStream() instanceof ByteArrayInputStream); assertTrue(file2.getInputStream() instanceof ByteArrayInputStream); File transfer1 = new File("C:/transfer1"); file1.transferTo(transfer1); File transfer2 = new File("C:/transfer2"); file2.transferTo(transfer2); assertEquals(transfer1, ((MockFileItem) file1.getFileItem()).writtenFile); assertEquals(transfer2, ((MockFileItem) file2.getFileItem()).writtenFile); }