Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -149,20 +149,6 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the default content type for the payload. Called when
|
||||
* {@link #toMessage(Object, MessageHeaders)} is invoked without message headers or
|
||||
* without a content type header.
|
||||
* <p>By default, this returns the first element of the {@link #getSupportedMimeTypes()
|
||||
* supportedMimeTypes}, if any. Can be overridden in sub-classes.
|
||||
* @param payload the payload being converted to message
|
||||
* @return the content type, or {@code null} if not known
|
||||
*/
|
||||
protected MimeType getDefaultContentType(Object payload) {
|
||||
List<MimeType> mimeTypes = getSupportedMimeTypes();
|
||||
return (!mimeTypes.isEmpty() ? mimeTypes.get(0) : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Object fromMessage(Message<?> message, Class<?> targetClass) {
|
||||
return fromMessage(message, targetClass, null);
|
||||
@@ -176,10 +162,6 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter
|
||||
return convertFromInternal(message, targetClass, conversionHint);
|
||||
}
|
||||
|
||||
protected boolean canConvertFrom(Message<?> message, Class<?> targetClass) {
|
||||
return (supports(targetClass) && supportsMimeType(message.getHeaders()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Message<?> toMessage(Object payload, MessageHeaders headers) {
|
||||
return toMessage(payload, headers, null);
|
||||
@@ -213,6 +195,11 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
protected boolean canConvertFrom(Message<?> message, Class<?> targetClass) {
|
||||
return (supports(targetClass) && supportsMimeType(message.getHeaders()));
|
||||
}
|
||||
|
||||
protected boolean canConvertTo(Object payload, MessageHeaders headers) {
|
||||
Class<?> clazz = (payload != null ? payload.getClass() : null);
|
||||
return (supports(clazz) && supportsMimeType(headers));
|
||||
@@ -238,6 +225,21 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter
|
||||
return (this.contentTypeResolver != null ? this.contentTypeResolver.resolve(headers) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default content type for the payload. Called when
|
||||
* {@link #toMessage(Object, MessageHeaders)} is invoked without
|
||||
* message headers or without a content type header.
|
||||
* <p>By default, this returns the first element of the
|
||||
* {@link #getSupportedMimeTypes() supportedMimeTypes}, if any.
|
||||
* Can be overridden in subclasses.
|
||||
* @param payload the payload being converted to a message
|
||||
* @return the content type, or {@code null} if not known
|
||||
*/
|
||||
protected MimeType getDefaultContentType(Object payload) {
|
||||
List<MimeType> mimeTypes = getSupportedMimeTypes();
|
||||
return (!mimeTypes.isEmpty() ? mimeTypes.get(0) : null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Whether the given class is supported by this converter.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -654,8 +654,10 @@ public class DefaultStompSession implements ConnectionHandlingStompSession {
|
||||
if (conn != null) {
|
||||
conn.send(HEARTBEAT).addCallback(
|
||||
new ListenableFutureCallback<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void result) {
|
||||
}
|
||||
@Override
|
||||
public void onFailure(Throwable ex) {
|
||||
handleFailure(ex);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -52,14 +52,14 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor {
|
||||
|
||||
|
||||
/**
|
||||
* A protected constructor to create new headers.
|
||||
* Protected constructor to create a new instance.
|
||||
*/
|
||||
protected NativeMessageHeaderAccessor() {
|
||||
this((Map<String, List<String>>) null);
|
||||
}
|
||||
|
||||
/**
|
||||
* A protected constructor to create new headers.
|
||||
* Protected constructor to create an instance with the given native headers.
|
||||
* @param nativeHeaders native headers to create the message with (may be {@code null})
|
||||
*/
|
||||
protected NativeMessageHeaderAccessor(Map<String, List<String>> nativeHeaders) {
|
||||
@@ -69,7 +69,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor {
|
||||
}
|
||||
|
||||
/**
|
||||
* A protected constructor accepting the headers of an existing message to copy.
|
||||
* Protected constructor that copies headers from another message.
|
||||
*/
|
||||
protected NativeMessageHeaderAccessor(Message<?> message) {
|
||||
super(message);
|
||||
@@ -84,13 +84,17 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Subclasses can use this method to access the "native" headers sub-map.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, List<String>> getNativeHeaders() {
|
||||
return (Map<String, List<String>>) getHeader(NATIVE_HEADERS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a copy of the native header values or an empty map.
|
||||
* Return a copy of the native headers sub-map, or an empty map.
|
||||
*/
|
||||
public Map<String, List<String>> toNativeHeaderMap() {
|
||||
Map<String, List<String>> map = getNativeHeaders();
|
||||
@@ -112,6 +116,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor {
|
||||
|
||||
/**
|
||||
* Whether the native header map contains the give header name.
|
||||
* @param headerName the name of the header
|
||||
*/
|
||||
public boolean containsNativeHeader(String headerName) {
|
||||
Map<String, List<String>> map = getNativeHeaders();
|
||||
@@ -119,7 +124,9 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all values for the specified native header or {@code null}.
|
||||
* Return all values for the specified native header, if present.
|
||||
* @param headerName the name of the header
|
||||
* @return the associated values, or {@code null} if none
|
||||
*/
|
||||
public List<String> getNativeHeader(String headerName) {
|
||||
Map<String, List<String>> map = getNativeHeaders();
|
||||
@@ -127,13 +134,15 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the first value for the specified native header of {@code null}.
|
||||
* Return the first value for the specified native header, if present.
|
||||
* @param headerName the name of the header
|
||||
* @return the associated value, or {@code null} if none
|
||||
*/
|
||||
public String getFirstNativeHeader(String headerName) {
|
||||
Map<String, List<String>> map = getNativeHeaders();
|
||||
if (map != null) {
|
||||
List<String> values = map.get(headerName);
|
||||
if (values != null) {
|
||||
if (!CollectionUtils.isEmpty(values)) {
|
||||
return values.get(0);
|
||||
}
|
||||
}
|
||||
@@ -142,6 +151,8 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor {
|
||||
|
||||
/**
|
||||
* Set the specified native header value replacing existing values.
|
||||
* <p>In order for this to work, the accessor must be {@link #isMutable()
|
||||
* mutable}. See {@link MessageHeaderAccessor} for details.
|
||||
*/
|
||||
public void setNativeHeader(String name, String value) {
|
||||
Assert.state(isMutable(), "Already immutable");
|
||||
@@ -167,6 +178,10 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor {
|
||||
|
||||
/**
|
||||
* Add the specified native header value to existing values.
|
||||
* <p>In order for this to work, the accessor must be {@link #isMutable()
|
||||
* mutable}. See {@link MessageHeaderAccessor} for details.
|
||||
* @param name the name of the header
|
||||
* @param value the header value to set
|
||||
*/
|
||||
public void addNativeHeader(String name, String value) {
|
||||
Assert.state(isMutable(), "Already immutable");
|
||||
@@ -187,6 +202,10 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor {
|
||||
setModified(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the specified native headers to existing values.
|
||||
* @param headers the headers to set
|
||||
*/
|
||||
public void addNativeHeaders(MultiValueMap<String, String> headers) {
|
||||
if (headers == null) {
|
||||
return;
|
||||
@@ -198,21 +217,36 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor {
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> removeNativeHeader(String name) {
|
||||
/**
|
||||
* Remove the specified native header value replacing existing values.
|
||||
* <p>In order for this to work, the accessor must be {@link #isMutable()
|
||||
* mutable}. See {@link MessageHeaderAccessor} for details.
|
||||
* @param headerName the name of the header
|
||||
* @return the associated values, or {@code null} if the header was not present
|
||||
*/
|
||||
public List<String> removeNativeHeader(String headerName) {
|
||||
Assert.state(isMutable(), "Already immutable");
|
||||
Map<String, List<String>> nativeHeaders = getNativeHeaders();
|
||||
if (nativeHeaders == null) {
|
||||
if (CollectionUtils.isEmpty(nativeHeaders)) {
|
||||
return null;
|
||||
}
|
||||
return nativeHeaders.remove(name);
|
||||
return nativeHeaders.remove(headerName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the first value for the specified native header,
|
||||
* or {@code null} if none.
|
||||
* @param headerName the name of the header
|
||||
* @param headers the headers map to introspect
|
||||
* @return the associated value, or {@code null} if none
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static String getFirstNativeHeader(String headerName, Map<String, Object> headers) {
|
||||
Map<String, List<String>> map = (Map<String, List<String>>) headers.get(NATIVE_HEADERS);
|
||||
if (map != null) {
|
||||
List<String> values = map.get(headerName);
|
||||
if (values != null) {
|
||||
if (!CollectionUtils.isEmpty(values)) {
|
||||
return values.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user