RestxRouting { public Optional<Match> match(RestxRequest restxRequest) { for (RestxRoute route : routes) { Optional<? extends RestxHandlerMatch> match = route.match(restxRequest); if (match.isPresent()) { ImmutableCollection<NamedComponent<RestxHandlerMatch>> routeFilters = this.routeFilters.get(route); List<NamedComponent<RestxHandlerMatch>> matches = Lists.newArrayListWithCapacity( filters.size() + routeFilters.size() + 1); matches.addAll(routeFilters); for (NamedComponent<RestxFilter> filter : filters) { Optional<? extends RestxHandlerMatch> filterMatch = filter.getComponent().match(restxRequest); if (filterMatch.isPresent()) { matches.add(NamedComponent.of( RestxHandlerMatch.class, filter.getName().getName(), filter.getPriority(), filterMatch.get())); } } return Optional.of(new Match( ImmutableList.<RestxHandlerMatch>builder() .addAll( transform(Ordering.from(Factory.NAMED_COMPONENT_COMPARATOR).sortedCopy(matches), NamedComponent.<RestxHandlerMatch>toComponent())) .add(match.get()) .build(), match)); } } return Optional.absent(); } RestxRouting(ImmutableList<NamedComponent<RestxFilter>> filters,
                        ImmutableList<NamedComponent<RestxRouteFilter>> routeFilters,
                        ImmutableList<RestxRoute> routes); ImmutableList<RestxFilter> getFilters(); ImmutableCollection<? extends RestxHandlerMatch> getRouteFilters(RestxRoute route); ImmutableList<RestxRoute> getRoutes(); Optional<Match> match(RestxRequest restxRequest);  }
@Test public void should_match_with_filters_in_order() throws Exception { RestxRouting routing = new RestxRouting( ImmutableList.of( NamedComponent.of(RestxFilter.class, "F1", 0, new TestFilter("F1"))), ImmutableList.of( NamedComponent.of(RestxRouteFilter.class, "RF1", -10, new TestRouteFilter("RF1")), NamedComponent.of(RestxRouteFilter.class, "RF2", 10, new TestRouteFilter("RF2")) ), ImmutableList.<RestxRoute>of(ROUTE) ); Optional<Match> m = routing.match(StdRequest.builder() .setHttpMethod("GET").setRestxPath("/test").setBaseUri("http: assertThat(m.isPresent()).isTrue(); assertThat(m.get().getMatches()).extracting("handler.name") .containsExactly("RF1", "F1", "RF2", "ROUTE"); }