use of cn.taketoday.core.MultiValueMap in project today-framework by TAKETODAY.
the class MultipartHttpMessageWriter method writeMultipart.
private Mono<Void> writeMultipart(MultiValueMap<String, ?> map, ReactiveHttpOutputMessage outputMessage, @Nullable MediaType mediaType, Map<String, Object> hints) {
byte[] boundary = generateMultipartBoundary();
mediaType = getMultipartMediaType(mediaType, boundary);
outputMessage.getHeaders().setContentType(mediaType);
LogFormatUtils.traceDebug(logger, traceOn -> Hints.getLogPrefix(hints) + "Encoding " + (isEnableLoggingRequestDetails() ? LogFormatUtils.formatValue(map, !traceOn) : "parts " + map.keySet() + " (content masked)"));
DataBufferFactory bufferFactory = outputMessage.bufferFactory();
Flux<DataBuffer> body = Flux.fromIterable(map.entrySet()).concatMap(entry -> encodePartValues(boundary, entry.getKey(), entry.getValue(), bufferFactory)).concatWith(generateLastLine(boundary, bufferFactory)).doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release);
if (logger.isDebugEnabled()) {
body = body.doOnNext(buffer -> Hints.touchDataBuffer(buffer, hints, logger));
}
return outputMessage.writeWith(body);
}
use of cn.taketoday.core.MultiValueMap in project today-framework by TAKETODAY.
the class MatrixParamMapParameterResolvingStrategy method resolveParameter.
@Nullable
@Override
public Object resolveParameter(RequestContext context, ResolvableMethodParameter resolvable) throws Throwable {
Map<String, MultiValueMap<String, String>> matrixVariables = context.getMatchingMetadata().getMatrixVariables();
if (CollectionUtils.isEmpty(matrixVariables)) {
return Collections.emptyMap();
}
MultiValueMap<String, String> map = MultiValueMap.fromLinkedHashMap();
MethodParameter parameter = resolvable.getParameter();
MatrixParam ann = parameter.getParameterAnnotation(MatrixParam.class);
Assert.state(ann != null, "No MatrixVariable annotation");
String pathVariable = ann.pathVar();
if (!pathVariable.equals(Constant.DEFAULT_NONE)) {
MultiValueMap<String, String> mapForPathVariable = matrixVariables.get(pathVariable);
if (mapForPathVariable == null) {
return Collections.emptyMap();
}
map.putAll(mapForPathVariable);
} else {
for (MultiValueMap<String, String> vars : matrixVariables.values()) {
for (Map.Entry<String, List<String>> entry : vars.entrySet()) {
String name = entry.getKey();
List<String> values = entry.getValue();
for (String value : values) {
map.add(name, value);
}
}
}
}
return (isSingleValueMap(parameter) ? map.toSingleValueMap() : map);
}
use of cn.taketoday.core.MultiValueMap in project today-framework by TAKETODAY.
the class FormHttpMessageReaderTests method readFormError.
@Test
public void readFormError() {
DataBuffer fooBuffer = stringBuffer("name=value");
Flux<DataBuffer> body = Flux.just(fooBuffer).concatWith(Flux.error(new RuntimeException()));
MockServerHttpRequest request = request(body);
Flux<MultiValueMap<String, String>> result = this.reader.read(null, request, null);
StepVerifier.create(result).expectError().verify();
}
use of cn.taketoday.core.MultiValueMap in project today-framework by TAKETODAY.
the class BodyInsertersTests method fromFormDataMap.
@Test
public void fromFormDataMap() {
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("https://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);
DataBufferUtils.release(dataBuffer);
assertThat(resultBytes).isEqualTo("name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3".getBytes(StandardCharsets.UTF_8));
}).expectComplete().verify();
}
use of cn.taketoday.core.MultiValueMap in project today-framework by TAKETODAY.
the class RequestResponseBodyMethodProcessorTests method resolveArgumentRawTypeFromParameterizedType.
@Test
public void resolveArgumentRawTypeFromParameterizedType() throws Throwable {
String content = "fruit=apple&vegetable=kale";
this.servletRequest.setMethod("GET");
this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8));
this.servletRequest.setContentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new AllEncompassingFormHttpMessageConverter());
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
@SuppressWarnings("unchecked") MultiValueMap<String, String> result = (MultiValueMap<String, String>) processor.resolveArgument(request, paramMultiValueMap);
assertThat(result).isNotNull();
assertThat(result.getFirst("fruit")).isEqualTo("apple");
assertThat(result.getFirst("vegetable")).isEqualTo("kale");
}
Aggregations