use of org.springframework.http.MediaType in project spring-framework by spring-projects.
the class RequestPartServletServerHttpRequest method determineCharset.
private Charset determineCharset() {
MediaType contentType = getHeaders().getContentType();
if (contentType != null) {
Charset charset = contentType.getCharset();
if (charset != null) {
return charset;
}
}
String encoding = this.multipartRequest.getCharacterEncoding();
return (encoding != null ? Charset.forName(encoding) : FORM_CHARSET);
}
use of org.springframework.http.MediaType in project spring-framework by spring-projects.
the class EncoderHttpMessageWriterTests method testDefaultMediaType.
private void testDefaultMediaType(MediaType negotiatedMediaType) {
this.response = new MockServerHttpResponse();
this.mediaTypeCaptor = ArgumentCaptor.forClass(MediaType.class);
MimeType defaultContentType = MimeTypeUtils.TEXT_XML;
HttpMessageWriter<String> writer = getWriter(defaultContentType);
writer.write(Mono.just("body"), forClass(String.class), negotiatedMediaType, this.response, NO_HINTS);
assertEquals(defaultContentType, this.response.getHeaders().getContentType());
assertEquals(defaultContentType, this.mediaTypeCaptor.getValue());
}
use of org.springframework.http.MediaType in project spring-framework by spring-projects.
the class EncoderHttpMessageWriterTests method useDefaultMediaTypeCharset.
@Test
public void useDefaultMediaTypeCharset() throws Exception {
HttpMessageWriter<String> writer = getWriter(TEXT_PLAIN_UTF_8, TEXT_HTML);
writer.write(Mono.just("body"), forClass(String.class), TEXT_HTML, response, NO_HINTS);
assertEquals(new MediaType("text", "html", UTF_8), this.response.getHeaders().getContentType());
assertEquals(new MediaType("text", "html", UTF_8), this.mediaTypeCaptor.getValue());
}
use of org.springframework.http.MediaType in project spring-framework by spring-projects.
the class EncoderHttpMessageWriterTests method useNegotiatedMediaTypeCharset.
@Test
public void useNegotiatedMediaTypeCharset() throws Exception {
MediaType negotiatedMediaType = new MediaType("text", "html", ISO_8859_1);
HttpMessageWriter<String> writer = getWriter(TEXT_PLAIN_UTF_8, TEXT_HTML);
writer.write(Mono.just("body"), forClass(String.class), negotiatedMediaType, this.response, NO_HINTS);
assertEquals(negotiatedMediaType, this.response.getHeaders().getContentType());
assertEquals(negotiatedMediaType, this.mediaTypeCaptor.getValue());
}
use of org.springframework.http.MediaType in project spring-framework by spring-projects.
the class BufferedImageHttpMessageConverterTests method read.
@Test
public void read() throws IOException {
Resource logo = new ClassPathResource("logo.jpg", BufferedImageHttpMessageConverterTests.class);
byte[] body = FileCopyUtils.copyToByteArray(logo.getInputStream());
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
inputMessage.getHeaders().setContentType(new MediaType("image", "jpeg"));
BufferedImage result = converter.read(BufferedImage.class, inputMessage);
assertEquals("Invalid height", 500, result.getHeight());
assertEquals("Invalid width", 750, result.getWidth());
}
Aggregations