Search in sources :

Example 6 with MultipartHttpMessageWriter

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));
}
Also used : MultipartHttpMessageWriter(org.springframework.http.codec.multipart.MultipartHttpMessageWriter) MultipartBodyBuilder(org.springframework.http.client.MultipartBodyBuilder) MultipartHttpMessageWriter(org.springframework.http.codec.multipart.MultipartHttpMessageWriter) Test(org.junit.jupiter.api.Test)

Example 7 with MultipartHttpMessageWriter

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);
}
Also used : HttpMessageReader(org.springframework.http.codec.HttpMessageReader) MultipartHttpMessageWriter(org.springframework.http.codec.multipart.MultipartHttpMessageWriter) HttpMessageWriter(org.springframework.http.codec.HttpMessageWriter) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) MultipartHttpMessageWriter(org.springframework.http.codec.multipart.MultipartHttpMessageWriter) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with MultipartHttpMessageWriter

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()));
}
Also used : MockClientHttpRequest(org.springframework.web.testfixture.http.client.reactive.MockClientHttpRequest) MultipartHttpMessageWriter(org.springframework.http.codec.multipart.MultipartHttpMessageWriter)

Example 9 with MultipartHttpMessageWriter

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<>();
}
Also used : ByteBufferEncoder(org.springframework.core.codec.ByteBufferEncoder) ServerSentEventHttpMessageWriter(org.springframework.http.codec.ServerSentEventHttpMessageWriter) FormHttpMessageWriter(org.springframework.http.codec.FormHttpMessageWriter) MultipartHttpMessageWriter(org.springframework.http.codec.multipart.MultipartHttpMessageWriter) ResourceHttpMessageWriter(org.springframework.http.codec.ResourceHttpMessageWriter) EncoderHttpMessageWriter(org.springframework.http.codec.EncoderHttpMessageWriter) HttpMessageWriter(org.springframework.http.codec.HttpMessageWriter) Optional(java.util.Optional) ArrayList(java.util.ArrayList) ServerSentEventHttpMessageWriter(org.springframework.http.codec.ServerSentEventHttpMessageWriter) Jaxb2XmlEncoder(org.springframework.http.codec.xml.Jaxb2XmlEncoder) Jackson2JsonEncoder(org.springframework.http.codec.json.Jackson2JsonEncoder) ResourceHttpMessageWriter(org.springframework.http.codec.ResourceHttpMessageWriter) List(java.util.List) ArrayList(java.util.ArrayList) FormHttpMessageWriter(org.springframework.http.codec.FormHttpMessageWriter) MultipartHttpMessageWriter(org.springframework.http.codec.multipart.MultipartHttpMessageWriter) Map(java.util.Map) HashMap(java.util.HashMap) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

MultipartHttpMessageWriter (org.springframework.http.codec.multipart.MultipartHttpMessageWriter)9 HttpMessageWriter (org.springframework.http.codec.HttpMessageWriter)7 EncoderHttpMessageWriter (org.springframework.http.codec.EncoderHttpMessageWriter)6 FormHttpMessageWriter (org.springframework.http.codec.FormHttpMessageWriter)6 ResourceHttpMessageWriter (org.springframework.http.codec.ResourceHttpMessageWriter)6 Jackson2JsonEncoder (org.springframework.http.codec.json.Jackson2JsonEncoder)5 Test (org.junit.jupiter.api.Test)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ByteBufferEncoder (org.springframework.core.codec.ByteBufferEncoder)3 HttpMessageReader (org.springframework.http.codec.HttpMessageReader)3 ServerSentEventHttpMessageWriter (org.springframework.http.codec.ServerSentEventHttpMessageWriter)3 ProtobufHttpMessageWriter (org.springframework.http.codec.protobuf.ProtobufHttpMessageWriter)3 BeforeEach (org.junit.jupiter.api.BeforeEach)2 DecoderHttpMessageReader (org.springframework.http.codec.DecoderHttpMessageReader)2 FormHttpMessageReader (org.springframework.http.codec.FormHttpMessageReader)2 ResourceHttpMessageReader (org.springframework.http.codec.ResourceHttpMessageReader)2 ServerSentEventHttpMessageReader (org.springframework.http.codec.ServerSentEventHttpMessageReader)2 Jackson2JsonDecoder (org.springframework.http.codec.json.Jackson2JsonDecoder)2 ServerHttpRequest (org.springframework.http.server.reactive.ServerHttpRequest)2