use of org.springframework.util.AntPathMatcher in project metalnx-web by irods-contrib.
the class CollectionInfoController method extractFilePath.
private String extractFilePath(HttpServletRequest request) throws JargonException {
String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
try {
path = URLDecoder.decode(path, this.getIrodsServices().getIrodsAccessObjectFactory().getJargonProperties().getEncoding());
} catch (UnsupportedEncodingException | JargonException e) {
logger.error("unable to decode path", e);
throw new JargonException(e);
}
String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
AntPathMatcher apm = new AntPathMatcher();
return apm.extractPathWithinPattern(bestMatchPattern, path);
}
use of org.springframework.util.AntPathMatcher in project spring-integration by spring-projects.
the class HttpRequestHandlingMessagingGatewayWithPathMappingTests method withPayloadExpressionPointingToPathVariable.
@Test
public void withPayloadExpressionPointingToPathVariable() throws Exception {
DirectChannel echoChannel = new DirectChannel();
echoChannel.subscribe(message -> {
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
replyChannel.send(message);
});
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
request.setMethod("POST");
request.setContentType("text/plain");
request.setParameter("foo", "bar");
request.setContent("hello".getBytes());
String requestURI = "/fname/bill/lname/clinton";
// See org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping#handleMatch
Map<String, String> uriTemplateVariables = new AntPathMatcher().extractUriTemplateVariables("/fname/{f}/lname/{l}", requestURI);
request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVariables);
request.setRequestURI(requestURI);
HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true);
gateway.setBeanFactory(mock(BeanFactory.class));
RequestMapping requestMapping = new RequestMapping();
requestMapping.setPathPatterns("/fname/{f}/lname/{l}");
gateway.setRequestMapping(requestMapping);
gateway.setRequestChannel(echoChannel);
gateway.setPayloadExpression(PARSER.parseExpression("#pathVariables.f"));
gateway.afterPropertiesSet();
gateway.start();
Object result = gateway.doHandleRequest(request, response);
assertThat(result, instanceOf(Message.class));
assertEquals("bill", ((Message<?>) result).getPayload());
}
use of org.springframework.util.AntPathMatcher in project commons by terran4j.
the class Strings method match.
/**
* 检测指定的 path 是否匹配 regexPaths 。
*
* @param path 路径。
* @param regexPaths 需要匹配的路径。
* @return 匹配的路径。
*/
public static boolean match(String path, String... regexPaths) {
PathMatcher pathMatch = new AntPathMatcher();
if (path == null || regexPaths == null) {
return false;
}
for (String regexPath : regexPaths) {
if (regexPath == null) {
continue;
}
regexPath = regexPath.trim();
path = path.trim();
if (pathMatch.match(regexPath, path)) {
return true;
}
}
return false;
}
use of org.springframework.util.AntPathMatcher in project AJSC by att.
the class UtilLib method getInput.
public static String getInput(String[] pathinfoArr, int arrLength, String componentType, String pathInfo) {
Set<String> endpointSet = null;
if (componentType.equalsIgnoreCase("rest")) {
endpointSet = DME2Helper.restletEndpointSet;
} else {
endpointSet = DME2Helper.serviceEndpointSet;
}
HashSet<String> setBasedArrLenth = new HashSet<String>();
HashMap setBasedCharMap = new HashMap();
HashSet<String> setBasedValues = new HashSet<String>();
AntPathMatcher pathMatcher = new AntPathMatcher();
String[] inputBasedonLength;
int globalvalue = 0;
for (String s : endpointSet) {
int dif = StringUtils.getLevenshteinDistance(pathInfo, s);
if (globalvalue == 0 || globalvalue > dif) {
globalvalue = dif;
setBasedCharMap.put(globalvalue, s);
}
inputBasedonLength = s.split("\\/");
int i = inputBasedonLength.length;
if (arrLength == i) {
setBasedArrLenth.add(s);
}
}
String[] inputBasedOnValues;
for (String s1 : setBasedArrLenth) {
inputBasedOnValues = s1.split("\\/");
int j = 1;
while (compareValues(pathinfoArr[j], inputBasedOnValues[j])) {
j++;
if (j >= arrLength) {
break;
}
}
if (j == arrLength) {
setBasedValues.add(s1);
}
}
String input = "";
if (setBasedValues.size() == 1) {
for (String s2 : setBasedValues) {
input = s2;
}
} else {
for (String s2 : setBasedValues) {
if (pathMatcher.match(pathInfo, s2)) {
input = s2;
}
}
}
if (input.isEmpty()) {
input = (String) setBasedCharMap.get(globalvalue);
}
return "/" + componentType + input;
}
use of org.springframework.util.AntPathMatcher in project spring-framework by spring-projects.
the class RSocketMessageHandlerTests method setRSocketStrategies.
@Test
public void setRSocketStrategies() {
RSocketStrategies strategies = RSocketStrategies.builder().encoder(new ByteArrayEncoder()).decoder(new ByteArrayDecoder()).routeMatcher(new SimpleRouteMatcher(new AntPathMatcher())).metadataExtractor(new DefaultMetadataExtractor()).reactiveAdapterStrategy(new ReactiveAdapterRegistry()).build();
RSocketMessageHandler handler = new RSocketMessageHandler();
handler.setRSocketStrategies(strategies);
assertThat(handler.getEncoders()).isEqualTo(strategies.encoders());
assertThat(handler.getDecoders()).isEqualTo(strategies.decoders());
assertThat(handler.getRouteMatcher()).isSameAs(strategies.routeMatcher());
assertThat(handler.getMetadataExtractor()).isSameAs(strategies.metadataExtractor());
assertThat(handler.getReactiveAdapterRegistry()).isSameAs(strategies.reactiveAdapterRegistry());
}
Aggregations