@Test public void testUnmatched() throws Exception { String path = "unmatched"; String baseUri = "http: UriInfo uriInfo = mock(UriInfo.class); when(uriInfo.getPath()).thenReturn(path); when(uriInfo.getBaseUri()).thenReturn(new URI(baseUri)); when(uriInfo.getRequestUri()).thenReturn(new URI(baseUri + path)); ContainerRequestContext request = mock(ContainerRequestContext.class); when(request.getUriInfo()).thenReturn(uriInfo); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { fail("setUris shouldn't be called"); return null; } }).when(request).setRequestUri(any(URI.class), any(URI.class)); RedirectResourceFilter filter = new RedirectResourceFilter(); filter.filter(request); }
@Override public void filter(ContainerRequestContext requestContext) throws IOException { final UriInfo uriInfo = requestContext.getUriInfo(); if (uriInfo.getPath().equals("controller")){ UriBuilder builder = UriBuilder.fromUri(uriInfo.getBaseUri()) .path(SiteToSiteResource.class) .replaceQuery(uriInfo.getRequestUri().getRawQuery()); URI redirectTo = builder.build(); requestContext.setRequestUri(uriInfo.getBaseUri(), redirectTo); } }
RedirectResourceFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws IOException { final UriInfo uriInfo = requestContext.getUriInfo(); if (uriInfo.getPath().equals("controller")){ UriBuilder builder = UriBuilder.fromUri(uriInfo.getBaseUri()) .path(SiteToSiteResource.class) .replaceQuery(uriInfo.getRequestUri().getRawQuery()); URI redirectTo = builder.build(); requestContext.setRequestUri(uriInfo.getBaseUri(), redirectTo); } } }
RedirectResourceFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws IOException { final UriInfo uriInfo = requestContext.getUriInfo(); if (uriInfo.getPath().equals("controller")){ UriBuilder builder = UriBuilder.fromUri(uriInfo.getBaseUri()) .path(SiteToSiteResource.class) .replaceQuery(uriInfo.getRequestUri().getRawQuery()); URI redirectTo = builder.build(); requestContext.setRequestUri(uriInfo.getBaseUri(), redirectTo); } }  }
RedirectResourceFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws IOException { final UriInfo uriInfo = requestContext.getUriInfo(); if (uriInfo.getPath().equals("controller")){ UriBuilder builder = UriBuilder.fromUri(uriInfo.getBaseUri()) .path(SiteToSiteResource.class) .replaceQuery(uriInfo.getRequestUri().getRawQuery()); URI redirectTo = builder.build(); requestContext.setRequestUri(uriInfo.getBaseUri(), redirectTo); } }  @Override void filter(ContainerRequestContext requestContext); }
RedirectResourceFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws IOException { final UriInfo uriInfo = requestContext.getUriInfo(); if (uriInfo.getPath().equals("controller")){ UriBuilder builder = UriBuilder.fromUri(uriInfo.getBaseUri()) .path(SiteToSiteResource.class) .replaceQuery(uriInfo.getRequestUri().getRawQuery()); URI redirectTo = builder.build(); requestContext.setRequestUri(uriInfo.getBaseUri(), redirectTo); } }  @Override void filter(ContainerRequestContext requestContext);  }