use of cn.taketoday.core.DefaultMultiValueMap in project today-infrastructure by TAKETODAY.
the class ReactorServerHttpRequest method initCookies.
@Override
protected MultiValueMap<String, HttpCookie> initCookies() {
DefaultMultiValueMap<String, HttpCookie> cookies = MultiValueMap.fromLinkedHashMap();
for (Map.Entry<CharSequence, Set<Cookie>> entry : request.cookies().entrySet()) {
CharSequence name = entry.getKey();
for (Cookie cookie : entry.getValue()) {
HttpCookie httpCookie = new HttpCookie(name.toString(), cookie.value());
cookies.add(name.toString(), httpCookie);
}
}
return cookies;
}
use of cn.taketoday.core.DefaultMultiValueMap in project today-infrastructure by TAKETODAY.
the class Jackson2ObjectMapperBuilder method configure.
/**
* Configure an existing {@link ObjectMapper} instance with this builder's
* settings. This can be applied to any number of {@code ObjectMappers}.
*
* @param objectMapper the ObjectMapper to configure
*/
public void configure(ObjectMapper objectMapper) {
Assert.notNull(objectMapper, "ObjectMapper must not be null");
DefaultMultiValueMap<Object, Module> modulesToRegister = MultiValueMap.fromLinkedHashMap();
if (this.findModulesViaServiceLoader) {
for (Module module : ObjectMapper.findModules(this.moduleClassLoader)) {
registerModule(module, modulesToRegister);
}
} else if (this.findWellKnownModules) {
registerWellKnownModulesIfAvailable(modulesToRegister);
}
if (this.modules != null) {
for (Module module : modules) {
registerModule(module, modulesToRegister);
}
}
if (this.moduleClasses != null) {
for (Class<? extends Module> moduleClass : this.moduleClasses) {
registerModule(BeanUtils.newInstance(moduleClass), modulesToRegister);
}
}
List<Module> modules = new ArrayList<>();
for (List<Module> nestedModules : modulesToRegister.values()) {
modules.addAll(nestedModules);
}
objectMapper.registerModules(modules);
if (this.dateFormat != null) {
objectMapper.setDateFormat(this.dateFormat);
}
if (this.locale != null) {
objectMapper.setLocale(this.locale);
}
if (this.timeZone != null) {
objectMapper.setTimeZone(this.timeZone);
}
if (this.annotationIntrospector != null) {
objectMapper.setAnnotationIntrospector(this.annotationIntrospector);
}
if (this.propertyNamingStrategy != null) {
objectMapper.setPropertyNamingStrategy(this.propertyNamingStrategy);
}
if (this.defaultTyping != null) {
objectMapper.setDefaultTyping(this.defaultTyping);
}
if (this.serializationInclusion != null) {
objectMapper.setDefaultPropertyInclusion(this.serializationInclusion);
}
if (this.filters != null) {
objectMapper.setFilterProvider(this.filters);
}
this.mixIns.forEach(objectMapper::addMixIn);
if (!this.serializers.isEmpty() || !this.deserializers.isEmpty()) {
SimpleModule module = new SimpleModule();
addSerializers(module);
addDeserializers(module);
objectMapper.registerModule(module);
}
this.visibilities.forEach(objectMapper::setVisibility);
for (Map.Entry<Object, Boolean> entry : features.entrySet()) {
Object feature = entry.getKey();
Boolean enabled = entry.getValue();
configureFeature(objectMapper, feature, enabled);
}
customizeDefaultFeatures(objectMapper);
if (this.handlerInstantiator != null) {
objectMapper.setHandlerInstantiator(this.handlerInstantiator);
} else if (this.applicationContext != null) {
objectMapper.setHandlerInstantiator(new BeanFactoryHandlerInstantiator(this.applicationContext.getAutowireCapableBeanFactory()));
}
if (this.configurer != null) {
this.configurer.accept(objectMapper);
}
}
use of cn.taketoday.core.DefaultMultiValueMap in project today-infrastructure by TAKETODAY.
the class FormHttpMessageWriterTests method writeForm.
@Test
public void writeForm() {
MultiValueMap<String, String> body = new DefaultMultiValueMap<>(new LinkedHashMap<>());
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);
MockServerHttpResponse response = new MockServerHttpResponse(this.bufferFactory);
this.writer.write(Mono.just(body), null, MediaType.APPLICATION_FORM_URLENCODED, response, null).block();
String expected = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3";
StepVerifier.create(response.getBody()).consumeNextWith(stringConsumer(expected)).expectComplete().verify();
HttpHeaders headers = response.getHeaders();
assertThat(headers.getContentType().toString()).isEqualTo("application/x-www-form-urlencoded;charset=UTF-8");
assertThat(headers.getContentLength()).isEqualTo(expected.length());
}
use of cn.taketoday.core.DefaultMultiValueMap in project today-infrastructure by TAKETODAY.
the class FormHttpMessageConverterTests method writeMultipartOrder.
// SPR-13309
@Test
public void writeMultipartOrder() throws Exception {
MyBean myBean = new MyBean();
myBean.setString("foo");
MultiValueMap<String, Object> parts = new DefaultMultiValueMap<>();
parts.add("part1", myBean);
HttpHeaders entityHeaders = HttpHeaders.create();
entityHeaders.setContentType(APPLICATION_JSON);
HttpEntity<MyBean> entity = new HttpEntity<>(myBean, entityHeaders);
parts.add("part2", entity);
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
this.converter.setMultipartCharset(StandardCharsets.UTF_8);
this.converter.write(parts, new MediaType("multipart", "form-data", StandardCharsets.UTF_8), outputMessage);
MediaType contentType = outputMessage.getHeaders().getContentType();
assertThat(contentType.getParameter("boundary")).as("No boundary found").isNotNull();
// see if Commons FileUpload can read what we wrote
FileItemFactory fileItemFactory = new DiskFileItemFactory();
FileUpload fileUpload = new FileUpload(fileItemFactory);
RequestContext requestContext = new MockHttpOutputMessageRequestContext(outputMessage);
List<FileItem> items = fileUpload.parseRequest(requestContext);
assertThat(items.size()).isEqualTo(2);
FileItem item = items.get(0);
assertThat(item.isFormField()).isTrue();
assertThat(item.getFieldName()).isEqualTo("part1");
assertThat(item.getString()).isEqualTo("{\"string\":\"foo\"}");
}
Aggregations