Top Description Fields Constructors Methods
org.springframework.messaging.handler

public Class DestinationPatternsMessageCondition

extends AbstractMessageCondition<DestinationPatternsMessageCondition>
Class Inheritance
Imports
java.util.ArrayList, .Collection, .Collections, .Comparator, .Iterator, .LinkedHashSet, .List, .Set, org.springframework.lang.Nullable, org.springframework.messaging.Message, org.springframework.util.AntPathMatcher, .CollectionUtils, .PathMatcher, .RouteMatcher, .SimpleRouteMatcher, .StringUtils

MessageCondition to match the destination header of a Message against one or more patterns through a RouteMatcher.
Author
Rossen Stoyanchev
Since
4.0

Field Summary

Modifier and TypeField and Description
public static final String
LOOKUP_DESTINATION_HEADER

The name of the "lookup destination" header.

private final Set<String>
private final RouteMatcher

Constructor Summary

AccessConstructor and Description
public
DestinationPatternsMessageCondition(String...
the URL patterns to match to, or if 0 then always match
patterns
)

Constructor with patterns only.

public
DestinationPatternsMessageCondition(String[]
the URL patterns to match to, or if 0 then always match
patterns
,
PathMatcher
the PathMatcher to use
matcher
)

Constructor with patterns and a PathMatcher instance.

public
DestinationPatternsMessageCondition(String[]
the URL patterns to match to, or if 0 then always match
patterns
,
RouteMatcher
the RouteMatcher to use
routeMatcher
)

Constructor with patterns and a RouteMatcher instance.

private

Method Summary

Modifier and TypeMethod and Description
public DestinationPatternsMessageCondition
combine(DestinationPatternsMessageCondition
the condition to combine with
other
)

Implements org.springframework.messaging.handler.MessageCondition.combine.

Returns a new instance with URL patterns from the current instance ("this") and the "other" instance as follows:
public int
compareTo(DestinationPatternsMessageCondition other, Message<?> message)

Implements org.springframework.messaging.handler.MessageCondition.compareTo.

Compare the two conditions based on the destination patterns they contain.
protected Collection<String>
getContent()

Implements abstract org.springframework.messaging.handler.AbstractMessageCondition.getContent.

Return the collection of objects the message condition is composed of (e.g. destination patterns), never null.
public DestinationPatternsMessageCondition

Returns:

the same instance if the condition contains no patterns; or a new condition with sorted matching patterns; or null either if a destination can not be extracted or there is no match
getMatchingCondition
(Message<?>
the message to match to
message
)

Implements org.springframework.messaging.handler.MessageCondition.getMatchingCondition.

Check if any of the patterns match the given Message destination and return an instance that is guaranteed to contain matching patterns, sorted via org.springframework.util.PathMatcher#getPatternComparator(String).
private Comparator<String>
public Set<String>
protected String
getToStringInfix()

Implements abstract org.springframework.messaging.handler.AbstractMessageCondition.getToStringInfix.

The notation to use when printing discrete items of content.
private boolean
matchPattern(String pattern, Object destination)

private static Set<String>
prependLeadingSlash(String[] patterns, RouteMatcher routeMatcher)

Inherited from org.springframework.messaging.handler.AbstractMessageCondition:
equalshashCodetoString

Field Detail

LOOKUP_DESTINATION_HEADERback to summary
public static final String LOOKUP_DESTINATION_HEADER

The name of the "lookup destination" header.

patternsback to summary
private final Set<String> patterns
routeMatcherback to summary
private final RouteMatcher routeMatcher

Constructor Detail

DestinationPatternsMessageConditionback to summary
public DestinationPatternsMessageCondition(String... patterns)

Constructor with patterns only. Creates and uses an instance of AntPathMatcher with default settings.

Non-empty patterns that don't start with "/" are prepended with "/".

Parameters
patterns:String[]

the URL patterns to match to, or if 0 then always match

DestinationPatternsMessageConditionback to summary
public DestinationPatternsMessageCondition(String[] patterns, PathMatcher matcher)

Constructor with patterns and a PathMatcher instance.

Parameters
patterns:String[]

the URL patterns to match to, or if 0 then always match

matcher:PathMatcher

the PathMatcher to use

DestinationPatternsMessageConditionback to summary
public DestinationPatternsMessageCondition(String[] patterns, RouteMatcher routeMatcher)

Constructor with patterns and a RouteMatcher instance.

Parameters
patterns:String[]

the URL patterns to match to, or if 0 then always match

routeMatcher:RouteMatcher

the RouteMatcher to use

Since
5.2
DestinationPatternsMessageConditionback to summary
private DestinationPatternsMessageCondition(Set<String> patterns, RouteMatcher routeMatcher)

Method Detail

combineback to summary
public DestinationPatternsMessageCondition combine(DestinationPatternsMessageCondition other)

Implements org.springframework.messaging.handler.MessageCondition.combine.

Returns a new instance with URL patterns from the current instance ("this") and the "other" instance as follows:

Parameters
other:DestinationPatternsMessageCondition

Doc from org.springframework.messaging.handler.MessageCondition.combine.

the condition to combine with

Returns:DestinationPatternsMessageCondition

Doc from org.springframework.messaging.handler.MessageCondition.combine.

the resulting message condition

Annotations
@Override
compareToback to summary
public int compareTo(DestinationPatternsMessageCondition other, Message<?> message)

Implements org.springframework.messaging.handler.MessageCondition.compareTo.

Compare the two conditions based on the destination patterns they contain. Patterns are compared one at a time, from top to bottom via org.springframework.util.PathMatcher#getPatternComparator(String). If all compared patterns match equally, but one instance has more patterns, it is considered a closer match.

It is assumed that both instances have been obtained via getMatchingCondition(Message) to ensure they contain only patterns that match the request and are sorted with the best matches on top.

Annotations
@Override
getContentback to summary
protected Collection<String> getContent()

Implements abstract org.springframework.messaging.handler.AbstractMessageCondition.getContent.

Doc from org.springframework.messaging.handler.AbstractMessageCondition.getContent.

Return the collection of objects the message condition is composed of (e.g. destination patterns), never null.

Annotations
@Override
getMatchingConditionback to summary
public DestinationPatternsMessageCondition getMatchingCondition(Message<?> message)

Implements org.springframework.messaging.handler.MessageCondition.getMatchingCondition.

Check if any of the patterns match the given Message destination and return an instance that is guaranteed to contain matching patterns, sorted via org.springframework.util.PathMatcher#getPatternComparator(String).

Parameters
message:Message<?>

the message to match to

Returns:DestinationPatternsMessageCondition

the same instance if the condition contains no patterns; or a new condition with sorted matching patterns; or null either if a destination can not be extracted or there is no match

Annotations
@Override
@Nullable
getPatternComparatorback to summary
private Comparator<String> getPatternComparator(Object destination)
getPatternsback to summary
public Set<String> getPatterns()
getToStringInfixback to summary
protected String getToStringInfix()

Implements abstract org.springframework.messaging.handler.AbstractMessageCondition.getToStringInfix.

Doc from org.springframework.messaging.handler.AbstractMessageCondition.getToStringInfix.

The notation to use when printing discrete items of content. For example " || " for URL patterns or " && " for param expressions.

Annotations
@Override
matchPatternback to summary
private boolean matchPattern(String pattern, Object destination)
prependLeadingSlashback to summary
private static Set<String> prependLeadingSlash(String[] patterns, RouteMatcher routeMatcher)