Search in sources :

Example 1 with ServerCodecConfigurer

use of cn.taketoday.http.codec.ServerCodecConfigurer in project today-framework by TAKETODAY.

the class ServerCodecConfigurerTests method cloneConfigurer.

@Test
public void cloneConfigurer() {
    ServerCodecConfigurer clone = this.configurer.clone();
    MultipartHttpMessageReader reader = new MultipartHttpMessageReader(new DefaultPartHttpMessageReader());
    Jackson2JsonEncoder encoder = new Jackson2JsonEncoder();
    clone.defaultCodecs().multipartReader(reader);
    clone.defaultCodecs().serverSentEventEncoder(encoder);
    // Clone has the customizations
    HttpMessageReader<?> actualReader = findCodec(clone.getReaders(), MultipartHttpMessageReader.class);
    ServerSentEventHttpMessageWriter actualWriter = findCodec(clone.getWriters(), ServerSentEventHttpMessageWriter.class);
    assertThat(actualReader).isSameAs(reader);
    assertThat(actualWriter.getEncoder()).isSameAs(encoder);
    // Original does not have the customizations
    actualReader = findCodec(this.configurer.getReaders(), MultipartHttpMessageReader.class);
    actualWriter = findCodec(this.configurer.getWriters(), ServerSentEventHttpMessageWriter.class);
    assertThat(actualReader).isNotSameAs(reader);
    assertThat(actualWriter.getEncoder()).isNotSameAs(encoder);
}
Also used : MultipartHttpMessageReader(cn.taketoday.http.codec.multipart.MultipartHttpMessageReader) DefaultPartHttpMessageReader(cn.taketoday.http.codec.multipart.DefaultPartHttpMessageReader) ServerSentEventHttpMessageWriter(cn.taketoday.http.codec.ServerSentEventHttpMessageWriter) ServerCodecConfigurer(cn.taketoday.http.codec.ServerCodecConfigurer) Jackson2JsonEncoder(cn.taketoday.http.codec.json.Jackson2JsonEncoder) Test(org.junit.jupiter.api.Test)

Example 2 with ServerCodecConfigurer

use of cn.taketoday.http.codec.ServerCodecConfigurer in project today-infrastructure by TAKETODAY.

the class ServerCodecConfigurerTests method cloneConfigurer.

@Test
public void cloneConfigurer() {
    ServerCodecConfigurer clone = this.configurer.clone();
    MultipartHttpMessageReader reader = new MultipartHttpMessageReader(new DefaultPartHttpMessageReader());
    Jackson2JsonEncoder encoder = new Jackson2JsonEncoder();
    clone.defaultCodecs().multipartReader(reader);
    clone.defaultCodecs().serverSentEventEncoder(encoder);
    // Clone has the customizations
    HttpMessageReader<?> actualReader = findCodec(clone.getReaders(), MultipartHttpMessageReader.class);
    ServerSentEventHttpMessageWriter actualWriter = findCodec(clone.getWriters(), ServerSentEventHttpMessageWriter.class);
    assertThat(actualReader).isSameAs(reader);
    assertThat(actualWriter.getEncoder()).isSameAs(encoder);
    // Original does not have the customizations
    actualReader = findCodec(this.configurer.getReaders(), MultipartHttpMessageReader.class);
    actualWriter = findCodec(this.configurer.getWriters(), ServerSentEventHttpMessageWriter.class);
    assertThat(actualReader).isNotSameAs(reader);
    assertThat(actualWriter.getEncoder()).isNotSameAs(encoder);
}
Also used : MultipartHttpMessageReader(cn.taketoday.http.codec.multipart.MultipartHttpMessageReader) DefaultPartHttpMessageReader(cn.taketoday.http.codec.multipart.DefaultPartHttpMessageReader) ServerSentEventHttpMessageWriter(cn.taketoday.http.codec.ServerSentEventHttpMessageWriter) ServerCodecConfigurer(cn.taketoday.http.codec.ServerCodecConfigurer) Jackson2JsonEncoder(cn.taketoday.http.codec.json.Jackson2JsonEncoder) Test(org.junit.jupiter.api.Test)

Aggregations

ServerCodecConfigurer (cn.taketoday.http.codec.ServerCodecConfigurer)2 ServerSentEventHttpMessageWriter (cn.taketoday.http.codec.ServerSentEventHttpMessageWriter)2 Jackson2JsonEncoder (cn.taketoday.http.codec.json.Jackson2JsonEncoder)2 DefaultPartHttpMessageReader (cn.taketoday.http.codec.multipart.DefaultPartHttpMessageReader)2 MultipartHttpMessageReader (cn.taketoday.http.codec.multipart.MultipartHttpMessageReader)2 Test (org.junit.jupiter.api.Test)2