Class StompHeaders
- java.lang.Object
- org.springframework.messaging.simp.stomp.StompHeaders
- All Implemented Interfaces:
Serializable,Map<String,List<String>>,MultiValueMap<String,String>
public class StompHeaders extends Object implements MultiValueMap<String,String>, Serializable
Represents STOMP frame headers.In addition to the normal methods defined by
Map, this class offers the following convenience methods:getFirst(String)return the first value for a header nameadd(String, String)add to the list of values for a header nameset(String, String)set a header name to a single string value
- Since:
- 4.2
- Author:
- Rossen Stoyanchev
- See Also:
- https://stomp.github.io/stomp-specification-1.2.html#Frames_and_Headers, Serialized Form
Field Summary
Fields Modifier and Type Field Description static StringACKstatic StringCONTENT_LENGTHstatic StringCONTENT_TYPEstatic StringDESTINATIONstatic StringHEARTBEATstatic StringHOSTstatic StringIDstatic StringLOGINstatic StringMESSAGE_IDstatic StringPASSCODEstatic StringRECEIPTstatic StringRECEIPT_IDstatic StringSERVERstatic StringSESSIONstatic StringSUBSCRIPTION
Constructor Summary
Constructors Constructor Description StompHeaders()Create a new instance to be populated with new header values.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(String headerName, String headerValue)Add the given, single header value under the given name.voidclear()booleancontainsKey(Object key)booleancontainsValue(Object value)Set<Map.Entry<String,List<String>>>entrySet()booleanequals(Object other)List<String>get(Object key)StringgetAck()Get the ack header.longgetContentLength()Return the content-length header or -1 if unknown.MimeTypegetContentType()Return the content-type header value.StringgetDestination()Get the destination header.StringgetFirst(String headerName)Return the first header value for the given header name, if any.long[]getHeartbeat()Get the heartbeat header.StringgetHost()Get the host header.StringgetId()Get the id header.StringgetLogin()Get the login header.StringgetMessageId()Get the message-id header.StringgetPasscode()Get the passcode header.StringgetReceipt()Get the receipt header.StringgetReceiptId()Get the receipt header.StringgetServer()Get the server header.StringgetSession()Get the session header.StringgetSubscription()Get the subscription header.inthashCode()booleanisEmpty()booleanisHeartbeatEnabled()Whether heartbeats are enabled.Set<String>keySet()List<String>put(String key, List<String> value)voidputAll(Map<? extends String,? extends List<String>> map)static StompHeadersreadOnlyStompHeaders(Map<String,List<String>> headers)Return aStompHeadersobject that can only be read, not written to.List<String>remove(Object key)voidset(String headerName, String headerValue)Set the given, single header value under the given name.voidsetAck(String ack)Set the ack header to one of "auto", "client", or "client-individual".voidsetAll(Map<String,String> values)Set the given values under.voidsetContentLength(long contentLength)Set the content-length header.voidsetContentType(MimeType mimeType)Set the content-type header.voidsetDestination(String destination)Set the destination header.voidsetHeartbeat(long[] heartbeat)Set the heartbeat header.voidsetHost(String host)Set the host header.voidsetId(String id)Set the id header.voidsetLogin(String login)Set the login header.voidsetMessageId(String messageId)Set the message-id header.voidsetPasscode(String passcode)Set the passcode header.voidsetReceipt(String receipt)Set the receipt header.voidsetReceiptId(String receiptId)Set the receipt-id header.voidsetServer(String server)Set the server header.voidsetSession(String session)Set the session header.voidsetSubscription(String subscription)Set the login header.intsize()Map<String,String>toSingleValueMap()Return aMapwith the first values contained in thisMultiValueMap.StringtoString()Collection<List<String>>values()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
Field Detail
CONTENT_TYPE
public static final String CONTENT_TYPE
- See Also:
- Constant Field Values
CONTENT_LENGTH
public static final String CONTENT_LENGTH
- See Also:
- Constant Field Values
RECEIPT
public static final String RECEIPT
- See Also:
- Constant Field Values
HOST
public static final String HOST
- See Also:
- Constant Field Values
LOGIN
public static final String LOGIN
- See Also:
- Constant Field Values
PASSCODE
public static final String PASSCODE
- See Also:
- Constant Field Values
HEARTBEAT
public static final String HEARTBEAT
- See Also:
- Constant Field Values
SESSION
public static final String SESSION
- See Also:
- Constant Field Values
SERVER
public static final String SERVER
- See Also:
- Constant Field Values
DESTINATION
public static final String DESTINATION
- See Also:
- Constant Field Values
ID
public static final String ID
- See Also:
- Constant Field Values
ACK
public static final String ACK
- See Also:
- Constant Field Values
SUBSCRIPTION
public static final String SUBSCRIPTION
- See Also:
- Constant Field Values
MESSAGE_ID
public static final String MESSAGE_ID
- See Also:
- Constant Field Values
RECEIPT_ID
public static final String RECEIPT_ID
- See Also:
- Constant Field Values
Constructor Detail
StompHeaders
public StompHeaders()
Create a new instance to be populated with new header values.
Method Detail
setContentType
public void setContentType(MimeType mimeType)
Set the content-type header. Applies to the SEND, MESSAGE, and ERROR frames.
getContentType
public MimeType getContentType()
Return the content-type header value.
setContentLength
public void setContentLength(long contentLength)
Set the content-length header. Applies to the SEND, MESSAGE, and ERROR frames.
getContentLength
public long getContentLength()
Return the content-length header or -1 if unknown.
setReceipt
public void setReceipt(String receipt)
Set the receipt header. Applies to any client frame other than CONNECT.
getReceipt
public String getReceipt()
Get the receipt header.
setPasscode
public void setPasscode(String passcode)
Set the passcode header. Applies to the CONNECT frame.
getPasscode
public String getPasscode()
Get the passcode header.
setHeartbeat
public void setHeartbeat(long[] heartbeat)
Set the heartbeat header. Applies to the CONNECT and CONNECTED frames.
getHeartbeat
public long[] getHeartbeat()
Get the heartbeat header.
isHeartbeatEnabled
public boolean isHeartbeatEnabled()
Whether heartbeats are enabled. ReturnsfalseifsetHeartbeat(long[])is set to "0,0", andtrueotherwise.
setSession
public void setSession(String session)
Set the session header. Applies to the CONNECTED frame.
getSession
public String getSession()
Get the session header.
setServer
public void setServer(String server)
Set the server header. Applies to the CONNECTED frame.
setDestination
public void setDestination(String destination)
Set the destination header.
getDestination
public String getDestination()
Get the destination header. Applies to the SEND, SUBSCRIBE, and MESSAGE frames.
setId
public void setId(String id)
Set the id header. Applies to the SUBSCR0BE, UNSUBSCRIBE, and ACK or NACK frames.
setAck
public void setAck(String ack)
Set the ack header to one of "auto", "client", or "client-individual". Applies to the SUBSCRIBE and MESSAGE frames.
setSubscription
public void setSubscription(String subscription)
Set the login header. Applies to the MESSAGE frame.
getSubscription
public String getSubscription()
Get the subscription header.
setMessageId
public void setMessageId(String messageId)
Set the message-id header. Applies to the MESSAGE frame.
getMessageId
public String getMessageId()
Get the message-id header.
setReceiptId
public void setReceiptId(String receiptId)
Set the receipt-id header. Applies to the RECEIPT frame.
getReceiptId
public String getReceiptId()
Get the receipt header.
getFirst
public String getFirst(String headerName)
Return the first header value for the given header name, if any.- Specified by:
getFirstin interfaceMultiValueMap<String,String>- Parameters:
headerName- the header name- Returns:
- the first header value, or
nullif none
add
public void add(String headerName, String headerValue)
Add the given, single header value under the given name.- Specified by:
addin interfaceMultiValueMap<String,String>- Parameters:
headerName- the header nameheaderValue- the header value- Throws:
UnsupportedOperationException- if adding headers is not supported- See Also:
put(String, List),set(String, String)
set
public void set(String headerName, String headerValue)
Set the given, single header value under the given name.- Specified by:
setin interfaceMultiValueMap<String,String>- Parameters:
headerName- the header nameheaderValue- the header value- Throws:
UnsupportedOperationException- if adding headers is not supported- See Also:
put(String, List),add(String, String)
setAll
public void setAll(Map<String,String> values)
Description copied from interface:MultiValueMapSet the given values under.- Specified by:
setAllin interfaceMultiValueMap<String,String>- Parameters:
values- the values.
toSingleValueMap
public Map<String,String> toSingleValueMap()
Description copied from interface:MultiValueMapReturn aMapwith the first values contained in thisMultiValueMap.- Specified by:
toSingleValueMapin interfaceMultiValueMap<String,String>- Returns:
- a single value representation of this map
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKeyin interfaceMap<String,List<String>>
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValuein interfaceMap<String,List<String>>
values
public Collection<List<String>> values()
hashCode
public int hashCode()
readOnlyStompHeaders
public static StompHeaders readOnlyStompHeaders(Map<String,List<String>> headers)
Return aStompHeadersobject that can only be read, not written to.