/** * Returns the default content type for the payload. Called when * {@link #toMessage(Object, MessageHeaders)} is invoked without message headers or * without a content type header. * <p>By default, this returns the first element of the {@link #getSupportedMimeTypes() * supportedMimeTypes}, if any. Can be overridden in sub-classes. * @param payload the payload being converted to message * @return the content type, or {@code null} if not known */ @Nullable protected MimeType getDefaultContentType(Object payload) { List<MimeType> mimeTypes = getSupportedMimeTypes(); return (!mimeTypes.isEmpty() ? mimeTypes.get(0) : null); }
/** * Whether this converter should convert messages for which no content type * could be resolved through the configured * {@link org.springframework.messaging.converter.ContentTypeResolver}. * <p>A converter can configured to be strict only when a * {@link #setContentTypeResolver contentTypeResolver} is configured and the * list of {@link #getSupportedMimeTypes() supportedMimeTypes} is not be empty. * <p>When this flag is set to {@code true}, {@link #supportsMimeType(MessageHeaders)} * will return {@code false} if the {@link #setContentTypeResolver contentTypeResolver} * is not defined or if no content-type header is present. */ public void setStrictContentTypeMatch(boolean strictContentTypeMatch) { if (strictContentTypeMatch) { Assert.notEmpty(getSupportedMimeTypes(), "Strict match requires non-empty list of supported mime types"); Assert.notNull(getContentTypeResolver(), "Strict match requires ContentTypeResolver"); } this.strictContentTypeMatch = strictContentTypeMatch; }
protected boolean supportsMimeType(@Nullable MessageHeaders headers) { if (getSupportedMimeTypes().isEmpty()) { return true; } MimeType mimeType = getMimeType(headers); if (mimeType == null) { return !isStrictContentTypeMatch(); } for (MimeType current : getSupportedMimeTypes()) { if (current.getType().equals(mimeType.getType()) && current.getSubtype().equals(mimeType.getSubtype())) { return true; } } return false; }
/** * Returns the default content type for the payload. Called when * {@link #toMessage(Object, MessageHeaders)} is invoked without message headers or * without a content type header. * <p>By default, this returns the first element of the {@link #getSupportedMimeTypes() * supportedMimeTypes}, if any. Can be overridden in sub-classes. * @param payload the payload being converted to message * @return the content type, or {@code null} if not known */ @Nullable protected MimeType getDefaultContentType(Object payload) { List<MimeType> mimeTypes = getSupportedMimeTypes(); return (!mimeTypes.isEmpty() ? mimeTypes.get(0) : null); }
/** * Whether this converter should convert messages for which no content type * could be resolved through the configured * {@link org.springframework.messaging.converter.ContentTypeResolver}. * <p>A converter can configured to be strict only when a * {@link #setContentTypeResolver contentTypeResolver} is configured and the * list of {@link #getSupportedMimeTypes() supportedMimeTypes} is not be empty. * <p>When this flag is set to {@code true}, {@link #supportsMimeType(MessageHeaders)} * will return {@code false} if the {@link #setContentTypeResolver contentTypeResolver} * is not defined or if no content-type header is present. */ public void setStrictContentTypeMatch(boolean strictContentTypeMatch) { if (strictContentTypeMatch) { Assert.notEmpty(getSupportedMimeTypes(), "Strict match requires non-empty list of supported mime types"); Assert.notNull(getContentTypeResolver(), "Strict match requires ContentTypeResolver"); } this.strictContentTypeMatch = strictContentTypeMatch; }
protected boolean supportsMimeType(@Nullable MessageHeaders headers) { if (getSupportedMimeTypes().isEmpty()) { return true; } MimeType mimeType = getMimeType(headers); if (mimeType == null) { return !isStrictContentTypeMatch(); } for (MimeType current : getSupportedMimeTypes()) { if (current.getType().equals(mimeType.getType()) && current.getSubtype().equals(mimeType.getSubtype())) { return true; } } return false; }
/** * Returns the default content type for the payload. Called when * {@link #toMessage(Object, MessageHeaders)} is invoked without message headers or * without a content type header. * <p>By default, this returns the first element of the {@link #getSupportedMimeTypes() * supportedMimeTypes}, if any. Can be overridden in sub-classes. * @param payload the payload being converted to message * @return the content type, or {@code null} if not known */ @Nullable protected MimeType getDefaultContentType(Object payload) { List<MimeType> mimeTypes = getSupportedMimeTypes(); return (!mimeTypes.isEmpty() ? mimeTypes.get(0) : null); }
/** * Returns the default content type for the payload. Called when * {@link #toMessage(Object, MessageHeaders)} is invoked without message headers or * without a content type header. * <p>By default, this returns the first element of the {@link #getSupportedMimeTypes() * supportedMimeTypes}, if any. Can be overridden in sub-classes. * @param payload the payload being converted to message * @return the content type, or {@code null} if not known */ @Nullable protected MimeType getDefaultContentType(Object payload) { List<MimeType> mimeTypes = getSupportedMimeTypes(); return (!mimeTypes.isEmpty() ? mimeTypes.get(0) : null); }
/** * Whether this converter should convert messages for which no content type * could be resolved through the configured * {@link org.springframework.messaging.converter.ContentTypeResolver}. * <p>A converter can configured to be strict only when a * {@link #setContentTypeResolver contentTypeResolver} is configured and the * list of {@link #getSupportedMimeTypes() supportedMimeTypes} is not be empty. * <p>When this flag is set to {@code true}, {@link #supportsMimeType(MessageHeaders)} * will return {@code false} if the {@link #setContentTypeResolver contentTypeResolver} * is not defined or if no content-type header is present. */ public void setStrictContentTypeMatch(boolean strictContentTypeMatch) { if (strictContentTypeMatch) { Assert.notEmpty(getSupportedMimeTypes(), "Strict match requires non-empty list of supported mime types"); Assert.notNull(getContentTypeResolver(), "Strict match requires ContentTypeResolver"); } this.strictContentTypeMatch = strictContentTypeMatch; }
/** * Whether this converter should convert messages for which no content type * could be resolved through the configured * {@link org.springframework.messaging.converter.ContentTypeResolver}. * <p>A converter can configured to be strict only when a * {@link #setContentTypeResolver contentTypeResolver} is configured and the * list of {@link #getSupportedMimeTypes() supportedMimeTypes} is not be empty. * <p>When this flag is set to {@code true}, {@link #supportsMimeType(MessageHeaders)} * will return {@code false} if the {@link #setContentTypeResolver contentTypeResolver} * is not defined or if no content-type header is present. */ public void setStrictContentTypeMatch(boolean strictContentTypeMatch) { if (strictContentTypeMatch) { Assert.notEmpty(getSupportedMimeTypes(), "Strict match requires non-empty list of supported mime types"); Assert.notNull(getContentTypeResolver(), "Strict match requires ContentTypeResolver"); } this.strictContentTypeMatch = strictContentTypeMatch; }
protected boolean supportsMimeType(@Nullable MessageHeaders headers) { if (getSupportedMimeTypes().isEmpty()) { return true; } MimeType mimeType = getMimeType(headers); if (mimeType == null) { return !isStrictContentTypeMatch(); } for (MimeType current : getSupportedMimeTypes()) { if (current.getType().equals(mimeType.getType()) && current.getSubtype().equals(mimeType.getSubtype())) { return true; } } return false; }
protected boolean supportsMimeType(@Nullable MessageHeaders headers) { if (getSupportedMimeTypes().isEmpty()) { return true; } MimeType mimeType = getMimeType(headers); if (mimeType == null) { return !isStrictContentTypeMatch(); } for (MimeType current : getSupportedMimeTypes()) { if (current.getType().equals(mimeType.getType()) && current.getSubtype().equals(mimeType.getSubtype())) { return true; } } return false; }
for (MessageConverter converter : this.converters) { if (converter instanceof AbstractMessageConverter) { for (MimeType type : ((AbstractMessageConverter) converter).getSupportedMimeTypes()) { if (type.includes(mimeType)) { converters.add(converter);