Java Code Examples for org.springframework.messaging.handler.annotation.support.MethodArgumentTypeMismatchException

Following code examples demonstrate how to use org.springframework.messaging.handler.annotation.support.MethodArgumentTypeMismatchExceptionfrom spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.messaging.handler.annotation.support.MethodArgumentTypeMismatchExceptionand various code implementation of this class.

    public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {

        Class<?> targetMessageType = parameter.getParameterType();
        Class<?> targetPayloadType = getPayloadType(parameter);

        if (!targetMessageType.isAssignableFrom(message.getClass())) {
            String actual = ClassUtils.getQualifiedName(message.getClass());
            String expected = ClassUtils.getQualifiedName(targetMessageType);
            throw new MethodArgumentTypeMismatchException(message, parameter, "The actual message type " +
                    "[" + actual + "] does not match the expected type [" + expected + "]");
        }

        Object payload = message.getPayload();
        if (payload == null || targetPayloadType.isInstance(payload)) {
            return message;
        }

        if (isEmptyPayload(payload)) {
            String actual = ClassUtils.getQualifiedName(payload.getClass());
            String expected = ClassUtils.getQualifiedName(targetPayloadType);
            throw new MessageConversionException(message, "Cannot convert from the " +
                    "expected payload type [" + expected + "] to the " +
                    "actual payload type [" + actual + "] when the payload is empty.");
        }

        payload = convertPayload(message, parameter, targetPayloadType);
        return MessageBuilder.createMessage(payload, message.getHeaders());
    } 


            while (true) {
                ListenerExecutionFailedException e = getException(lefe.getCause(), ListenerExecutionFailedException.class);
                if (e == null) {
                    break;
                }
                lefe = e;
            } 

        private boolean isCauseFatal(Throwable cause) {
            return cause instanceof MessageConversionException
                    || cause instanceof org.springframework.messaging.converter.MessageConversionException
                    || cause instanceof MethodArgumentNotValidException
                    || cause instanceof MethodArgumentTypeMismatchException
                    || cause instanceof NoSuchMethodException
                    || cause instanceof ClassCastException
                    || isUserCauseFatal(cause);
        } 

	public static boolean causeIsFatal(Throwable cause) {
		return cause instanceof MessageConversionException
				|| cause instanceof org.springframework.messaging.converter.MessageConversionException
				|| cause instanceof MethodArgumentNotValidException
				|| cause instanceof MethodArgumentTypeMismatchException
				|| cause instanceof NullPointerException;
	} 

Advertisement
Javadoc
Exception that indicates that a method argument has not the expected type. @author Stephane Nicoll @

since 4.0.3

Read More
Advertisement