@Test public void validateRootRequestWithoutTrailingSlash() throws Exception { when(uriInfo.getAbsolutePath()).thenReturn( UriBuilder.fromPath(URL_PREFIX + "central").build()); Response response = underTest.getHtml(REPOSITORY_NAME, "", uriInfo); assertThat(response.getStatus(), is(303)); assertThat(response.getHeaders().get("location").get(0).toString(), is(URL_PREFIX + "central/")); }
@GET public Response getHtml(@PathParam("repositoryName") final String repositoryName, @PathParam("repositoryPath") final String repositoryPath, @Context final UriInfo uriInfo) { log.debug("Get HTML directory listing for repository {} on path {}", repositoryName, repositoryPath); if (!uriInfo.getAbsolutePath().toString().endsWith("/")) { log.debug("Request does include a trailing slash, redirecting to include it"); return Response.seeOther(UriBuilder.fromUri(uriInfo.getAbsolutePath()).path("/").build()).build(); } Repository repository = repositoryManager.get(repositoryName); if (repository == null) { throw createNotFoundException(repositoryName, null); } List<String> pathSegments = new ArrayList<>(); if (!isRoot(repositoryPath)) { pathSegments = asList(repositoryPath.split("/")); } Iterable<BrowseNode> browseNodes = browseNodeQueryService.getByPath(repository, pathSegments, configuration.getMaxHtmlNodes()); final boolean permitted = securityHelper.allPermitted(new RepositoryViewPermission(repository, BROWSE)); final boolean hasChildren = browseNodes != null && !Iterables.isEmpty(browseNodes); final List<BrowseListItem> listItems = hasChildren ? browseNodeQueryService.toListItems(repository, browseNodes) : Collections.emptyList(); if (hasChildren || (isRoot(repositoryPath) && permitted)) { return Response .ok(templateHelper.render(template, initializeTemplateParameters(repositoryName, repositoryPath, listItems))) .build(); } throw createNotFoundException(repositoryName, permitted ? repositoryPath : null); }
RepositoryBrowseResource extends ComponentSupport implements Resource { @GET public Response getHtml(@PathParam("repositoryName") final String repositoryName, @PathParam("repositoryPath") final String repositoryPath, @Context final UriInfo uriInfo) { log.debug("Get HTML directory listing for repository {} on path {}", repositoryName, repositoryPath); if (!uriInfo.getAbsolutePath().toString().endsWith("/")) { log.debug("Request does include a trailing slash, redirecting to include it"); return Response.seeOther(UriBuilder.fromUri(uriInfo.getAbsolutePath()).path("/").build()).build(); } Repository repository = repositoryManager.get(repositoryName); if (repository == null) { throw createNotFoundException(repositoryName, null); } List<String> pathSegments = new ArrayList<>(); if (!isRoot(repositoryPath)) { pathSegments = asList(repositoryPath.split("/")); } Iterable<BrowseNode> browseNodes = browseNodeQueryService.getByPath(repository, pathSegments, configuration.getMaxHtmlNodes()); final boolean permitted = securityHelper.allPermitted(new RepositoryViewPermission(repository, BROWSE)); final boolean hasChildren = browseNodes != null && !Iterables.isEmpty(browseNodes); final List<BrowseListItem> listItems = hasChildren ? browseNodeQueryService.toListItems(repository, browseNodes) : Collections.emptyList(); if (hasChildren || (isRoot(repositoryPath) && permitted)) { return Response .ok(templateHelper.render(template, initializeTemplateParameters(repositoryName, repositoryPath, listItems))) .build(); } throw createNotFoundException(repositoryName, permitted ? repositoryPath : null); } }
RepositoryBrowseResource extends ComponentSupport implements Resource { @GET public Response getHtml(@PathParam("repositoryName") final String repositoryName, @PathParam("repositoryPath") final String repositoryPath, @Context final UriInfo uriInfo) { log.debug("Get HTML directory listing for repository {} on path {}", repositoryName, repositoryPath); if (!uriInfo.getAbsolutePath().toString().endsWith("/")) { log.debug("Request does include a trailing slash, redirecting to include it"); return Response.seeOther(UriBuilder.fromUri(uriInfo.getAbsolutePath()).path("/").build()).build(); } Repository repository = repositoryManager.get(repositoryName); if (repository == null) { throw createNotFoundException(repositoryName, null); } List<String> pathSegments = new ArrayList<>(); if (!isRoot(repositoryPath)) { pathSegments = asList(repositoryPath.split("/")); } Iterable<BrowseNode> browseNodes = browseNodeQueryService.getByPath(repository, pathSegments, configuration.getMaxHtmlNodes()); final boolean permitted = securityHelper.allPermitted(new RepositoryViewPermission(repository, BROWSE)); final boolean hasChildren = browseNodes != null && !Iterables.isEmpty(browseNodes); final List<BrowseListItem> listItems = hasChildren ? browseNodeQueryService.toListItems(repository, browseNodes) : Collections.emptyList(); if (hasChildren || (isRoot(repositoryPath) && permitted)) { return Response .ok(templateHelper.render(template, initializeTemplateParameters(repositoryName, repositoryPath, listItems))) .build(); } throw createNotFoundException(repositoryName, permitted ? repositoryPath : null); } @Inject  RepositoryBrowseResource(
      final RepositoryManager repositoryManager,
      final BrowseNodeQueryService browseNodeQueryService,
      final BrowseNodeConfiguration configuration,
      final TemplateHelper templateHelper,
      final SecurityHelper securityHelper); }
RepositoryBrowseResource extends ComponentSupport implements Resource { @GET public Response getHtml(@PathParam("repositoryName") final String repositoryName, @PathParam("repositoryPath") final String repositoryPath, @Context final UriInfo uriInfo) { log.debug("Get HTML directory listing for repository {} on path {}", repositoryName, repositoryPath); if (!uriInfo.getAbsolutePath().toString().endsWith("/")) { log.debug("Request does include a trailing slash, redirecting to include it"); return Response.seeOther(UriBuilder.fromUri(uriInfo.getAbsolutePath()).path("/").build()).build(); } Repository repository = repositoryManager.get(repositoryName); if (repository == null) { throw createNotFoundException(repositoryName, null); } List<String> pathSegments = new ArrayList<>(); if (!isRoot(repositoryPath)) { pathSegments = asList(repositoryPath.split("/")); } Iterable<BrowseNode> browseNodes = browseNodeQueryService.getByPath(repository, pathSegments, configuration.getMaxHtmlNodes()); final boolean permitted = securityHelper.allPermitted(new RepositoryViewPermission(repository, BROWSE)); final boolean hasChildren = browseNodes != null && !Iterables.isEmpty(browseNodes); final List<BrowseListItem> listItems = hasChildren ? browseNodeQueryService.toListItems(repository, browseNodes) : Collections.emptyList(); if (hasChildren || (isRoot(repositoryPath) && permitted)) { return Response .ok(templateHelper.render(template, initializeTemplateParameters(repositoryName, repositoryPath, listItems))) .build(); } throw createNotFoundException(repositoryName, permitted ? repositoryPath : null); } @Inject  RepositoryBrowseResource(
      final RepositoryManager repositoryManager,
      final BrowseNodeQueryService browseNodeQueryService,
      final BrowseNodeConfiguration configuration,
      final TemplateHelper templateHelper,
      final SecurityHelper securityHelper); @GET Response getHtml(@PathParam("repositoryName") final String repositoryName,
                          @PathParam("repositoryPath") final String repositoryPath,
                          @Context final UriInfo uriInfo); }
RepositoryBrowseResource extends ComponentSupport implements Resource { @GET public Response getHtml(@PathParam("repositoryName") final String repositoryName, @PathParam("repositoryPath") final String repositoryPath, @Context final UriInfo uriInfo) { log.debug("Get HTML directory listing for repository {} on path {}", repositoryName, repositoryPath); if (!uriInfo.getAbsolutePath().toString().endsWith("/")) { log.debug("Request does include a trailing slash, redirecting to include it"); return Response.seeOther(UriBuilder.fromUri(uriInfo.getAbsolutePath()).path("/").build()).build(); } Repository repository = repositoryManager.get(repositoryName); if (repository == null) { throw createNotFoundException(repositoryName, null); } List<String> pathSegments = new ArrayList<>(); if (!isRoot(repositoryPath)) { pathSegments = asList(repositoryPath.split("/")); } Iterable<BrowseNode> browseNodes = browseNodeQueryService.getByPath(repository, pathSegments, configuration.getMaxHtmlNodes()); final boolean permitted = securityHelper.allPermitted(new RepositoryViewPermission(repository, BROWSE)); final boolean hasChildren = browseNodes != null && !Iterables.isEmpty(browseNodes); final List<BrowseListItem> listItems = hasChildren ? browseNodeQueryService.toListItems(repository, browseNodes) : Collections.emptyList(); if (hasChildren || (isRoot(repositoryPath) && permitted)) { return Response .ok(templateHelper.render(template, initializeTemplateParameters(repositoryName, repositoryPath, listItems))) .build(); } throw createNotFoundException(repositoryName, permitted ? repositoryPath : null); } @Inject  RepositoryBrowseResource(
      final RepositoryManager repositoryManager,
      final BrowseNodeQueryService browseNodeQueryService,
      final BrowseNodeConfiguration configuration,
      final TemplateHelper templateHelper,
      final SecurityHelper securityHelper); @GET Response getHtml(@PathParam("repositoryName") final String repositoryName,
                          @PathParam("repositoryPath") final String repositoryPath,
                          @Context final UriInfo uriInfo); static final String RESOURCE_URI; }