private List<UriPatternMatcher> parsePatterns(UriPatternType type, List<String> patterns) { List<UriPatternMatcher> patternMatchers = new ArrayList<>(); for (String pattern : patterns) { UriPatternMatcher matcher = null; try { matcher = UriPatternType.get(type, pattern); } catch (IllegalArgumentException iae) { binder .skipSources(ServletModule.class, FiltersModuleBuilder.class) .addError("%s", iae.getMessage()); } if (matcher != null) { patternMatchers.add(matcher); } } return patternMatchers; }
private List<UriPatternMatcher> parsePatterns(UriPatternType type, List<String> patterns) { List<UriPatternMatcher> patternMatchers = new ArrayList<>(); for (String pattern : patterns) { if (!servletUris.add(pattern)) { binder .skipSources(ServletModule.class, ServletsModuleBuilder.class) .addError("More than one servlet was mapped to the same URI pattern: " + pattern); } else { UriPatternMatcher matcher = null; try { matcher = UriPatternType.get(type, pattern); } catch (IllegalArgumentException iae) { binder .skipSources(ServletModule.class, ServletsModuleBuilder.class) .addError("%s", iae.getMessage()); } if (matcher != null) { patternMatchers.add(matcher); } } } return patternMatchers; }
public void testPatternWithPercentEncodedChars_servlet() { try { UriPatternType.get(UriPatternType.SERVLET, "/foo/%2f/*"); fail(); } catch (IllegalArgumentException iae) { assertTrue(iae.getMessage().contains("Servlet patterns cannot contain escape patterns.")); } } }
public void testServiceWithContextPath() throws IOException, ServletException { String pattern = "/*"; //some init params Map<String, String> initParams = new ImmutableMap.Builder<String, String>() .put("ahsd", "asdas24dok") .put("ahssd", "asdasd124ok") .build(); final ServletDefinition servletDefinition = new ServletDefinition( Key.get(HttpServlet.class), UriPatternType.get(UriPatternType.SERVLET, pattern), initParams, null); HttpServletResponse servletResponse = createMock(HttpServletResponse.class); HttpServletRequest servletRequest = createMock(HttpServletRequest.class); expect(servletRequest.getContextPath()).andReturn("/a_context_path"); expect(servletRequest.getRequestURI()).andReturn("/test.html"); replay(servletRequest, servletResponse); servletDefinition.service(servletRequest, servletResponse); verify(servletRequest, servletResponse); } }
new FilterDefinition( Key.get(Filter.class), UriPatternType.get(UriPatternType.SERVLET, pattern), new HashMap<String, String>(), null);
new FilterDefinition( Key.get(Filter.class), UriPatternType.get(UriPatternType.SERVLET, pattern), new HashMap<String, String>(), null);
new ServletDefinition( Key.get(HttpServlet.class), UriPatternType.get(UriPatternType.SERVLET, mapping), new HashMap<String, String>(), null);
new ServletDefinition( Key.get(HttpServlet.class), UriPatternType.get(UriPatternType.SERVLET, mapping), new HashMap<String, String>(), null);
new ServletDefinition( Key.get(HttpServlet.class), UriPatternType.get(UriPatternType.REGEX, mapping), new HashMap<String, String>(), null);
new ServletDefinition( Key.get(HttpServlet.class), UriPatternType.get(UriPatternType.SERVLET, pattern), new HashMap<String, String>(), null);
new ServletDefinition( Key.get(HttpServlet.class), UriPatternType.get(UriPatternType.SERVLET, pattern), new HashMap<String, String>(), null);
new ServletDefinition( Key.get(HttpServlet.class), UriPatternType.get(UriPatternType.SERVLET, pattern), new HashMap<String, String>(), null);
new ServletDefinition( Key.get(HttpServlet.class), UriPatternType.get(UriPatternType.SERVLET, pattern), initParams, null);
new FilterDefinition( Key.get(Filter.class), UriPatternType.get(UriPatternType.SERVLET, pattern), initParams, null);
new FilterDefinition( Key.get(Filter.class), UriPatternType.get(UriPatternType.SERVLET, pattern), new HashMap<String, String>(), null);
new FilterDefinition( Key.get(Filter.class), UriPatternType.get(UriPatternType.SERVLET, pattern), new HashMap<String, String>(), null);
private void through(Key<? extends Filter> filterKey, Map<String, String> initParams, Filter filterInstance) { for (String pattern : uriPatterns) { filterDefinitions.add( new FilterDefinition(pattern, filterKey, UriPatternType.get(uriPatternType, pattern), initParams, filterInstance)); } }
public void with(Key<? extends HttpServlet> servletKey, Map<String, String> contextParams) { for (String pattern : uriPatterns) { servletDefinitions.add( new ServletDefinition(pattern, servletKey, UriPatternType.get(uriPatternType, pattern), contextParams)); } } }
public void testMatches_regex() { UriPatternMatcher pattern = UriPatternType.get(UriPatternType.REGEX, "/.*/foo"); assertFalse(pattern.matches("/foo/asdf")); assertFalse(pattern.matches("/foo/asdf?val=1")); assertTrue(pattern.matches("/path/foo")); assertTrue(pattern.matches("/path/foo?val=1")); assertFalse(pattern.matches("/foo")); assertFalse(pattern.matches("/foo?val=1")); }
public void testMatches_servlet() { UriPatternMatcher pattern = UriPatternType.get(UriPatternType.SERVLET, "/foo/*"); assertTrue(pattern.matches("/foo/asdf")); assertTrue(pattern.matches("/foo/asdf?val=1")); assertFalse(pattern.matches("/path/file.bar")); assertFalse(pattern.matches("/path/file.bar?val=1")); assertFalse(pattern.matches("/asdf")); assertFalse(pattern.matches("/asdf?val=1")); pattern = UriPatternType.get(UriPatternType.SERVLET, "*.bar"); assertFalse(pattern.matches("/foo/asdf")); assertFalse(pattern.matches("/foo/asdf?val=1")); assertTrue(pattern.matches("/path/file.bar")); assertTrue(pattern.matches("/path/file.bar?val=1")); assertFalse(pattern.matches("/asdf")); assertFalse(pattern.matches("/asdf?val=1")); pattern = UriPatternType.get(UriPatternType.SERVLET, "/asdf"); assertFalse(pattern.matches("/foo/asdf")); assertFalse(pattern.matches("/foo/asdf?val=1")); assertFalse(pattern.matches("/path/file.bar")); assertFalse(pattern.matches("/path/file.bar?val=1")); assertTrue(pattern.matches("/asdf")); assertTrue(pattern.matches("/asdf?val=1")); }