@Test public void testController() throws Exception { ContainerRequest request = mock(ContainerRequest.class); String path = "controller"; String baseUri = "http: when(request.getPath()).thenReturn(path); when(request.getBaseUri()).thenReturn(new URI(baseUri)); when(request.getRequestUri()).thenReturn(new URI(baseUri + path)); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { assertEquals("base uri should be retained", new URI(baseUri), invocation.getArguments()[0]); assertEquals("request uri should be redirected", new URI(baseUri + "site-to-site"), invocation.getArguments()[1]); return null; } }).when(request).setUris(any(URI.class), any(URI.class)); RedirectResourceFilter filter = new RedirectResourceFilter(); filter.filter(request); }
@Override public ContainerRequest filter(ContainerRequest containerRequest) { if(containerRequest.getPath().equals("controller")){ UriBuilder builder = UriBuilder.fromUri(containerRequest.getBaseUri()) .path(SiteToSiteResource.class) .replaceQuery(containerRequest.getRequestUri().getRawQuery()); URI redirectTo = builder.build(); containerRequest.setUris(containerRequest.getBaseUri(), redirectTo); } return containerRequest; }
RedirectResourceFilter implements ContainerRequestFilter { @Override public ContainerRequest filter(ContainerRequest containerRequest) { if(containerRequest.getPath().equals("controller")){ UriBuilder builder = UriBuilder.fromUri(containerRequest.getBaseUri()) .path(SiteToSiteResource.class) .replaceQuery(containerRequest.getRequestUri().getRawQuery()); URI redirectTo = builder.build(); containerRequest.setUris(containerRequest.getBaseUri(), redirectTo); } return containerRequest; } }
RedirectResourceFilter implements ContainerRequestFilter { @Override public ContainerRequest filter(ContainerRequest containerRequest) { if(containerRequest.getPath().equals("controller")){ UriBuilder builder = UriBuilder.fromUri(containerRequest.getBaseUri()) .path(SiteToSiteResource.class) .replaceQuery(containerRequest.getRequestUri().getRawQuery()); URI redirectTo = builder.build(); containerRequest.setUris(containerRequest.getBaseUri(), redirectTo); } return containerRequest; }  }
RedirectResourceFilter implements ContainerRequestFilter { @Override public ContainerRequest filter(ContainerRequest containerRequest) { if(containerRequest.getPath().equals("controller")){ UriBuilder builder = UriBuilder.fromUri(containerRequest.getBaseUri()) .path(SiteToSiteResource.class) .replaceQuery(containerRequest.getRequestUri().getRawQuery()); URI redirectTo = builder.build(); containerRequest.setUris(containerRequest.getBaseUri(), redirectTo); } return containerRequest; }  @Override ContainerRequest filter(ContainerRequest containerRequest); }
RedirectResourceFilter implements ContainerRequestFilter { @Override public ContainerRequest filter(ContainerRequest containerRequest) { if(containerRequest.getPath().equals("controller")){ UriBuilder builder = UriBuilder.fromUri(containerRequest.getBaseUri()) .path(SiteToSiteResource.class) .replaceQuery(containerRequest.getRequestUri().getRawQuery()); URI redirectTo = builder.build(); containerRequest.setUris(containerRequest.getBaseUri(), redirectTo); } return containerRequest; }  @Override ContainerRequest filter(ContainerRequest containerRequest);  }