@Override public List<String> put(String key, List<String> value) { return this.headers.put(key, value); }
@Override public List<String> put(String key, List<String> value) { return this.headers.put(key, value); }
@Override public WebSocketHandlerRegistration addHandler(WebSocketHandler handler, String... paths) { Assert.notNull(handler, "WebSocketHandler must not be null"); Assert.notEmpty(paths, "Paths must not be empty"); this.handlerMap.put(handler, Arrays.asList(paths)); return this; }
public List<String> put(String key, List<String> value) { return parameters.put(key, value); }
private static <K, V> void copyMultiValueMap(MultiValueMap<K,V> source, MultiValueMap<K,V> target) { source.forEach((key, value) -> target.put(key, new LinkedList<>(value))); }
public DefaultAccessTokenRequest(Map<String, String[]> parameters) { if (parameters!=null) { for (Entry<String,String[]> entry : parameters.entrySet()) { this.parameters.put(entry.getKey(), Arrays.asList(entry.getValue())); } } }
private static <K,V> void copy(MultiValueMap<K,V> src, MultiValueMap<K,V> dst) { if (!src.isEmpty()) { src.entrySet().stream() .filter(entry -> !dst.containsKey(entry.getKey())) .forEach(entry -> dst.put(entry.getKey(), entry.getValue())); } } }
private MultiValueMap<String, String> encodeQueryParams(BiFunction<String, Type, String> encoder) { int size = this.queryParams.size(); MultiValueMap<String, String> result = new LinkedMultiValueMap<>(size); this.queryParams.forEach((key, values) -> { String name = encoder.apply(key, Type.QUERY_PARAM); List<String> encodedValues = new ArrayList<>(values.size()); for (String value : values) { encodedValues.add(value != null ? encoder.apply(value, Type.QUERY_PARAM) : null); } result.put(name, encodedValues); }); return CollectionUtils.unmodifiableMultiValueMap(result); }
private static <K, V> void copyMultiValueMap(MultiValueMap<K,V> source, MultiValueMap<K,V> target) { source.forEach((key, value) -> target.put(key, new LinkedList<>(value))); }
private MultiValueMap<String, String> encodeQueryParams(BiFunction<String, Type, String> encoder) { int size = this.queryParams.size(); MultiValueMap<String, String> result = new LinkedMultiValueMap<>(size); this.queryParams.forEach((key, values) -> { String name = encoder.apply(key, Type.QUERY_PARAM); List<String> encodedValues = new ArrayList<>(values.size()); for (String value : values) { encodedValues.add(value != null ? encoder.apply(value, Type.QUERY_PARAM) : null); } result.put(name, encodedValues); }); return CollectionUtils.unmodifiableMultiValueMap(result); }
private MultiValueMap<String, String> expandQueryParams(UriTemplateVariables variables) { int size = this.queryParams.size(); MultiValueMap<String, String> result = new LinkedMultiValueMap<>(size); UriTemplateVariables queryVariables = new QueryUriTemplateVariables(variables); this.queryParams.forEach((key, values) -> { String name = expandUriComponent(key, queryVariables, this.variableEncoder); List<String> expandedValues = new ArrayList<>(values.size()); for (String value : values) { expandedValues.add(expandUriComponent(value, queryVariables, this.variableEncoder)); } result.put(name, expandedValues); }); return CollectionUtils.unmodifiableMultiValueMap(result); }
@NoWarning("BC") public void setOtherParam(String name, List<String> values) { List<String> otherP = otherParams.get(name); // triggers bug: Impossible // cast from String to // java.util.List if (otherP == null) { otherParams.put(name, values); } else { otherP.addAll(values); } }
@SuppressWarnings("unchecked") private void assertEnrichAndValidateAttributes(Map<String, Object> sourceAttributes, Map<String, Object> expected) throws Exception { Class<? extends Annotation> annotationType = ImplicitAliasesContextConfig.class; // Since the ordering of attribute methods returned by the JVM is non-deterministic, // we have to rig the attributeAliasesCache in AnnotationUtils so that the tests // consistently fail in case enrichAndValidateAttributes() is buggy. // Otherwise, these tests would intermittently pass even for an invalid implementation. Field cacheField = AnnotationUtils.class.getDeclaredField("attributeAliasesCache"); cacheField.setAccessible(true); Map<Class<? extends Annotation>, MultiValueMap<String, String>> attributeAliasesCache = (Map<Class<? extends Annotation>, MultiValueMap<String, String>>) cacheField.get(null); // Declare aliases in an order that will cause enrichAndValidateAttributes() to // fail unless it considers all aliases in the set of implicit aliases. MultiValueMap<String, String> aliases = new LinkedMultiValueMap<>(); aliases.put("xmlFile", Arrays.asList("value", "groovyScript", "location1", "location2", "location3")); aliases.put("groovyScript", Arrays.asList("value", "xmlFile", "location1", "location2", "location3")); aliases.put("value", Arrays.asList("xmlFile", "groovyScript", "location1", "location2", "location3")); aliases.put("location1", Arrays.asList("xmlFile", "groovyScript", "value", "location2", "location3")); aliases.put("location2", Arrays.asList("xmlFile", "groovyScript", "value", "location1", "location3")); aliases.put("location3", Arrays.asList("xmlFile", "groovyScript", "value", "location1", "location2")); attributeAliasesCache.put(annotationType, aliases); MapAnnotationAttributeExtractor extractor = new MapAnnotationAttributeExtractor(sourceAttributes, annotationType, null); Map<String, Object> enriched = extractor.getSource(); assertEquals("attribute map size", expected.size(), enriched.size()); expected.forEach((attr, expectedValue) -> assertThat("for attribute '" + attr + "'", enriched.get(attr), is(expectedValue))); }
private MultiValueMap<String, String> expandQueryParams(UriTemplateVariables variables) { int size = this.queryParams.size(); MultiValueMap<String, String> result = new LinkedMultiValueMap<>(size); UriTemplateVariables queryVariables = new QueryUriTemplateVariables(variables); this.queryParams.forEach((key, values) -> { String name = expandUriComponent(key, queryVariables, this.variableEncoder); List<String> expandedValues = new ArrayList<>(values.size()); for (String value : values) { expandedValues.add(expandUriComponent(value, queryVariables, this.variableEncoder)); } result.put(name, expandedValues); }); return CollectionUtils.unmodifiableMultiValueMap(result); }
@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"))); }
@Test public void putShouldOverrideExisting() { this.headers.add("TestHeader", "first"); this.headers.put("TestHeader", Arrays.asList("override")); assertEquals("override", this.headers.getFirst("TestHeader")); assertEquals(1, this.headers.get("TestHeader").size()); }
@Before public void setUp() throws Exception { userDetails = mock(UserDetails.class); mockUserDetails(userDetails); mockUaaWithUser(); userAttributes = new LinkedMultiValueMap<>(); userAttributes.put("1", Arrays.asList("1")); userAttributes.put("2", Arrays.asList("2", "3")); externalGroups = Arrays.asList("role1", "role2", "role3"); }
@Before public void setup() { MultiValueMap<String, String> customAttributes = new LinkedMultiValueMap<>(); customAttributes.put(MULTI_VALUE, Arrays.asList("value1", "value2")); customAttributes.add(SINGLE_VALUE, "value3"); roles = Arrays.asList("group1", "group1"); info = new UserInfo() .setUserAttributes(customAttributes) .setRoles(roles); userDatabase.storeUserInfo(ID, info); }
@Test // SPR-16350 public void fromMultipartDataWithMultipleValues() { MultiValueMap<String, Object> map = new LinkedMultiValueMap<>(); map.put("name", Arrays.asList("value1", "value2")); BodyInserters.FormInserter<Object> inserter = BodyInserters.fromMultipartData(map); 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(DataBufferUtils.join(request.getBody())) .consumeNextWith(dataBuffer -> { byte[] resultBytes = new byte[dataBuffer.readableByteCount()]; dataBuffer.read(resultBytes); DataBufferUtils.release(dataBuffer); String content = new String(resultBytes, StandardCharsets.UTF_8); assertThat(content, containsString("Content-Disposition: form-data; name=\"name\"\r\n" + "Content-Type: text/plain;charset=UTF-8\r\n" + "Content-Length: 6\r\n" + "\r\n" + "value1")); assertThat(content, containsString("Content-Disposition: form-data; name=\"name\"\r\n" + "Content-Type: text/plain;charset=UTF-8\r\n" + "Content-Length: 6\r\n" + "\r\n" + "value2")); }) .expectComplete() .verify(); }