本文整理汇总了Java中org.springframework.messaging.converter.AbstractMessageConverter类的典型用法代码示例。如果您正苦于以下问题:Java AbstractMessageConverter类的具体用法?Java AbstractMessageConverter怎么用?Java AbstractMessageConverter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AbstractMessageConverter类属于org.springframework.messaging.converter包,在下文中一共展示了AbstractMessageConverter类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMessageConverterForType
import org.springframework.messaging.converter.AbstractMessageConverter; //导入依赖的package包/类
/**
* Creation method.
* @param mimeType the target MIME type
* @return a converter for the target MIME type
*/
public MessageConverter getMessageConverterForType(MimeType mimeType) {
List<MessageConverter> converters = new ArrayList<>();
for (MessageConverter converter : this.converters) {
if (converter instanceof AbstractMessageConverter) {
for (MimeType type : ((AbstractMessageConverter) converter).getSupportedMimeTypes()) {
if (type.includes(mimeType)) {
converters.add(converter);
}
}
}
else {
if (this.log.isDebugEnabled()) {
this.log.debug("Ommitted " + converter + " of type " + converter.getClass().toString() +
" for '" + mimeType.toString() + "' as it is not an AbstractMessageConverter");
}
}
}
if (CollectionUtils.isEmpty(converters)) {
throw new ConversionException("No message converter is registered for "
+ mimeType.toString());
}
if (converters.size() > 1) {
return new CompositeMessageConverter(converters);
}
else {
return converters.get(0);
}
}
示例2: testConfigureOutputChannelCannotConvert
import org.springframework.messaging.converter.AbstractMessageConverter; //导入依赖的package包/类
@Test
@Ignore
public void testConfigureOutputChannelCannotConvert() {
BindingServiceProperties props = new BindingServiceProperties();
BindingProperties bindingProps = new BindingProperties();
bindingProps.setContentType("foo/bar");
props.setBindings(Collections.singletonMap("foo", bindingProps));
MessageConverter converter = new AbstractMessageConverter(new MimeType("foo", "bar")) {
@Override
protected boolean supports(Class<?> clazz) {
return true;
}
@Override
protected Object convertToInternal(Object payload, MessageHeaders headers, Object conversionHint) {
return null;
}
};
CompositeMessageConverterFactory converterFactory = new CompositeMessageConverterFactory(
Collections.<MessageConverter>singletonList(converter), null);
MessageConverterConfigurer configurer = new MessageConverterConfigurer(props, converterFactory);
QueueChannel out = new QueueChannel();
configurer.configureOutputChannel(out, "foo");
try {
out.send(new GenericMessage<Foo>(new Foo(),
Collections.<String, Object> singletonMap(MessageHeaders.CONTENT_TYPE, "bad/ct")));
fail("Expected MessageConversionException: " + out.receive(0));
}
catch (MessageConversionException e) {
assertThat(e.getMessage()).endsWith("to the configured output type: 'foo/bar'");
}
}
示例3: busJsonConverter
import org.springframework.messaging.converter.AbstractMessageConverter; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(name = "busJsonConverter")
@StreamMessageConverter
public AbstractMessageConverter busJsonConverter(@Autowired(required = false) ObjectMapper objectMapper) {
return new BusJacksonMessageConverter(objectMapper);
}