use of org.springframework.http.codec.multipart.MultipartHttpMessageWriter in project spring-security by spring-projects.
the class ServerOAuth2AuthorizedClientExchangeFilterFunctionTests method getBody.
private static String getBody(ClientRequest request) {
final List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
messageWriters.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
messageWriters.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()));
messageWriters.add(new ResourceHttpMessageWriter());
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));
BodyInserter.Context 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 new HashMap<>();
}
};
MockClientHttpRequest body = new MockClientHttpRequest(HttpMethod.GET, "/");
request.body().insert(body, context).block();
return body.getBodyAsString().block();
}
use of org.springframework.http.codec.multipart.MultipartHttpMessageWriter in project spring-framework by spring-projects.
the class ClientCodecConfigurerTests method objectMapperCustomization.
@Test
public void objectMapperCustomization() {
ObjectMapper objectMapper = new ObjectMapper();
this.configurer.defaultCodecs().configureDefaultCodec(codec -> {
if (codec instanceof Jackson2CodecSupport) {
((Jackson2CodecSupport) codec).setObjectMapper(objectMapper);
}
});
List<HttpMessageReader<?>> readers = this.configurer.getReaders();
Jackson2JsonDecoder actualDecoder = findCodec(readers, Jackson2JsonDecoder.class);
assertThat(actualDecoder.getObjectMapper()).isSameAs(objectMapper);
List<HttpMessageWriter<?>> writers = this.configurer.getWriters();
Jackson2JsonEncoder actualEncoder = findCodec(writers, Jackson2JsonEncoder.class);
assertThat(actualEncoder.getObjectMapper()).isSameAs(objectMapper);
MultipartHttpMessageWriter multipartWriter = findCodec(writers, MultipartHttpMessageWriter.class);
actualEncoder = findCodec(multipartWriter.getPartWriters(), Jackson2JsonEncoder.class);
assertThat(actualEncoder.getObjectMapper()).isSameAs(objectMapper);
}
use of org.springframework.http.codec.multipart.MultipartHttpMessageWriter in project spring-framework by spring-projects.
the class ClientCodecConfigurerTests method jackson2CodecCustomization.
@Test
public void jackson2CodecCustomization() {
Jackson2JsonDecoder decoder = new Jackson2JsonDecoder();
Jackson2JsonEncoder encoder = new Jackson2JsonEncoder();
this.configurer.defaultCodecs().jackson2JsonDecoder(decoder);
this.configurer.defaultCodecs().jackson2JsonEncoder(encoder);
List<HttpMessageReader<?>> readers = this.configurer.getReaders();
Jackson2JsonDecoder actualDecoder = findCodec(readers, Jackson2JsonDecoder.class);
assertThat(actualDecoder).isSameAs(decoder);
assertThat(findCodec(readers, ServerSentEventHttpMessageReader.class).getDecoder()).isSameAs(decoder);
List<HttpMessageWriter<?>> writers = this.configurer.getWriters();
Jackson2JsonEncoder actualEncoder = findCodec(writers, Jackson2JsonEncoder.class);
assertThat(actualEncoder).isSameAs(encoder);
MultipartHttpMessageWriter multipartWriter = findCodec(writers, MultipartHttpMessageWriter.class);
actualEncoder = findCodec(multipartWriter.getPartWriters(), Jackson2JsonEncoder.class);
assertThat(actualEncoder).isSameAs(encoder);
}
use of org.springframework.http.codec.multipart.MultipartHttpMessageWriter in project spring-framework by spring-projects.
the class ClientCodecConfigurerTests method enableLoggingRequestDetails.
@Test
public void enableLoggingRequestDetails() {
this.configurer.defaultCodecs().enableLoggingRequestDetails(true);
List<HttpMessageWriter<?>> writers = this.configurer.getWriters();
MultipartHttpMessageWriter multipartWriter = findCodec(writers, MultipartHttpMessageWriter.class);
assertThat(multipartWriter.isEnableLoggingRequestDetails()).isTrue();
FormHttpMessageWriter formWriter = (FormHttpMessageWriter) multipartWriter.getFormWriter();
assertThat(formWriter).isNotNull();
assertThat(formWriter.isEnableLoggingRequestDetails()).isTrue();
}
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