Browse Source

Polishing

pull/842/merge
Juergen Hoeller 9 years ago
parent
commit
965fca808a
  1. 2
      spring-core/src/main/java/org/springframework/core/MethodParameter.java
  2. 27
      spring-jms/src/main/java/org/springframework/jms/listener/adapter/AbstractAdaptableMessageListener.java
  3. 8
      spring-jms/src/main/java/org/springframework/jms/listener/adapter/MessagingMessageListenerAdapter.java
  4. 17
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/JsonViewRequestBodyAdvice.java
  5. 15
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/JsonViewResponseBodyAdvice.java
  6. 1
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/InfoReceiver.java
  7. 5
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/Transport.java
  8. 1
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/XhrTransport.java

2
spring-core/src/main/java/org/springframework/core/MethodParameter.java

@ -207,7 +207,7 @@ public class MethodParameter { @@ -207,7 +207,7 @@ public class MethodParameter {
/**
* Return the index of the method/constructor parameter.
* @return the parameter index (never negative)
* @return the parameter index (-1 in case of the return type)
*/
public int getParameterIndex() {
return this.parameterIndex;

27
spring-jms/src/main/java/org/springframework/jms/listener/adapter/AbstractAdaptableMessageListener.java

@ -40,8 +40,8 @@ import org.springframework.jms.support.destination.DynamicDestinationResolver; @@ -40,8 +40,8 @@ import org.springframework.jms.support.destination.DynamicDestinationResolver;
import org.springframework.util.Assert;
/**
* An abstract {@link MessageListener} adapter providing the necessary infrastructure
* to extract the payload of a {@link Message}
* An abstract JMS {@link MessageListener} adapter providing the necessary
* infrastructure to extract the payload of a JMS {@link Message}.
*
* @author Juergen Hoeller
* @author Stephane Nicoll
@ -217,7 +217,7 @@ public abstract class AbstractAdaptableMessageListener @@ -217,7 +217,7 @@ public abstract class AbstractAdaptableMessageListener
return message;
}
catch (JMSException ex) {
throw new MessageConversionException("Could not unmarshal message", ex);
throw new MessageConversionException("Could not convert JMS message", ex);
}
}
@ -246,10 +246,12 @@ public abstract class AbstractAdaptableMessageListener @@ -246,10 +246,12 @@ public abstract class AbstractAdaptableMessageListener
sendResponse(session, destination, response);
}
catch (Exception ex) {
throw new ReplyFailureException("Failed to send reply with payload '" + result + "'", ex);
throw new ReplyFailureException("Failed to send reply with payload [" + result + "]", ex);
}
}
else {
// No JMS Session available
if (logger.isWarnEnabled()) {
logger.warn("Listener method returned result [" + result +
"]: not generating response message for it because of no JMS Session given");
@ -266,26 +268,22 @@ public abstract class AbstractAdaptableMessageListener @@ -266,26 +268,22 @@ public abstract class AbstractAdaptableMessageListener
* @see #setMessageConverter
*/
protected Message buildMessage(Session session, Object result) throws JMSException {
Object content = (result instanceof JmsResponse
? ((JmsResponse<?>) result).getResponse() : result);
MessageConverter converter = getMessageConverter();
if (converter != null) {
Object content = (result instanceof JmsResponse ? ((JmsResponse<?>) result).getResponse() : result);
if (content instanceof org.springframework.messaging.Message) {
return this.messagingMessageConverter.toMessage(content, session);
}
else {
MessageConverter converter = getMessageConverter();
if (converter != null) {
return converter.toMessage(content, session);
}
}
else {
if (!(content instanceof Message)) {
throw new MessageConversionException(
"No MessageConverter specified - cannot handle message [" + content + "]");
}
return (Message) content;
}
}
/**
* Post-process the given response message before it will be sent.
@ -307,6 +305,7 @@ public abstract class AbstractAdaptableMessageListener @@ -307,6 +305,7 @@ public abstract class AbstractAdaptableMessageListener
private Destination getResponseDestination(Message request, Message response, Session session, Object result)
throws JMSException {
if (result instanceof JmsResponse) {
JmsResponse<?> jmsResponse = (JmsResponse) result;
Destination destination = jmsResponse.resolveDestination(getDestinationResolver(), session);
@ -418,7 +417,7 @@ public abstract class AbstractAdaptableMessageListener @@ -418,7 +417,7 @@ public abstract class AbstractAdaptableMessageListener
if (converter != null) {
return converter.toMessage(payload, session);
}
throw new IllegalStateException("No message converter, cannot handle '" + payload + "'");
throw new IllegalStateException("No message converter - cannot handle [" + payload + "]");
}
}

8
spring-jms/src/main/java/org/springframework/jms/listener/adapter/MessagingMessageListenerAdapter.java

@ -1,5 +1,5 @@ @@ -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.
@ -77,7 +77,7 @@ public class MessagingMessageListenerAdapter extends AbstractAdaptableMessageLis @@ -77,7 +77,7 @@ public class MessagingMessageListenerAdapter extends AbstractAdaptableMessageLis
return (Message<?>) getMessagingMessageConverter().fromMessage(jmsMessage);
}
catch (JMSException ex) {
throw new MessageConversionException("Could not unmarshal message", ex);
throw new MessageConversionException("Could not convert JMS message", ex);
}
}
@ -90,8 +90,8 @@ public class MessagingMessageListenerAdapter extends AbstractAdaptableMessageLis @@ -90,8 +90,8 @@ public class MessagingMessageListenerAdapter extends AbstractAdaptableMessageLis
return this.handlerMethod.invoke(message, jmsMessage, session);
}
catch (MessagingException ex) {
throw new ListenerExecutionFailedException(createMessagingErrorMessage("Listener method could not " +
"be invoked with the incoming message"), ex);
throw new ListenerExecutionFailedException(
createMessagingErrorMessage("Listener method could not be invoked with incoming message"), ex);
}
catch (Exception ex) {
throw new ListenerExecutionFailedException("Listener method '" +

17
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/JsonViewRequestBodyAdvice.java

@ -28,22 +28,23 @@ import org.springframework.http.converter.json.AbstractJackson2HttpMessageConver @@ -28,22 +28,23 @@ import org.springframework.http.converter.json.AbstractJackson2HttpMessageConver
import org.springframework.http.converter.json.MappingJacksonInputMessage;
/**
* A {@code RequestBodyAdvice} implementation that adds support for
* Jackson's {@code @JsonView} annotation declared on a Spring MVC
* {@code @HttpEntity} and {@code @RequestBody} method parameters.
* A {@link RequestBodyAdvice} implementation that adds support for Jackson's
* {@code @JsonView} annotation declared on a Spring MVC {@code @HttpEntity}
* or {@code @RequestBody} method parameter.
*
* <p>The deserialization view specified in the annotation will be passed in to
* the {@code MappingJackson2HttpMessageConverter} which will then use it to
* deserialize the request body with.
* <p>The deserialization view specified in the annotation will be passed in to the
* {@link org.springframework.http.converter.json.MappingJackson2HttpMessageConverter}
* which will then use it to deserialize the request body with.
*
* <p>Note that despite {@code @JsonView} allowing for more than one class to
* be specified, the use for a request body advice is only supported with
* exactly one class argument. Consider the use of a composite interface.
*
* <p>Jackson 2.5.0 or later is required.
* <p>Jackson 2.5 or later is required for parameter-level use of {@code @JsonView}.
*
* @author Sebastien Deleuze
* @since 4.2
* @see com.fasterxml.jackson.annotation.JsonView
* @see com.fasterxml.jackson.databind.ObjectMapper#readerWithView(Class)
*/
public class JsonViewRequestBodyAdvice extends RequestBodyAdviceAdapter {
@ -51,6 +52,7 @@ public class JsonViewRequestBodyAdvice extends RequestBodyAdviceAdapter { @@ -51,6 +52,7 @@ public class JsonViewRequestBodyAdvice extends RequestBodyAdviceAdapter {
@Override
public boolean supports(MethodParameter methodParameter, Type targetType,
Class<? extends HttpMessageConverter<?>> converterType) {
return (AbstractJackson2HttpMessageConverter.class.isAssignableFrom(converterType) &&
methodParameter.getParameterAnnotation(JsonView.class) != null);
}
@ -58,6 +60,7 @@ public class JsonViewRequestBodyAdvice extends RequestBodyAdviceAdapter { @@ -58,6 +60,7 @@ public class JsonViewRequestBodyAdvice extends RequestBodyAdviceAdapter {
@Override
public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter methodParameter,
Type targetType, Class<? extends HttpMessageConverter<?>> selectedConverterType) throws IOException {
JsonView annotation = methodParameter.getParameterAnnotation(JsonView.class);
Class<?>[] classes = annotation.value();
if (classes.length != 1) {

15
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/JsonViewResponseBodyAdvice.java

@ -1,5 +1,5 @@ @@ -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.
@ -26,13 +26,13 @@ import org.springframework.http.server.ServerHttpRequest; @@ -26,13 +26,13 @@ import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
/**
* A {@code ResponseBodyAdvice} implementation that adds support for
* Jackson's {@code @JsonView} annotation declared on a Spring MVC
* {@code @RequestMapping} or {@code @ExceptionHandler} method.
* A {@link ResponseBodyAdvice} implementation that adds support for Jackson's
* {@code @JsonView} annotation declared on a Spring MVC {@code @RequestMapping}
* or {@code @ExceptionHandler} method.
*
* <p>The serialization view specified in the annotation will be passed in to
* the {@code MappingJackson2HttpMessageConverter} which will then use it to
* serialize the response body with.
* <p>The serialization view specified in the annotation will be passed in to the
* {@link org.springframework.http.converter.json.MappingJackson2HttpMessageConverter}
* which will then use it to serialize the response body with.
*
* <p>Note that despite {@code @JsonView} allowing for more than one class to
* be specified, the use for a response body advice is only supported with
@ -40,6 +40,7 @@ import org.springframework.http.server.ServerHttpResponse; @@ -40,6 +40,7 @@ import org.springframework.http.server.ServerHttpResponse;
*
* @author Rossen Stoyanchev
* @since 4.1
* @see com.fasterxml.jackson.annotation.JsonView
* @see com.fasterxml.jackson.databind.ObjectMapper#writerWithView(Class)
*/
public class JsonViewResponseBodyAdvice extends AbstractMappingJacksonResponseBodyAdvice {

1
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/InfoReceiver.java

@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.socket.sockjs.client;
import java.net.URI;

5
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/Transport.java

@ -1,5 +1,5 @@ @@ -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.
@ -13,8 +13,8 @@ @@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.socket.sockjs.client;
package org.springframework.web.socket.sockjs.client;
import java.util.List;
@ -40,7 +40,6 @@ public interface Transport { @@ -40,7 +40,6 @@ public interface Transport {
/**
* Connect the transport.
*
* @param request the transport request.
* @param webSocketHandler the application handler to delegate lifecycle events to.
* @return a future to indicate success or failure to connect.

1
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/XhrTransport.java

@ -13,6 +13,7 @@ @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.socket.sockjs.client;
import java.net.URI;

Loading…
Cancel
Save