Package org.apache.wink.common.internal.uritemplate

Examples of org.apache.wink.common.internal.uritemplate.UriTemplateMatcher


        } catch (IllegalStateException e) {
        }

        // compiled but not matched
        processor.compile("/path1/{var1}");
        UriTemplateMatcher matcher = processor.matcher();
        assertFalse(matcher.matches("/path2"));

        try {
            matcher.getVariables(false);
            fail("expected IllegalStateException to be thrown");
        } catch (IllegalStateException e) {
        }

        try {
            matcher.getVariableValue("var1");
            fail("expected IllegalStateException to be thrown");
        } catch (IllegalStateException e) {
        }

        try {
            matcher.getVariableValue("var1", false);
            fail("expected IllegalStateException to be thrown");
        } catch (IllegalStateException e) {
        }

        try {
            matcher.getVariableValues("var1");
            fail("expected IllegalStateException to be thrown");
        } catch (IllegalStateException e) {
        }

        try {
            matcher.getVariableValues("var1", false);
            fail("expected IllegalStateException to be thrown");
        } catch (IllegalStateException e) {
        }

        try {
            matcher.getTail();
            fail("expected IllegalStateException to be thrown");
        } catch (IllegalStateException e) {
        }

        try {
            matcher.getTail(false);
            fail("expected IllegalStateException to be thrown");
        } catch (IllegalStateException e) {
        }
    }
View Full Code Here


    }

    public void testMatches() {
        String template = "/path1/{var1}/path2{var2:[ab]*}/tail";
        JaxRsUriTemplateProcessor processor = new JaxRsUriTemplateProcessor(template);
        UriTemplateMatcher matcher = processor.matcher();
        assertEquals(template, processor.getTemplate());

        boolean matches = matcher.matches("/path1/value1/path2/tail");
        assertTrue(matches);
        matches = matcher.matches("/path1/value1/path2ab/tail");
        assertTrue(matches);
        matches = matcher.matches("/path1/value1/path2ababab/tail");
        assertTrue(matches);
        matches = matcher.matches("/path1/value2/path2/tail");
        assertTrue(matches);

        matches = matcher.matches("/path1/value1/path2c/tail");
        assertFalse(matches);
        matches = matcher.matches("/path2/value1/path2ab/tail");
        assertFalse(matches);
        matches = matcher.matches("/path1/value1/path2c/tailZ");
        assertFalse(matches);
    }
View Full Code Here

    }

    public void testGetVariables() {
        JaxRsUriTemplateProcessor processor =
            new JaxRsUriTemplateProcessor("/path1/{var1}/path2{var2:[ab]*}/{var1}");
        UriTemplateMatcher matcher = processor.matcher();
        matcher.matches("/path1/value%20a/path2abab/valueB/tail%20part");

        // variable value
        assertEquals("value a", matcher.getVariableValue("var1"));
        assertEquals("value%20a", matcher.getVariableValue("var1", false));
        assertEquals("abab", matcher.getVariableValue("var2"));
        assertEquals("abab", matcher.getVariableValue("var2", false));
        assertNull(matcher.getVariableValue("var3"));

        // variable values as list
        List<String> varValues = matcher.getVariableValues("var1");
        assertEquals(2, varValues.size());
        assertEquals("value a", varValues.get(0));
        assertEquals("valueB", varValues.get(1));
        varValues = matcher.getVariableValues("var1", false);
        assertEquals(2, varValues.size());
        assertEquals("value%20a", varValues.get(0));
        assertEquals("valueB", varValues.get(1));
        varValues = matcher.getVariableValues("var2");
        assertEquals(1, varValues.size());
        assertEquals("abab", varValues.get(0));

        // variable names set
        Set<String> variableNames = processor.getVariableNames();
        assertEquals(2, variableNames.size());
        assertTrue(variableNames.contains("var1"));
        assertTrue(variableNames.contains("var2"));

        // get all variables
        // decoded
        MultivaluedMap<String, String> allVariables = matcher.getVariables(true);
        assertEquals(2, allVariables.size());
        varValues = allVariables.get("var1");
        assertEquals(2, varValues.size());
        assertEquals("value a", varValues.get(0));
        assertEquals("valueB", varValues.get(1));
        varValues = allVariables.get("var2");
        assertEquals(1, varValues.size());
        assertEquals("abab", varValues.get(0));

        // encoded
        allVariables = matcher.getVariables(false);
        assertEquals(2, allVariables.size());
        varValues = allVariables.get("var1");
        assertEquals(2, varValues.size());
        assertEquals("value%20a", varValues.get(0));
        assertEquals("valueB", varValues.get(1));
View Full Code Here

    }

    public void testTail() {
        JaxRsUriTemplateProcessor processor =
            new JaxRsUriTemplateProcessor("/path1/{var1}/path2{var2:[ab]*}/{var3}");
        UriTemplateMatcher matcher = processor.matcher();
        matcher.matches("/path1/value%20a/path2abab/valueB/tail%20part");

        String tail = matcher.getTail();
        assertEquals("/tail part", tail);
        assertEquals("/tail%20part", matcher.getTail(false));

        matcher.matches("/path1/value%20a/path2abab/valueB/");
        tail = matcher.getTail();
        assertEquals("/", tail);

        matcher.matches("/path1/value%20a/path2abab/valueB");
        tail = matcher.getTail();
        assertEquals("", tail);
    }
View Full Code Here

    }

    public void testHead() {
        JaxRsUriTemplateProcessor processor =
            new JaxRsUriTemplateProcessor("/path1/{var1}/path2{var2:[ab]*}/{var3}");
        UriTemplateMatcher matcher = processor.matcher();
        matcher.matches("/path1/value%20a/path2abab/valueB/tail%20part");

        String head = matcher.getHead();
        assertEquals("/path1/value a/path2abab/valueB", head);
        assertEquals("/path1/value%20a/path2abab/valueB", matcher.getHead(false));

        matcher.matches("/path1/value%20a/path2abab/valueB/");
        head = matcher.getHead();
        assertEquals("/path1/value a/path2abab/valueB", head);

        matcher.matches("/path1/value%20a/path2abab/valueB");
        head = matcher.getHead();
        assertEquals("/path1/value a/path2abab/valueB", head);
    }
View Full Code Here

                String requestPath = input.get(JRack.PATH_INFO);
                if (StringUtils.isBlank(requestPath)) {
                    requestPath = input.get(Rack.SCRIPT_NAME);
                }

                UriTemplateMatcher templateMatcher = match(requestPath, path);

                if (templateMatcher != null) {
                    try {
                        MultivaluedMap<String, String> routeParams = templateMatcher.getVariables(true);
                        Map<String, String[]> params = (Map<String, String[]>) context.get(Globals.PARAMS);

                        if (CollectionUtils.isEmpty(params)) {
                            params = new HashMap<String, String[]>();
                            context.with(Globals.PARAMS, params);
View Full Code Here

        if (processor == null) {
            processor = new JaxRsUriTemplateProcessor(testPath);
        }

        UriTemplateMatcher matcher = processor.matcher();
        return matcher.matches(requestPath) ? matcher : null;
    }
View Full Code Here

        if (processor == null) {
            // processor = new BitWorkingUriTemplateProcessor(testPath);
            processor = new JaxRsUriTemplateProcessor(testPath);
        }

        UriTemplateMatcher matcher = processor.matcher();
        return matcher.matches(requestPath) ? matcher : null;
    }
View Full Code Here

    if (requestedMethod != null) {
      for (Route route : routes) {
        if (route.getMethod().isEmpty() || route.getMethod().contains(requestedMethod)) {

          UriTemplateMatcher templateMatcher = route.match(path, route.getPath());

          if (templateMatcher != null) {
            MultivaluedMap<String, String> routeParams = templateMatcher.getVariables(true);
            Map<String, Object> params = (Map<String, Object>) context.get(Globals.PARAMS);

            if (CollectionUtils.isEmpty(params)) {
              params = new HashMap<String, Object>();
              context.with(Globals.PARAMS, params);
View Full Code Here

TOP

Related Classes of org.apache.wink.common.internal.uritemplate.UriTemplateMatcher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.