use of org.springframework.util.MimeType in project spring-framework by spring-projects.
the class MappingJackson2MessageConverterTests method mimetypeParametrizedConstructor.
// SPR-12724
@Test
public void mimetypeParametrizedConstructor() {
MimeType mimetype = new MimeType("application", "xml", StandardCharsets.UTF_8);
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(mimetype);
assertThat(converter.getSupportedMimeTypes(), contains(mimetype));
assertFalse(converter.getObjectMapper().getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
}
use of org.springframework.util.MimeType in project spring-framework by spring-projects.
the class MappingJackson2MessageConverterTests method toMessageUtf16String.
@Test
public void toMessageUtf16String() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
converter.setSerializedPayloadClass(String.class);
MimeType contentType = new MimeType("application", "json", StandardCharsets.UTF_16BE);
Map<String, Object> map = new HashMap<>();
map.put(MessageHeaders.CONTENT_TYPE, contentType);
MessageHeaders headers = new MessageHeaders(map);
String payload = "Héllo Wörld";
Message<?> message = converter.toMessage(payload, headers);
assertEquals("\"" + payload + "\"", message.getPayload());
assertEquals(contentType, message.getHeaders().get(MessageHeaders.CONTENT_TYPE));
}
use of org.springframework.util.MimeType in project spring-framework by spring-projects.
the class DefaultStompSessionTests method handleErrorFrame.
@Test
public void handleErrorFrame() throws Exception {
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.ERROR);
accessor.setContentType(new MimeType("text", "plain", StandardCharsets.UTF_8));
accessor.addNativeHeader("foo", "bar");
accessor.setLeaveMutable(true);
String payload = "Oops";
StompHeaders stompHeaders = StompHeaders.readOnlyStompHeaders(accessor.getNativeHeaders());
when(this.sessionHandler.getPayloadType(stompHeaders)).thenReturn(String.class);
this.session.handleMessage(MessageBuilder.createMessage(payload.getBytes(StandardCharsets.UTF_8), accessor.getMessageHeaders()));
verify(this.sessionHandler).getPayloadType(stompHeaders);
verify(this.sessionHandler).handleFrame(stompHeaders, payload);
verifyNoMoreInteractions(this.sessionHandler);
}
use of org.springframework.util.MimeType in project spring-framework by spring-projects.
the class Jackson2JsonEncoder method encode.
@Override
public Flux<DataBuffer> encode(Publisher<?> inputStream, DataBufferFactory bufferFactory, ResolvableType elementType, MimeType mimeType, Map<String, Object> hints) {
Assert.notNull(inputStream, "'inputStream' must not be null");
Assert.notNull(bufferFactory, "'bufferFactory' must not be null");
Assert.notNull(elementType, "'elementType' must not be null");
if (inputStream instanceof Mono) {
return Flux.from(inputStream).map(value -> encodeValue(value, bufferFactory, elementType, hints));
} else if (APPLICATION_STREAM_JSON.isCompatibleWith(mimeType)) {
return Flux.from(inputStream).map(value -> {
DataBuffer buffer = encodeValue(value, bufferFactory, elementType, hints);
buffer.write(new byte[] { '\n' });
return buffer;
});
}
ResolvableType listType = ResolvableType.forClassWithGenerics(List.class, elementType);
return Flux.from(inputStream).collectList().map(list -> encodeValue(list, bufferFactory, listType, hints)).flux();
}
use of org.springframework.util.MimeType 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());
}
Aggregations