use of org.springframework.util.MimeType in project spring-framework by spring-projects.
the class WebFluxConfigurationSupportTests method viewResolutionResultHandler.
@Test
public void viewResolutionResultHandler() throws Exception {
ApplicationContext context = loadConfig(CustomViewResolverConfig.class);
String name = "viewResolutionResultHandler";
ViewResolutionResultHandler handler = context.getBean(name, ViewResolutionResultHandler.class);
assertNotNull(handler);
assertEquals(Ordered.LOWEST_PRECEDENCE, handler.getOrder());
List<ViewResolver> resolvers = handler.getViewResolvers();
assertEquals(1, resolvers.size());
assertEquals(FreeMarkerViewResolver.class, resolvers.get(0).getClass());
List<View> views = handler.getDefaultViews();
assertEquals(1, views.size());
MimeType type = MimeTypeUtils.parseMimeType("application/json;charset=UTF-8");
assertEquals(type, views.get(0).getSupportedMediaTypes().get(0));
}
use of org.springframework.util.MimeType in project spring-framework by spring-projects.
the class HttpMessageWriterViewTests method supportedMediaTypes.
@Test
public void supportedMediaTypes() throws Exception {
List<MimeType> mimeTypes = Arrays.asList(new MimeType("application", "json", StandardCharsets.UTF_8), new MimeType("application", "*+json", StandardCharsets.UTF_8));
assertEquals(mimeTypes, this.view.getSupportedMediaTypes());
}
use of org.springframework.util.MimeType in project spring-framework by spring-projects.
the class AbstractMessageConverter method toMessage.
@Override
public final Message<?> toMessage(Object payload, MessageHeaders headers, Object conversionHint) {
if (!canConvertTo(payload, headers)) {
return null;
}
payload = convertToInternal(payload, headers, conversionHint);
if (payload == null) {
return null;
}
MimeType mimeType = getDefaultContentType(payload);
if (headers != null) {
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(headers, MessageHeaderAccessor.class);
if (accessor != null && accessor.isMutable()) {
accessor.setHeaderIfAbsent(MessageHeaders.CONTENT_TYPE, mimeType);
return MessageBuilder.createMessage(payload, accessor.getMessageHeaders());
}
}
MessageBuilder<?> builder = MessageBuilder.withPayload(payload);
if (headers != null) {
builder.copyHeaders(headers);
}
builder.setHeaderIfAbsent(MessageHeaders.CONTENT_TYPE, mimeType);
return builder.build();
}
use of org.springframework.util.MimeType in project spring-framework by spring-projects.
the class ResourceRegionEncoderTests method canEncode.
@Test
public void canEncode() {
ResolvableType resourceRegion = ResolvableType.forClass(ResourceRegion.class);
MimeType allMimeType = MimeType.valueOf("*/*");
assertFalse(this.encoder.canEncode(ResolvableType.forClass(Resource.class), MimeTypeUtils.APPLICATION_OCTET_STREAM));
assertFalse(this.encoder.canEncode(ResolvableType.forClass(Resource.class), allMimeType));
assertTrue(this.encoder.canEncode(resourceRegion, MimeTypeUtils.APPLICATION_OCTET_STREAM));
assertTrue(this.encoder.canEncode(resourceRegion, allMimeType));
}
use of org.springframework.util.MimeType in project spring-framework by spring-projects.
the class DefaultStompSessionTests method send.
@Test
public void send() throws Exception {
this.session.afterConnected(this.connection);
assertTrue(this.session.isConnected());
String destination = "/topic/foo";
String payload = "sample payload";
this.session.send(destination, payload);
Message<byte[]> message = this.messageCaptor.getValue();
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
assertEquals(StompCommand.SEND, accessor.getCommand());
StompHeaders stompHeaders = StompHeaders.readOnlyStompHeaders(accessor.getNativeHeaders());
assertEquals(stompHeaders.toString(), 2, stompHeaders.size());
assertEquals(destination, stompHeaders.getDestination());
assertEquals(new MimeType("text", "plain", StandardCharsets.UTF_8), stompHeaders.getContentType());
// StompEncoder isn't involved
assertEquals(-1, stompHeaders.getContentLength());
assertEquals(payload, new String(message.getPayload(), StandardCharsets.UTF_8));
}
Aggregations