diff --git a/spring-expression/src/main/java/org/springframework/expression/ExpressionException.java b/spring-expression/src/main/java/org/springframework/expression/ExpressionException.java index edebcb5949..767f5cee3b 100644 --- a/spring-expression/src/main/java/org/springframework/expression/ExpressionException.java +++ b/spring-expression/src/main/java/org/springframework/expression/ExpressionException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ package org.springframework.expression; /** - * Super class for exceptions that can occur whilst processing expressions + * Super class for exceptions that can occur whilst processing expressions. * * @author Andy Clement * @since 3.0 @@ -27,11 +27,11 @@ public class ExpressionException extends RuntimeException { protected String expressionString; - protected int position; // -1 if not known - but should be known in all reasonable cases + protected int position; // -1 if not known - but should be known in all reasonable cases /** - * Creates a new expression exception. + * Construct a new expression exception. * @param expressionString the expression string * @param message a descriptive message */ @@ -42,7 +42,7 @@ public class ExpressionException extends RuntimeException { } /** - * Creates a new expression exception. + * Construct a new expression exception. * @param expressionString the expression string * @param position the position in the expression string where the problem occurred * @param message a descriptive message @@ -54,7 +54,7 @@ public class ExpressionException extends RuntimeException { } /** - * Creates a new expression exception. + * Construct a new expression exception. * @param position the position in the expression string where the problem occurred * @param message a descriptive message */ @@ -64,7 +64,7 @@ public class ExpressionException extends RuntimeException { } /** - * Creates a new expression exception. + * Construct a new expression exception. * @param position the position in the expression string where the problem occurred * @param message a descriptive message * @param cause the underlying cause of this exception @@ -75,21 +75,40 @@ public class ExpressionException extends RuntimeException { } /** - * Creates a new expression exception. + * Construct a new expression exception. * @param message a descriptive message */ public ExpressionException(String message) { super(message); } + /** + * Construct a new expression exception. + * @param message a descriptive message + * @param cause the underlying cause of this exception + */ public ExpressionException(String message, Throwable cause) { super(message,cause); } /** - * Return the exception message. Since Spring 4.0 this method returns the same - * result as {@link #toDetailedString()}. + * Return the expression string. + */ + public final String getExpressionString() { + return this.expressionString; + } + + /** + * Return the position in the expression string where the problem occurred. + */ + public final int getPosition() { + return this.position; + } + + /** + * Return the exception message. Since Spring 4.0 this method returns the + * same result as {@link #toDetailedString()}. * @see java.lang.Throwable#getMessage() */ @Override @@ -98,35 +117,34 @@ public class ExpressionException extends RuntimeException { } /** - * Return the exception simple message without including the expression that caused - * the failure. + * Return a detailed description of this exception, including the expression + * String and position (if available) as well as the actual exception message. + */ + public String toDetailedString() { + if (this.expressionString != null) { + StringBuilder output = new StringBuilder(); + output.append("Expression '"); + output.append(this.expressionString); + output.append("'"); + if (this.position != -1) { + output.append(" @ "); + output.append(this.position); + } + output.append(": "); + output.append(getSimpleMessage()); + return output.toString(); + } + else { + return getSimpleMessage(); + } + } + + /** + * Return the exception simple message without including the expression + * that caused the failure. */ public String getSimpleMessage() { return super.getMessage(); } - public String toDetailedString() { - StringBuilder output = new StringBuilder(); - if (this.expressionString!=null) { - output.append("Expression '"); - output.append(this.expressionString); - output.append("'"); - if (this.position!=-1) { - output.append(" @ "); - output.append(this.position); - } - output.append(": "); - } - output.append(getSimpleMessage()); - return output.toString(); - } - - public final String getExpressionString() { - return this.expressionString; - } - - public final int getPosition() { - return this.position; - } - } diff --git a/spring-jms/src/main/java/org/springframework/jms/core/JmsMessagingTemplate.java b/spring-jms/src/main/java/org/springframework/jms/core/JmsMessagingTemplate.java index 467c0812e5..7a22c041a1 100644 --- a/spring-jms/src/main/java/org/springframework/jms/core/JmsMessagingTemplate.java +++ b/spring-jms/src/main/java/org/springframework/jms/core/JmsMessagingTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -120,7 +120,7 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate * to convert the payload of the message. *

Consider configuring a {@link MessagingMessageConverter} with a different * {@link MessagingMessageConverter#setPayloadConverter(MessageConverter) payload converter} - * for more advanced scenario. + * for more advanced scenarios. * @see org.springframework.jms.support.converter.MessagingMessageConverter */ public void setJmsMessageConverter(MessageConverter jmsMessageConverter) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/AbstractMessageConverter.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/AbstractMessageConverter.java index 69cc344b8c..e70394e14d 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/converter/AbstractMessageConverter.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/AbstractMessageConverter.java @@ -49,7 +49,6 @@ public abstract class AbstractMessageConverter implements MessageConverter { * ({@link MethodParameter} instance) about the origin of the payload (for * {@link #toMessage(Object, MessageHeaders)}) or about the target of the payload * ({@link #fromMessage(Message, Class)}). - * * @since 4.2 */ public static final String METHOD_PARAMETER_HINT_HEADER = "methodParameterHint"; @@ -221,12 +220,7 @@ public abstract class AbstractMessageConverter implements MessageConverter { } MimeType mimeType = getMimeType(headers); if (mimeType == null) { - if (isStrictContentTypeMatch()) { - return false; - } - else { - return true; - } + return !isStrictContentTypeMatch(); } for (MimeType current : getSupportedMimeTypes()) { if (current.getType().equals(mimeType.getType()) && current.getSubtype().equals(mimeType.getSubtype())) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/MappingJackson2MessageConverter.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/MappingJackson2MessageConverter.java index 5a0e9e02fd..426fcb6d33 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/converter/MappingJackson2MessageConverter.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/MappingJackson2MessageConverter.java @@ -245,8 +245,8 @@ public class MappingJackson2MessageConverter extends AbstractMessageConverter { } private Class getSerializationView(MessageHeaders headers) { - MethodParameter returnType = (headers == null ? null : - (MethodParameter)headers.get(METHOD_PARAMETER_HINT_HEADER)); + MethodParameter returnType = (headers != null ? + (MethodParameter) headers.get(METHOD_PARAMETER_HINT_HEADER) : null); if (returnType == null) { return null; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/DefaultMessageHandlerMethodFactory.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/DefaultMessageHandlerMethodFactory.java index a7c2e989c0..6ff383b235 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/DefaultMessageHandlerMethodFactory.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/DefaultMessageHandlerMethodFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,8 +37,8 @@ import org.springframework.validation.Validator; * The default {@link MessageHandlerMethodFactory} implementation creating an * {@link InvocableHandlerMethod} with the necessary * {@link HandlerMethodArgumentResolver} instances to detect and process - * most of the use cases defined by - * {@link org.springframework.messaging.handler.annotation.MessageMapping MessageMapping} + * most of the use cases defined by + * {@link org.springframework.messaging.handler.annotation.MessageMapping MessageMapping}. * *

Extra method argument resolvers can be added to customize the method * signature that can be handled. diff --git a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java index 1c2fd4a69a..3cb8779c49 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java @@ -156,12 +156,14 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat this.messageConverters.add(new AtomFeedHttpMessageConverter()); this.messageConverters.add(new RssChannelHttpMessageConverter()); } + if (jackson2XmlPresent) { - messageConverters.add(new MappingJackson2XmlHttpMessageConverter()); + this.messageConverters.add(new MappingJackson2XmlHttpMessageConverter()); } else if (jaxb2Present) { this.messageConverters.add(new Jaxb2RootElementHttpMessageConverter()); } + if (jackson2Present) { this.messageConverters.add(new MappingJackson2HttpMessageConverter()); }