Polishing
This commit is contained in:
parent
48c977afdc
commit
086f1eda71
|
@ -64,6 +64,13 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the configured message channel.
|
||||||
|
*/
|
||||||
|
public MessageChannel getMessageChannel() {
|
||||||
|
return this.messageChannel;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure the prefix to use for destinations targeting a specific user.
|
* Configure the prefix to use for destinations targeting a specific user.
|
||||||
* <p>The default value is "/user/".
|
* <p>The default value is "/user/".
|
||||||
|
@ -75,7 +82,7 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the userDestinationPrefix
|
* Return the configured user destination prefix.
|
||||||
*/
|
*/
|
||||||
public String getUserDestinationPrefix() {
|
public String getUserDestinationPrefix() {
|
||||||
return this.userDestinationPrefix;
|
return this.userDestinationPrefix;
|
||||||
|
@ -98,22 +105,14 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the configured message channel.
|
* Specify the timeout value to use for send operations (in milliseconds).
|
||||||
*/
|
|
||||||
public MessageChannel getMessageChannel() {
|
|
||||||
return this.messageChannel;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Specify the timeout value to use for send operations.
|
|
||||||
* @param sendTimeout the send timeout in milliseconds
|
|
||||||
*/
|
*/
|
||||||
public void setSendTimeout(long sendTimeout) {
|
public void setSendTimeout(long sendTimeout) {
|
||||||
this.sendTimeout = sendTimeout;
|
this.sendTimeout = sendTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the configured send timeout.
|
* Return the configured send timeout (in milliseconds).
|
||||||
*/
|
*/
|
||||||
public long getSendTimeout() {
|
public long getSendTimeout() {
|
||||||
return this.sendTimeout;
|
return this.sendTimeout;
|
||||||
|
@ -194,6 +193,7 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void convertAndSendToUser(String user, String destination, Object payload) throws MessagingException {
|
public void convertAndSendToUser(String user, String destination, Object payload) throws MessagingException {
|
||||||
convertAndSendToUser(user, destination, payload, (MessagePostProcessor) null);
|
convertAndSendToUser(user, destination, payload, (MessagePostProcessor) null);
|
||||||
|
@ -222,6 +222,7 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String
|
||||||
super.convertAndSend(this.userDestinationPrefix + user + destination, payload, headers, postProcessor);
|
super.convertAndSend(this.userDestinationPrefix + user + destination, payload, headers, postProcessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new map and puts the given headers under the key
|
* Creates a new map and puts the given headers under the key
|
||||||
* {@link org.springframework.messaging.support.NativeMessageHeaderAccessor#NATIVE_HEADERS NATIVE_HEADERS NATIVE_HEADERS NATIVE_HEADERS}.
|
* {@link org.springframework.messaging.support.NativeMessageHeaderAccessor#NATIVE_HEADERS NATIVE_HEADERS NATIVE_HEADERS NATIVE_HEADERS}.
|
||||||
|
@ -236,18 +237,15 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate<String
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Map<String, Object> processHeadersToSend(Map<String, Object> headers) {
|
protected Map<String, Object> processHeadersToSend(Map<String, Object> headers) {
|
||||||
|
|
||||||
if (headers == null) {
|
if (headers == null) {
|
||||||
SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE);
|
SimpMessageHeaderAccessor headerAccessor = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE);
|
||||||
initHeaders(headerAccessor);
|
initHeaders(headerAccessor);
|
||||||
headerAccessor.setLeaveMutable(true);
|
headerAccessor.setLeaveMutable(true);
|
||||||
return headerAccessor.getMessageHeaders();
|
return headerAccessor.getMessageHeaders();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (headers.containsKey(NativeMessageHeaderAccessor.NATIVE_HEADERS)) {
|
if (headers.containsKey(NativeMessageHeaderAccessor.NATIVE_HEADERS)) {
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (headers instanceof MessageHeaders) {
|
if (headers instanceof MessageHeaders) {
|
||||||
SimpMessageHeaderAccessor accessor =
|
SimpMessageHeaderAccessor accessor =
|
||||||
MessageHeaderAccessor.getAccessor((MessageHeaders) headers, SimpMessageHeaderAccessor.class);
|
MessageHeaderAccessor.getAccessor((MessageHeaders) headers, SimpMessageHeaderAccessor.class);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2014 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.
|
||||||
|
@ -25,6 +25,7 @@ import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpInputMessage;
|
import org.springframework.http.HttpInputMessage;
|
||||||
import org.springframework.http.HttpOutputMessage;
|
import org.springframework.http.HttpOutputMessage;
|
||||||
|
@ -169,11 +170,12 @@ public abstract class AbstractHttpMessageConverter<T> implements HttpMessageConv
|
||||||
|
|
||||||
final HttpHeaders headers = outputMessage.getHeaders();
|
final HttpHeaders headers = outputMessage.getHeaders();
|
||||||
if (headers.getContentType() == null) {
|
if (headers.getContentType() == null) {
|
||||||
|
MediaType contentTypeToUse = contentType;
|
||||||
if (contentType == null || contentType.isWildcardType() || contentType.isWildcardSubtype()) {
|
if (contentType == null || contentType.isWildcardType() || contentType.isWildcardSubtype()) {
|
||||||
contentType = getDefaultContentType(t);
|
contentTypeToUse = getDefaultContentType(t);
|
||||||
}
|
}
|
||||||
if (contentType != null) {
|
if (contentTypeToUse != null) {
|
||||||
headers.setContentType(contentType);
|
headers.setContentType(contentTypeToUse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (headers.getContentLength() == -1) {
|
if (headers.getContentLength() == -1) {
|
||||||
|
@ -182,10 +184,10 @@ public abstract class AbstractHttpMessageConverter<T> implements HttpMessageConv
|
||||||
headers.setContentLength(contentLength);
|
headers.setContentLength(contentLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outputMessage instanceof StreamingHttpOutputMessage) {
|
if (outputMessage instanceof StreamingHttpOutputMessage) {
|
||||||
StreamingHttpOutputMessage streamingOutputMessage =
|
StreamingHttpOutputMessage streamingOutputMessage =
|
||||||
(StreamingHttpOutputMessage) outputMessage;
|
(StreamingHttpOutputMessage) outputMessage;
|
||||||
|
|
||||||
streamingOutputMessage.setBody(new StreamingHttpOutputMessage.Body() {
|
streamingOutputMessage.setBody(new StreamingHttpOutputMessage.Body() {
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(final OutputStream outputStream) throws IOException {
|
public void writeTo(final OutputStream outputStream) throws IOException {
|
||||||
|
@ -194,7 +196,6 @@ public abstract class AbstractHttpMessageConverter<T> implements HttpMessageConv
|
||||||
public OutputStream getBody() throws IOException {
|
public OutputStream getBody() throws IOException {
|
||||||
return outputStream;
|
return outputStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpHeaders getHeaders() {
|
public HttpHeaders getHeaders() {
|
||||||
return headers;
|
return headers;
|
||||||
|
@ -256,7 +257,7 @@ public abstract class AbstractHttpMessageConverter<T> implements HttpMessageConv
|
||||||
/**
|
/**
|
||||||
* Abstract template method that writes the actual body. Invoked from {@link #write}.
|
* Abstract template method that writes the actual body. Invoked from {@link #write}.
|
||||||
* @param t the object to write to the output message
|
* @param t the object to write to the output message
|
||||||
* @param outputMessage the message to write to
|
* @param outputMessage the HTTP output message to write to
|
||||||
* @throws IOException in case of I/O errors
|
* @throws IOException in case of I/O errors
|
||||||
* @throws HttpMessageNotWritableException in case of conversion errors
|
* @throws HttpMessageNotWritableException in case of conversion errors
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue