Allow to customize separator for messaging destinations
In order to be able to use separators like "." (used by default by most broker relays) instead of "/" for destination patterns handling, the PathMatcher used in spring-messaging can now be customized easily thanks to XML websocket namespace or JavaConfig. AntPathMatcher has been updated in order to use the configured path separator instead of an hardcoded "/" for path concatenation. Extension handling is now disabled when the "." separator is configured. Issue: SPR-11660
This commit is contained in:
committed by
Rossen Stoyanchev
parent
b676c41805
commit
928a466b5d
@@ -68,6 +68,23 @@ public class AntPathMatcher implements PathMatcher {
|
||||
|
||||
final Map<String, AntPathStringMatcher> stringMatcherCache = new ConcurrentHashMap<String, AntPathStringMatcher>(256);
|
||||
|
||||
/**
|
||||
* Create a new AntPathMatcher with the default Ant path separator "/".
|
||||
*/
|
||||
public AntPathMatcher() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new AntPathMatcher.
|
||||
* @param pathSeparator the path separator to use
|
||||
* @since 4.1
|
||||
*/
|
||||
public AntPathMatcher(String pathSeparator) {
|
||||
if(pathSeparator != null) {
|
||||
this.pathSeparator = pathSeparator;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the path separator to use for pattern parsing.
|
||||
@@ -430,20 +447,20 @@ public class AntPathMatcher implements PathMatcher {
|
||||
|
||||
// /hotels/* + /booking -> /hotels/booking
|
||||
// /hotels/* + booking -> /hotels/booking
|
||||
if (pattern1.endsWith("/*")) {
|
||||
return slashConcat(pattern1.substring(0, pattern1.length() - 2), pattern2);
|
||||
if (pattern1.endsWith(this.pathSeparator + "*")) {
|
||||
return separatorConcat(pattern1.substring(0, pattern1.length() - 2), pattern2);
|
||||
}
|
||||
|
||||
// /hotels/** + /booking -> /hotels/**/booking
|
||||
// /hotels/** + booking -> /hotels/**/booking
|
||||
if (pattern1.endsWith("/**")) {
|
||||
return slashConcat(pattern1, pattern2);
|
||||
if (pattern1.endsWith(this.pathSeparator + "**")) {
|
||||
return separatorConcat(pattern1, pattern2);
|
||||
}
|
||||
|
||||
int starDotPos1 = pattern1.indexOf("*.");
|
||||
if (pattern1ContainsUriVar || starDotPos1 == -1) {
|
||||
if (pattern1ContainsUriVar || starDotPos1 == -1 || this.pathSeparator.equals(".")) {
|
||||
// simply concatenate the two patterns
|
||||
return slashConcat(pattern1, pattern2);
|
||||
return separatorConcat(pattern1, pattern2);
|
||||
}
|
||||
String extension1 = pattern1.substring(starDotPos1 + 1);
|
||||
int dotPos2 = pattern2.indexOf('.');
|
||||
@@ -453,11 +470,11 @@ public class AntPathMatcher implements PathMatcher {
|
||||
return fileName2 + extension;
|
||||
}
|
||||
|
||||
private String slashConcat(String path1, String path2) {
|
||||
if (path1.endsWith("/") || path2.startsWith("/")) {
|
||||
private String separatorConcat(String path1, String path2) {
|
||||
if (path1.endsWith(this.pathSeparator) || path2.startsWith(this.pathSeparator)) {
|
||||
return path1 + path2;
|
||||
}
|
||||
return path1 + "/" + path2;
|
||||
return path1 + this.pathSeparator + path2;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user