org.mockserver.matchers.StringMatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockserver-core Show documentation
Show all versions of mockserver-core Show documentation
Functionality used by all MockServer modules for matching and expectations
package org.mockserver.matchers;
import com.google.common.base.Strings;
import org.mockserver.model.ModelObject;
import java.util.regex.PatternSyntaxException;
/**
* @author jamesdbloom
*/
public class StringMatcher extends ModelObject implements Matcher {
private final String path;
public StringMatcher(String path) {
this.path = path;
}
public boolean matches(String path) {
boolean result = false;
if (Strings.isNullOrEmpty(this.path)) {
result = true;
} else if (path != null) {
try {
if (path.matches(this.path)) {
result = true;
}
} catch (PatternSyntaxException pse) {
logger.error("Error while matching regex [" + this.path + "] for string [" + path + "] " + pse.getMessage());
}
try {
if (this.path.matches(path)) {
result = true;
}
} catch (PatternSyntaxException pse) {
logger.error("Error while matching regex [" + path + "] for string [" + this.path + "] " + pse.getMessage());
}
}
if (!result) {
logger.trace("Failed to match [{}] with [{}]", path, this.path);
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy