Polishing
This commit is contained in:
parent
8196af4bc5
commit
f06581f5b8
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -31,11 +31,11 @@ import org.springframework.messaging.MessageHeaders;
|
||||||
public interface MessageConverter {
|
public interface MessageConverter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the payload of a {@link Message} from serialized form to a typed Object of
|
* Convert the payload of a {@link Message} from a serialized form to a typed Object
|
||||||
* the specified target class. The {@link MessageHeaders#CONTENT_TYPE} header should
|
* of the specified target class. The {@link MessageHeaders#CONTENT_TYPE} header
|
||||||
* indicate the MIME type to convert from.
|
* should indicate the MIME type to convert from.
|
||||||
* <p>If the converter does not support the specified media type or cannot perform the
|
* <p>If the converter does not support the specified media type or cannot perform
|
||||||
* conversion, it should return {@code null}.
|
* the conversion, it should return {@code null}.
|
||||||
* @param message the input message
|
* @param message the input message
|
||||||
* @param targetClass the target class for the conversion
|
* @param targetClass the target class for the conversion
|
||||||
* @return the result of the conversion, or {@code null} if the converter cannot
|
* @return the result of the conversion, or {@code null} if the converter cannot
|
||||||
|
|
@ -47,15 +47,15 @@ public interface MessageConverter {
|
||||||
* Create a {@link Message} whose payload is the result of converting the given
|
* Create a {@link Message} whose payload is the result of converting the given
|
||||||
* payload Object to serialized form. The optional {@link MessageHeaders} parameter
|
* payload Object to serialized form. The optional {@link MessageHeaders} parameter
|
||||||
* may contain a {@link MessageHeaders#CONTENT_TYPE} header to specify the target
|
* may contain a {@link MessageHeaders#CONTENT_TYPE} header to specify the target
|
||||||
* media type for the conversion and it may contain additional headers to be added to
|
* media type for the conversion and it may contain additional headers to be added
|
||||||
* the message.
|
* to the message.
|
||||||
* <p>If the converter does not support the specified media type or cannot perform the
|
* <p>If the converter does not support the specified media type or cannot perform
|
||||||
* conversion, it should return {@code null}.
|
* the conversion, it should return {@code null}.
|
||||||
* @param payload the Object to convert
|
* @param payload the Object to convert
|
||||||
* @param header optional headers for the message, may be {@code null}
|
* @param headers optional headers for the message (may be {@code null})
|
||||||
* @return the new message or {@code null} if the converter does not support the
|
* @return the new message, or {@code null} if the converter does not support the
|
||||||
* Object type or the target media type
|
* Object type or the target media type
|
||||||
*/
|
*/
|
||||||
Message<?> toMessage(Object payload, MessageHeaders header);
|
Message<?> toMessage(Object payload, MessageHeaders headers);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -46,7 +46,6 @@ public interface SimpMessageSendingOperations extends MessageSendingOperations<S
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a message to the given user.
|
* Send a message to the given user.
|
||||||
*
|
|
||||||
* @param user the user that should receive the message.
|
* @param user the user that should receive the message.
|
||||||
* @param destination the destination to send the message to.
|
* @param destination the destination to send the message to.
|
||||||
* @param payload the payload to send
|
* @param payload the payload to send
|
||||||
|
|
@ -55,13 +54,11 @@ public interface SimpMessageSendingOperations extends MessageSendingOperations<S
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a message to the given user.
|
* Send a message to the given user.
|
||||||
*
|
|
||||||
* <p>By default headers are interpreted as native headers (e.g. STOMP) and
|
* <p>By default headers are interpreted as native headers (e.g. STOMP) and
|
||||||
* are saved under a special key in the resulting Spring
|
* are saved under a special key in the resulting Spring
|
||||||
* {@link org.springframework.messaging.Message Message}. In effect when the
|
* {@link org.springframework.messaging.Message Message}. In effect when the
|
||||||
* message leaves the application, the provided headers are included with it
|
* message leaves the application, the provided headers are included with it
|
||||||
* and delivered to the destination (e.g. the STOMP client or broker).
|
* and delivered to the destination (e.g. the STOMP client or broker).
|
||||||
*
|
|
||||||
* <p>If the map already contains the key
|
* <p>If the map already contains the key
|
||||||
* {@link org.springframework.messaging.support.NativeMessageHeaderAccessor#NATIVE_HEADERS "nativeHeaders"}
|
* {@link org.springframework.messaging.support.NativeMessageHeaderAccessor#NATIVE_HEADERS "nativeHeaders"}
|
||||||
* or was prepared with
|
* or was prepared with
|
||||||
|
|
@ -69,36 +66,31 @@ public interface SimpMessageSendingOperations extends MessageSendingOperations<S
|
||||||
* then the headers are used directly. A common expected case is providing a
|
* then the headers are used directly. A common expected case is providing a
|
||||||
* content type (to influence the message conversion) and native headers.
|
* content type (to influence the message conversion) and native headers.
|
||||||
* This may be done as follows:
|
* This may be done as follows:
|
||||||
*
|
|
||||||
* <pre class="code">
|
* <pre class="code">
|
||||||
* SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
|
* SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
|
||||||
* accessor.setContentType(MimeTypeUtils.TEXT_PLAIN);
|
* accessor.setContentType(MimeTypeUtils.TEXT_PLAIN);
|
||||||
* accessor.setNativeHeader("foo", "bar");
|
* accessor.setNativeHeader("foo", "bar");
|
||||||
* accessor.setLeaveMutable(true);
|
* accessor.setLeaveMutable(true);
|
||||||
* MessageHeaders headers = accessor.getMessageHeaders();
|
* MessageHeaders headers = accessor.getMessageHeaders();
|
||||||
*
|
|
||||||
* messagingTemplate.convertAndSendToUser(user, destination, payload, headers);
|
* messagingTemplate.convertAndSendToUser(user, destination, payload, headers);
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
|
||||||
* <p><strong>Note:</strong> if the {@code MessageHeaders} are mutable as in
|
* <p><strong>Note:</strong> if the {@code MessageHeaders} are mutable as in
|
||||||
* the above example, implementations of this interface should take notice and
|
* the above example, implementations of this interface should take notice and
|
||||||
* update the headers in the same instance (rather than copy or re-create it)
|
* update the headers in the same instance (rather than copy or re-create it)
|
||||||
* and then set it immutable before sending the final message.
|
* and then set it immutable before sending the final message.
|
||||||
*
|
* @param user the user that should receive the message (must not be {@code null})
|
||||||
* @param user the user that should receive the message, must not be {@code null}
|
* @param destination the destination to send the message to (must not be {@code null})
|
||||||
* @param destination the destination to send the message to, must not be {@code null}
|
* @param payload the payload to send (may be {@code null})
|
||||||
* @param payload the payload to send, may be {@code null}
|
* @param headers the message headers (may be {@code null})
|
||||||
* @param headers the message headers, may be {@code null}
|
|
||||||
*/
|
*/
|
||||||
void convertAndSendToUser(String user, String destination, Object payload, Map<String, Object> headers)
|
void convertAndSendToUser(String user, String destination, Object payload, Map<String, Object> headers)
|
||||||
throws MessagingException;
|
throws MessagingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a message to the given user.
|
* Send a message to the given user.
|
||||||
*
|
* @param user the user that should receive the message (must not be {@code null})
|
||||||
* @param user the user that should receive the message, must not be {@code null}
|
* @param destination the destination to send the message to (must not be {@code null})
|
||||||
* @param destination the destination to send the message to, must not be {@code null}
|
* @param payload the payload to send (may be {@code null})
|
||||||
* @param payload the payload to send, may be {@code null}
|
|
||||||
* @param postProcessor a postProcessor to post-process or modify the created message
|
* @param postProcessor a postProcessor to post-process or modify the created message
|
||||||
*/
|
*/
|
||||||
void convertAndSendToUser(String user, String destination, Object payload,
|
void convertAndSendToUser(String user, String destination, Object payload,
|
||||||
|
|
@ -106,12 +98,10 @@ public interface SimpMessageSendingOperations extends MessageSendingOperations<S
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a message to the given user.
|
* Send a message to the given user.
|
||||||
*
|
|
||||||
* <p>See {@link #convertAndSend(Object, Object, java.util.Map)} for important
|
* <p>See {@link #convertAndSend(Object, Object, java.util.Map)} for important
|
||||||
* notes regarding the input headers.
|
* notes regarding the input headers.
|
||||||
*
|
* @param user the user that should receive the message
|
||||||
* @param user the user that should receive the message.
|
* @param destination the destination to send the message to
|
||||||
* @param destination the destination to send the message to.
|
|
||||||
* @param payload the payload to send
|
* @param payload the payload to send
|
||||||
* @param headers the message headers
|
* @param headers the message headers
|
||||||
* @param postProcessor a postProcessor to post-process or modify the created message
|
* @param postProcessor a postProcessor to post-process or modify the created message
|
||||||
|
|
|
||||||
|
|
@ -515,7 +515,7 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a rae TransactionStatus instance for the given arguments.
|
* Create a TransactionStatus instance for the given arguments.
|
||||||
*/
|
*/
|
||||||
protected DefaultTransactionStatus newTransactionStatus(
|
protected DefaultTransactionStatus newTransactionStatus(
|
||||||
TransactionDefinition definition, Object transaction, boolean newTransaction,
|
TransactionDefinition definition, Object transaction, boolean newTransaction,
|
||||||
|
|
|
||||||
|
|
@ -212,7 +212,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
|
||||||
private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) {
|
private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) {
|
||||||
try {
|
try {
|
||||||
if (inputMessage instanceof MappingJacksonInputMessage) {
|
if (inputMessage instanceof MappingJacksonInputMessage) {
|
||||||
Class<?> deserializationView = ((MappingJacksonInputMessage)inputMessage).getDeserializationView();
|
Class<?> deserializationView = ((MappingJacksonInputMessage) inputMessage).getDeserializationView();
|
||||||
if (deserializationView != null) {
|
if (deserializationView != null) {
|
||||||
return this.objectMapper.readerWithView(deserializationView)
|
return this.objectMapper.readerWithView(deserializationView)
|
||||||
.withType(javaType).readValue(inputMessage.getBody());
|
.withType(javaType).readValue(inputMessage.getBody());
|
||||||
|
|
|
||||||
|
|
@ -49,14 +49,6 @@ public class MappingJacksonInputMessage implements HttpInputMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setDeserializationView(Class<?> deserializationView) {
|
|
||||||
this.deserializationView = deserializationView;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class<?> getDeserializationView() {
|
|
||||||
return deserializationView;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream getBody() throws IOException {
|
public InputStream getBody() throws IOException {
|
||||||
return this.body;
|
return this.body;
|
||||||
|
|
@ -67,4 +59,12 @@ public class MappingJacksonInputMessage implements HttpInputMessage {
|
||||||
return this.headers;
|
return this.headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDeserializationView(Class<?> deserializationView) {
|
||||||
|
this.deserializationView = deserializationView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<?> getDeserializationView() {
|
||||||
|
return this.deserializationView;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue