Polishing

This commit is contained in:
Juergen Hoeller 2015-07-17 15:25:43 +02:00
parent 7e2a662f63
commit 203f1225c3
6 changed files with 65 additions and 51 deletions

View File

@ -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;
}
}

View File

@ -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<Destination>
* to convert the payload of the message.
* <p>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) {

View File

@ -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())) {

View File

@ -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;
}

View File

@ -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}.
*
* <p>Extra method argument resolvers can be added to customize the method
* signature that can be handled.

View File

@ -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());
}