Search in sources :

Example 1 with ClientCodecConfigurer

use of org.springframework.http.codec.ClientCodecConfigurer in project spring-framework by spring-projects.

the class ClientCodecConfigurerTests method cloneShouldNotBeImpactedByChangesToOriginal.

@Test
public void cloneShouldNotBeImpactedByChangesToOriginal() {
    ClientCodecConfigurer clone = this.configurer.clone();
    this.configurer.registerDefaults(false);
    this.configurer.customCodecs().register(new Jackson2JsonEncoder());
    List<HttpMessageWriter<?>> writers = findCodec(clone.getWriters(), MultipartHttpMessageWriter.class).getPartWriters();
    assertThat(writers).hasSize(12);
}
Also used : 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) ProtobufHttpMessageWriter(org.springframework.http.codec.protobuf.ProtobufHttpMessageWriter) HttpMessageWriter(org.springframework.http.codec.HttpMessageWriter) ClientCodecConfigurer(org.springframework.http.codec.ClientCodecConfigurer) MultipartHttpMessageWriter(org.springframework.http.codec.multipart.MultipartHttpMessageWriter) Jackson2JsonEncoder(org.springframework.http.codec.json.Jackson2JsonEncoder) Test(org.junit.jupiter.api.Test)

Example 2 with ClientCodecConfigurer

use of org.springframework.http.codec.ClientCodecConfigurer in project spring-framework by spring-projects.

the class ClientCodecConfigurerTests method cloneShouldNotDropMultipartCodecs.

// gh-24194
@Test
public void cloneShouldNotDropMultipartCodecs() {
    ClientCodecConfigurer clone = this.configurer.clone();
    List<HttpMessageWriter<?>> writers = findCodec(clone.getWriters(), MultipartHttpMessageWriter.class).getPartWriters();
    assertThat(writers).hasSize(12);
}
Also used : 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) ProtobufHttpMessageWriter(org.springframework.http.codec.protobuf.ProtobufHttpMessageWriter) HttpMessageWriter(org.springframework.http.codec.HttpMessageWriter) ClientCodecConfigurer(org.springframework.http.codec.ClientCodecConfigurer) MultipartHttpMessageWriter(org.springframework.http.codec.multipart.MultipartHttpMessageWriter) Test(org.junit.jupiter.api.Test)

Example 3 with ClientCodecConfigurer

use of org.springframework.http.codec.ClientCodecConfigurer in project spring-framework by spring-projects.

the class ClientCodecConfigurerTests method clonedConfigurer.

@Test
public void clonedConfigurer() {
    ClientCodecConfigurer clone = this.configurer.clone();
    Jackson2JsonDecoder jackson2Decoder = new Jackson2JsonDecoder();
    clone.defaultCodecs().serverSentEventDecoder(jackson2Decoder);
    clone.defaultCodecs().multipartCodecs().encoder(new Jackson2SmileEncoder());
    clone.defaultCodecs().multipartCodecs().writer(new ResourceHttpMessageWriter());
    // Clone has the customizations
    Decoder<?> sseDecoder = findCodec(clone.getReaders(), ServerSentEventHttpMessageReader.class).getDecoder();
    List<HttpMessageWriter<?>> writers = findCodec(clone.getWriters(), MultipartHttpMessageWriter.class).getPartWriters();
    assertThat(sseDecoder).isSameAs(jackson2Decoder);
    assertThat(writers).hasSize(2);
    // Original does not have the customizations
    sseDecoder = findCodec(this.configurer.getReaders(), ServerSentEventHttpMessageReader.class).getDecoder();
    writers = findCodec(this.configurer.getWriters(), MultipartHttpMessageWriter.class).getPartWriters();
    assertThat(sseDecoder).isNotSameAs(jackson2Decoder);
    assertThat(writers).hasSize(12);
}
Also used : ServerSentEventHttpMessageReader(org.springframework.http.codec.ServerSentEventHttpMessageReader) 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) ProtobufHttpMessageWriter(org.springframework.http.codec.protobuf.ProtobufHttpMessageWriter) HttpMessageWriter(org.springframework.http.codec.HttpMessageWriter) ClientCodecConfigurer(org.springframework.http.codec.ClientCodecConfigurer) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) Jackson2SmileEncoder(org.springframework.http.codec.json.Jackson2SmileEncoder) ResourceHttpMessageWriter(org.springframework.http.codec.ResourceHttpMessageWriter) MultipartHttpMessageWriter(org.springframework.http.codec.multipart.MultipartHttpMessageWriter) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 ClientCodecConfigurer (org.springframework.http.codec.ClientCodecConfigurer)3 EncoderHttpMessageWriter (org.springframework.http.codec.EncoderHttpMessageWriter)3 FormHttpMessageWriter (org.springframework.http.codec.FormHttpMessageWriter)3 HttpMessageWriter (org.springframework.http.codec.HttpMessageWriter)3 ResourceHttpMessageWriter (org.springframework.http.codec.ResourceHttpMessageWriter)3 MultipartHttpMessageWriter (org.springframework.http.codec.multipart.MultipartHttpMessageWriter)3 ProtobufHttpMessageWriter (org.springframework.http.codec.protobuf.ProtobufHttpMessageWriter)3 ServerSentEventHttpMessageReader (org.springframework.http.codec.ServerSentEventHttpMessageReader)1 Jackson2JsonDecoder (org.springframework.http.codec.json.Jackson2JsonDecoder)1 Jackson2JsonEncoder (org.springframework.http.codec.json.Jackson2JsonEncoder)1 Jackson2SmileEncoder (org.springframework.http.codec.json.Jackson2SmileEncoder)1