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


Java MessageConversionException类代码示例

本文整理汇总了Java中org.springframework.messaging.converter.MessageConversionException的典型用法代码示例。如果您正苦于以下问题:Java MessageConversionException类的具体用法?Java MessageConversionException怎么用?Java MessageConversionException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MessageConversionException类属于org.springframework.messaging.converter包,在下文中一共展示了MessageConversionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: tensorflowInputConverter

import org.springframework.messaging.converter.MessageConversionException; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(name = "tensorflowInputConverter")
@SuppressWarnings("unchecked")
public TensorflowInputConverter tensorflowInputConverter() {
	return new TensorflowInputConverter() {

		@Override
		public Map<String, Object> convert(Object input, Map<String, Object> processorContext) {

			if (input instanceof Map) {
				return (Map<String, Object>) input;
			}

			throw new MessageConversionException("Unsupported input format: " + input);
		}
	};
}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:tensorflow,代码行数:18,代码来源:TensorflowCommonProcessorConfiguration.java

示例2: createMessage

import org.springframework.messaging.converter.MessageConversionException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Message<byte[]> createMessage(StompHeaderAccessor accessor, Object payload) {
	accessor.updateSimpMessageHeadersFromStompHeaders();
	Message<byte[]> message;
	if (payload == null) {
		message = MessageBuilder.createMessage(EMPTY_PAYLOAD, accessor.getMessageHeaders());
	}
	else if (payload instanceof byte[]) {
		message = MessageBuilder.createMessage((byte[]) payload, accessor.getMessageHeaders());
	}
	else {
		message = (Message<byte[]>) getMessageConverter().toMessage(payload, accessor.getMessageHeaders());
		accessor.updateStompHeadersFromSimpMessageHeaders();
		if (message == null) {
			throw new MessageConversionException("Unable to convert payload with type='" +
					payload.getClass().getName() + "', contentType='" + accessor.getContentType() +
					"', converter=[" + getMessageConverter() + "]");
		}
	}
	return message;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:DefaultStompSession.java

示例3: handleErrorFrameWithConversionException

import org.springframework.messaging.converter.MessageConversionException; //导入依赖的package包/类
@Test
public void handleErrorFrameWithConversionException() throws Exception {

	StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.ERROR);
	accessor.setContentType(MimeTypeUtils.APPLICATION_JSON);
	accessor.addNativeHeader("foo", "bar");
	accessor.setLeaveMutable(true);
	byte[] payload = "{'foo':'bar'}".getBytes(UTF_8);

	StompHeaders stompHeaders = StompHeaders.readOnlyStompHeaders(accessor.getNativeHeaders());
	when(this.sessionHandler.getPayloadType(stompHeaders)).thenReturn(Map.class);

	this.session.handleMessage(MessageBuilder.createMessage(payload, accessor.getMessageHeaders()));

	verify(this.sessionHandler).getPayloadType(stompHeaders);
	verify(this.sessionHandler).handleException(same(this.session), same(StompCommand.ERROR),
			eq(stompHeaders), same(payload), any(MessageConversionException.class));
	verifyNoMoreInteractions(this.sessionHandler);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:DefaultStompSessionTests.java

示例4: handle

import org.springframework.messaging.converter.MessageConversionException; //导入依赖的package包/类
public void handle(Message<?> message){
	Message<?> transformedMessage = message;
	if (convertToJson) {
		Object payload = message.getPayload();

		if (payload instanceof String) {
			PdxInstance transformedPayload = transformer.toObject((String)payload);
			transformedMessage =  MessageBuilder
					.fromMessage(message)
					.withPayload(transformedPayload)
					.build();
		}
		else {
			throw new MessageConversionException(String.format(
					"Cannot convert object of type %s", payload.getClass()
							.getName()));
		}
	}
	messageHandler.handleMessage(transformedMessage);
}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:gemfire,代码行数:21,代码来源:GemfireSinkHandler.java

示例5: fromMessage

import org.springframework.messaging.converter.MessageConversionException; //导入依赖的package包/类
@Nullable
@Override
public Object fromMessage(Message<?> message, Class<?> targetClass, @Nullable Object conversionHint) {
	if (!canConvertFrom(message, targetClass)) {
		return null;
	}
	if(!message.getPayload().getClass().isAssignableFrom(byte[].class)){
		throw new MessageConversionException("This converter can only convert messages with byte[] payload");
	}
	byte[] payload = (byte[])message.getPayload();
	try {
		return deserialize(payload, targetClass);
	}
	catch (IOException e) {
		throw new MessageConversionException("Could not deserialize payload",e);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream,代码行数:18,代码来源:KryoMessageConverter.java

示例6: fromMessage

import org.springframework.messaging.converter.MessageConversionException; //导入依赖的package包/类
@Override
public Object fromMessage(Message<?> message, Type targetType, Class<?> contextClass) {
    ObjectMapper objectMapper = getObjectMapper();
    JavaType javaType = objectMapper.getTypeFactory().constructType(targetType, contextClass);
    try {
        Object payload = message.getPayload();
        if (payload instanceof byte[]) {
            return objectMapper.readValue((byte[]) payload, javaType);
        } else {
            return objectMapper.readValue((String) payload, javaType);
        }
    } catch (IOException ex) {
        throw new MessageConversionException(message, "Could not read JSON: " + ex.getMessage(), ex);
    }
}
 
开发者ID:kinglcc,项目名称:spring-boot-jms,代码行数:16,代码来源:Jackson2MessageAdapterConverter.java

示例7: convertClassFromMessage

import org.springframework.messaging.converter.MessageConversionException; //导入依赖的package包/类
private Object convertClassFromMessage(Message<?> message, Class<?> targetClass) {
    Object payload = this.converter.fromMessage(message, targetClass);
    if (payload == null) {
        throw new MessageConversionException(message,
                "No converter found to convert to " + targetClass + ", message=" + message);
    }
    return payload;
}
 
开发者ID:kinglcc,项目名称:spring-boot-jms,代码行数:9,代码来源:Jackson2PayloadArgumentResolver.java

示例8: convertJavaTypeFromMessage

import org.springframework.messaging.converter.MessageConversionException; //导入依赖的package包/类
private Object convertJavaTypeFromMessage(Message<?> message, MethodParameter parameter) {
    Type targetType = parameter.getGenericParameterType();
    Class<?> contextClass = parameter.getContainingClass();
    Object payload = ((GenericMessageAdapterConverter) converter).fromMessage(message, targetType, contextClass);
    if (payload == null) {
        throw new MessageConversionException(message,
                "No converter found to convert to " + targetType + ", message=" + message);
    }
    return payload;
}
 
开发者ID:kinglcc,项目名称:spring-boot-jms,代码行数:11,代码来源:Jackson2PayloadArgumentResolver.java

示例9: invokeHandler

import org.springframework.messaging.converter.MessageConversionException; //导入依赖的package包/类
private void invokeHandler(StompFrameHandler handler, Message<byte[]> message, StompHeaders stompHeaders) {
	if (message.getPayload().length == 0) {
		handler.handleFrame(stompHeaders, null);
		return;
	}
	Type type = handler.getPayloadType(stompHeaders);
	Class<?> payloadType = ResolvableType.forType(type).getRawClass();
	Object object = getMessageConverter().fromMessage(message, payloadType);
	if (object == null) {
		throw new MessageConversionException("No suitable converter, payloadType=" + payloadType +
				", handlerType=" + handler.getClass());
	}
	handler.handleFrame(stompHeaders, object);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:DefaultStompSession.java

示例10: resolveArgument

import org.springframework.messaging.converter.MessageConversionException; //导入依赖的package包/类
@Override
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
	Payload ann = parameter.getParameterAnnotation(Payload.class);
	if (ann != null && StringUtils.hasText(ann.expression())) {
		throw new IllegalStateException("@Payload SpEL expressions not supported by this resolver");
	}

	Object payload = message.getPayload();
	if (isEmptyPayload(payload)) {
		if (ann == null || ann.required()) {
			String paramName = getParameterName(parameter);
			BindingResult bindingResult = new BeanPropertyBindingResult(payload, paramName);
			bindingResult.addError(new ObjectError(paramName, "Payload value must not be empty"));
			throw new MethodArgumentNotValidException(message, parameter, bindingResult);
		}
		else {
			return null;
		}
	}

	Class<?> targetClass = parameter.getParameterType();
	if (ClassUtils.isAssignable(targetClass, payload.getClass())) {
		validate(message, parameter, payload);
		return payload;
	}
	else {
		payload = (this.converter instanceof SmartMessageConverter ?
				((SmartMessageConverter) this.converter).fromMessage(message, targetClass, parameter) :
				this.converter.fromMessage(message, targetClass));
		if (payload == null) {
			throw new MessageConversionException(message,
					"No converter found to convert to " + targetClass + ", message=" + message);
		}
		validate(message, parameter, payload);
		return payload;
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:38,代码来源:PayloadArgumentResolver.java

示例11: doConvert

import org.springframework.messaging.converter.MessageConversionException; //导入依赖的package包/类
/**
 * Convert from the given message to the given target class.
 * @param message the message to convert
 * @param targetClass the target class to convert the payload to
 * @return the converted payload of the reply message (never {@code null})
 */
@SuppressWarnings("unchecked")
protected <T> T doConvert(Message<?> message, Class<T> targetClass) {
	MessageConverter messageConverter = getMessageConverter();
	T value = (T) messageConverter.fromMessage(message, targetClass);
	if (value == null) {
		throw new MessageConversionException(message, "Unable to convert payload [" + message.getPayload() +
				"] to type [" + targetClass + "] using converter [" + messageConverter + "]");
	}
	return value;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:AbstractMessageReceivingTemplate.java

示例12: handleMessageFrameWithConversionException

import org.springframework.messaging.converter.MessageConversionException; //导入依赖的package包/类
@Test
public void handleMessageFrameWithConversionException() throws Exception {

	this.session.afterConnected(this.connection);
	assertTrue(this.session.isConnected());

	StompFrameHandler frameHandler = mock(StompFrameHandler.class);
	String destination = "/topic/foo";
	Subscription subscription = this.session.subscribe(destination, frameHandler);

	StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.MESSAGE);
	accessor.setDestination(destination);
	accessor.setSubscriptionId(subscription.getSubscriptionId());
	accessor.setContentType(MimeTypeUtils.APPLICATION_JSON);
	accessor.setMessageId("1");
	accessor.setLeaveMutable(true);
	byte[] payload = "{'foo':'bar'}".getBytes(UTF_8);

	StompHeaders stompHeaders = StompHeaders.readOnlyStompHeaders(accessor.getNativeHeaders());
	when(frameHandler.getPayloadType(stompHeaders)).thenReturn(Map.class);

	this.session.handleMessage(MessageBuilder.createMessage(payload, accessor.getMessageHeaders()));

	verify(frameHandler).getPayloadType(stompHeaders);
	verifyNoMoreInteractions(frameHandler);

	verify(this.sessionHandler).handleException(same(this.session), same(StompCommand.MESSAGE),
			eq(stompHeaders), same(payload), any(MessageConversionException.class));
	verifyNoMoreInteractions(this.sessionHandler);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:31,代码来源:DefaultStompSessionTests.java

示例13: sendWithConversionException

import org.springframework.messaging.converter.MessageConversionException; //导入依赖的package包/类
@Test
public void sendWithConversionException() throws Exception {

	this.session.afterConnected(this.connection);
	assertTrue(this.session.isConnected());

	StompHeaders stompHeaders = new StompHeaders();
	stompHeaders.setDestination("/topic/foo");
	stompHeaders.setContentType(MimeTypeUtils.APPLICATION_JSON);
	String payload = "{'foo':'bar'}";

	this.expected.expect(MessageConversionException.class);
	this.session.send(stompHeaders, payload);
	verifyNoMoreInteractions(this.connection);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:DefaultStompSessionTests.java

示例14: resolveNonConvertibleParam

import org.springframework.messaging.converter.MessageConversionException; //导入依赖的package包/类
@Test
public void resolveNonConvertibleParam() throws Exception {
	Message<?> notEmptyMessage = MessageBuilder.withPayload(123).build();

	thrown.expect(MessageConversionException.class);
	thrown.expectMessage("No converter found");
	this.resolver.resolveArgument(this.paramAnnotatedRequired, notEmptyMessage);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:PayloadArgumentResolverTests.java

示例15: customConversionServiceFailure

import org.springframework.messaging.converter.MessageConversionException; //导入依赖的package包/类
@Test
public void customConversionServiceFailure() throws Exception {
	DefaultMessageHandlerMethodFactory instance = createInstance();
	GenericConversionService conversionService = new GenericConversionService();
	assertFalse("conversion service should fail to convert payload",
			conversionService.canConvert(Integer.class, String.class));
	instance.setConversionService(conversionService);
	instance.afterPropertiesSet();

	InvocableHandlerMethod invocableHandlerMethod =
			createInvocableHandlerMethod(instance, "simpleString", String.class);

	thrown.expect(MessageConversionException.class);
	invocableHandlerMethod.invoke(MessageBuilder.withPayload(123).build());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:DefaultMessageHandlerMethodFactoryTests.java


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