当前位置: 首页>>代码示例>>Java>>正文


Java AbstractMessageConverter类代码示例

本文整理汇总了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);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:34,代码来源:CompositeMessageConverterFactory.java

示例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'");
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:35,代码来源:MessageConverterConfigurerTests.java

示例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);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-bus,代码行数:7,代码来源:BusJacksonAutoConfiguration.java


注:本文中的org.springframework.messaging.converter.AbstractMessageConverter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。