use of org.springframework.http.codec.multipart.MultipartHttpMessageWriter in project spring-framework by spring-projects.
the class CancelWithoutDemandCodecTests method cancelWithMultipartContent.
// gh-22107
@Test
public void cancelWithMultipartContent() {
MultipartBodyBuilder builder = new MultipartBodyBuilder();
builder.part("part1", "value1");
builder.part("part2", "value2");
List<HttpMessageWriter<?>> writers = ClientCodecConfigurer.create().getWriters();
MultipartHttpMessageWriter writer = new MultipartHttpMessageWriter(writers);
CancellingOutputMessage outputMessage = new CancellingOutputMessage(this.bufferFactory);
writer.write(Mono.just(builder.build()), null, MediaType.MULTIPART_FORM_DATA, outputMessage, Collections.emptyMap()).block(Duration.ofSeconds(5));
}
use of org.springframework.http.codec.multipart.MultipartHttpMessageWriter in project spring-framework by spring-projects.
the class RequestPartMethodArgumentResolverTests method setup.
@BeforeEach
void setup() {
List<HttpMessageReader<?>> readers = ServerCodecConfigurer.create().getReaders();
ReactiveAdapterRegistry registry = ReactiveAdapterRegistry.getSharedInstance();
this.resolver = new RequestPartMethodArgumentResolver(readers, registry);
List<HttpMessageWriter<?>> writers = ClientCodecConfigurer.create().getWriters();
this.writer = new MultipartHttpMessageWriter(writers);
}
use of org.springframework.http.codec.multipart.MultipartHttpMessageWriter in project spring-framework by spring-projects.
the class WebExchangeDataBinderTests method exchangeMultipart.
private ServerWebExchange exchangeMultipart(MultiValueMap<String, ?> multipartData) {
MockClientHttpRequest request = new MockClientHttpRequest(HttpMethod.POST, "/");
new MultipartHttpMessageWriter().write(Mono.just(multipartData), forClass(MultiValueMap.class), MediaType.MULTIPART_FORM_DATA, request, Collections.emptyMap()).block();
return MockServerWebExchange.from(MockServerHttpRequest.post("/").contentType(request.getHeaders().getContentType()).body(request.getBody()));
}
use of org.springframework.http.codec.multipart.MultipartHttpMessageWriter in project spring-framework by spring-projects.
the class BodyInsertersTests method createContext.
@BeforeEach
public void createContext() {
final List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
messageWriters.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
messageWriters.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()));
messageWriters.add(new ResourceHttpMessageWriter());
messageWriters.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()));
Jackson2JsonEncoder jsonEncoder = new Jackson2JsonEncoder();
messageWriters.add(new EncoderHttpMessageWriter<>(jsonEncoder));
messageWriters.add(new ServerSentEventHttpMessageWriter(jsonEncoder));
messageWriters.add(new FormHttpMessageWriter());
messageWriters.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
messageWriters.add(new MultipartHttpMessageWriter(messageWriters));
this.context = new BodyInserter.Context() {
@Override
public List<HttpMessageWriter<?>> messageWriters() {
return messageWriters;
}
@Override
public Optional<ServerHttpRequest> serverRequest() {
return Optional.empty();
}
@Override
public Map<String, Object> hints() {
return hints;
}
};
this.hints = new HashMap<>();
}
Aggregations