/** * Performs a case-insensitive wildcard match against two strings. This method works with pseduo-regex chars; specifically ? and * are supported. * <ul> * <li>An asterisk (*) represents any combination of characters</li> * <li>A question mark (?) represents any single character</li> * </ul> * * @param pattern * the regex-like pattern to be compared against * @param text * the string to compare against the pattern * @return whether the text matches the pattern */ public static boolean wildcardMatch(String pattern, String text){ return wildcardMatch(pattern, text, true); }
if(isWildcardGlob(pattern)) { return true; return simpleWildcardMatch(pattern, text);
if(isWildcardGlob(pattern)) { return true; return simpleWildcardMatch(pattern, text);
/** * Determines whether or not this sampling rule applies to the incoming request based on some of the request's parameters. Any null parameters provided will be considered an implicit match. For example, {@code appliesTo(null, null, null)} will always return {@code true}, for any rule. * * @param requestHost * the host name for the incoming request. * @param requestPath * the path from the incoming request * @param requestMethod * the method used to make the incoming request * @return whether or not this rule applies to the incoming request */ public boolean appliesTo(String requestHost, String requestPath, String requestMethod) { return (null == host || SearchPattern.wildcardMatch(host, requestHost)) && (null == requestPath || SearchPattern.wildcardMatch(urlPath, requestPath)) && (null == requestMethod || SearchPattern.wildcardMatch(httpMethod, requestMethod)); }
/** * Determines whether or not this sampling rule applies to the incoming request based on some of the request's parameters. Any null parameters provided will be considered an implicit match. For example, {@code appliesTo(null, null, null)} will always return {@code true}, for any rule. * * @param requestHost * the host name for the incoming request. * @param requestPath * the path from the incoming request * @param requestMethod * the method used to make the incoming request * @return whether or not this rule applies to the incoming request */ public boolean appliesTo(String requestHost, String requestPath, String requestMethod) { return (null == host || SearchPattern.wildcardMatch(host, requestHost)) && (null == requestPath || SearchPattern.wildcardMatch(urlPath, requestPath)) && (null == requestMethod || SearchPattern.wildcardMatch(httpMethod, requestMethod)); }
/** * Performs a case-insensitive wildcard match against two strings. This method works with pseduo-regex chars; specifically ? and * are supported. * <ul> * <li>An asterisk (*) represents any combination of characters</li> * <li>A question mark (?) represents any single character</li> * </ul> * * @param pattern * the regex-like pattern to be compared against * @param text * the string to compare against the pattern * @return whether the text matches the pattern */ public static boolean wildcardMatch(String pattern, String text){ return wildcardMatch(pattern, text, true); }
/** * * Returns the derived segment name for an incoming request. Attempts to get the {@code Host} header from the {@code HttpServletRequest}. If the {@code Host} header has a value and if the value matches the optionally provided {@code recognizedHosts} pattern, then this value is returned as the segment name. Otherwise, {@code fallbackName} is returned. * * * @param request * the incoming request * @return * the segment name for the incoming request. */ @Override public String nameForRequest(HttpServletRequest request) { Optional<String> hostHeaderValue = Optional.ofNullable(request.getHeader("Host")); if (hostHeaderValue.isPresent() && (null == recognizedHosts || SearchPattern.wildcardMatch(recognizedHosts, hostHeaderValue.get()))) { return hostHeaderValue.get(); } return fallbackName; } }
/** * * Returns the derived segment name for an incoming request. Attempts to get the {@code Host} header from the {@code HttpServletRequest}. If the {@code Host} header has a value and if the value matches the optionally provided {@code recognizedHosts} pattern, then this value is returned as the segment name. Otherwise, {@code fallbackName} is returned. * * * @param request * the incoming request * @return * the segment name for the incoming request. */ @Override public String nameForRequest(HttpServletRequest request) { Optional<String> hostHeaderValue = Optional.ofNullable(request.getHeader("Host")); if (hostHeaderValue.isPresent() && (null == recognizedHosts || SearchPattern.wildcardMatch(recognizedHosts, hostHeaderValue.get()))) { return hostHeaderValue.get(); } return fallbackName; } }
boolean match(SamplingRequest req) { // Comparing against the full list of matchers can be expensive. We try to short-circuit the req as quickly // as possible by comparing against matchers with high variance and moving down to matchers that are almost // always "*". Map<String, String> requestAttributes = req.getAttributes(); // Ensure that each defined attribute in the sampling rule is satisfied by the request. It is okay for the // request to have attributes with no corresponding match in the sampling rule. for (Map.Entry<String, String> a : attributes.entrySet()) { if (!requestAttributes.containsKey(a.getKey())) { return false; } if (!SearchPattern.wildcardMatch(a.getValue(), requestAttributes.get(a.getKey()))) { return false; } continue; } // Missing string parameters from the sampling request are replaced with ""s to ensure they match against * // matchers. return SearchPattern.wildcardMatch(url, req.getUrl().orElse("")) && SearchPattern.wildcardMatch(service, req.getService().orElse("")) && SearchPattern.wildcardMatch(method, req.getMethod().orElse("")) && SearchPattern.wildcardMatch(host, req.getHost().orElse("")) && SearchPattern.wildcardMatch(serviceType, req.getServiceType().orElse("")); } }
boolean match(SamplingRequest req) { // Comparing against the full list of matchers can be expensive. We try to short-circuit the req as quickly // as possible by comparing against matchers with high variance and moving down to matchers that are almost // always "*". Map<String, String> requestAttributes = req.getAttributes(); // Ensure that each defined attribute in the sampling rule is satisfied by the request. It is okay for the // request to have attributes with no corresponding match in the sampling rule. for (Map.Entry<String, String> a : attributes.entrySet()) { if (!requestAttributes.containsKey(a.getKey())) { return false; } if (!SearchPattern.wildcardMatch(a.getValue(), requestAttributes.get(a.getKey()))) { return false; } continue; } // Missing string parameters from the sampling request are replaced with ""s to ensure they match against * // matchers. return SearchPattern.wildcardMatch(url, req.getUrl().orElse("")) && SearchPattern.wildcardMatch(service, req.getService().orElse("")) && SearchPattern.wildcardMatch(method, req.getMethod().orElse("")) && SearchPattern.wildcardMatch(host, req.getHost().orElse("")) && SearchPattern.wildcardMatch(serviceType, req.getServiceType().orElse("")); } }