Search in sources :

Example 26 with AntPathMatcher

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);
}
Also used : JargonException(org.irods.jargon.core.exception.JargonException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AntPathMatcher(org.springframework.util.AntPathMatcher)

Example 27 with AntPathMatcher

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());
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) Message(org.springframework.messaging.Message) DirectChannel(org.springframework.integration.channel.DirectChannel) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) BeanFactory(org.springframework.beans.factory.BeanFactory) AntPathMatcher(org.springframework.util.AntPathMatcher) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 28 with AntPathMatcher

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;
}
Also used : PathMatcher(org.springframework.util.PathMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher)

Example 29 with AntPathMatcher

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;
}
Also used : HashMap(java.util.HashMap) AntPathMatcher(org.springframework.util.AntPathMatcher) HashSet(java.util.HashSet)

Example 30 with AntPathMatcher

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());
}
Also used : ByteArrayEncoder(org.springframework.core.codec.ByteArrayEncoder) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) RSocketStrategies(org.springframework.messaging.rsocket.RSocketStrategies) DefaultMetadataExtractor(org.springframework.messaging.rsocket.DefaultMetadataExtractor) SimpleRouteMatcher(org.springframework.util.SimpleRouteMatcher) AntPathMatcher(org.springframework.util.AntPathMatcher) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder) Test(org.junit.jupiter.api.Test)

Aggregations

AntPathMatcher (org.springframework.util.AntPathMatcher)36 Test (org.junit.jupiter.api.Test)13 SimpleRouteMatcher (org.springframework.util.SimpleRouteMatcher)11 Test (org.junit.Test)5 ReactiveAdapterRegistry (org.springframework.core.ReactiveAdapterRegistry)5 ByteArrayDecoder (org.springframework.core.codec.ByteArrayDecoder)4 ByteArrayEncoder (org.springframework.core.codec.ByteArrayEncoder)4 GenericMessage (org.springframework.messaging.support.GenericMessage)4 Message (org.springframework.messaging.Message)3 DefaultMetadataExtractor (org.springframework.messaging.rsocket.DefaultMetadataExtractor)3 RSocketStrategies (org.springframework.messaging.rsocket.RSocketStrategies)3 MessageHeaderAccessor (org.springframework.messaging.support.MessageHeaderAccessor)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 PathMatcher (org.springframework.util.PathMatcher)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 BeanFactory (org.springframework.beans.factory.BeanFactory)2 CharSequenceEncoder (org.springframework.core.codec.CharSequenceEncoder)2