Search in sources :

Example 1 with NotFoundException

use of jakarta.ws.rs.NotFoundException in project metrics by dropwizard.

the class SingletonMetricsJerseyTest method testResourceNotFound.

@Test
public void testResourceNotFound() {
    final Response response = target().path("not-found").request().get();
    assertThat(response.getStatus()).isEqualTo(404);
    try {
        target().path("not-found").request().get(ClientResponse.class);
        failBecauseExceptionWasNotThrown(NotFoundException.class);
    } catch (NotFoundException e) {
        assertThat(e.getMessage()).isEqualTo("HTTP 404 Not Found");
    }
}
Also used : Response(jakarta.ws.rs.core.Response) ClientResponse(org.glassfish.jersey.client.ClientResponse) NotFoundException(jakarta.ws.rs.NotFoundException) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 2 with NotFoundException

use of jakarta.ws.rs.NotFoundException in project OpenGrok by OpenGrok.

the class ProjectsController method markIndexed.

@PUT
@Path("/{project}/indexed")
@Consumes(MediaType.TEXT_PLAIN)
public Response markIndexed(@Context HttpServletRequest request, @PathParam("project") String projectNameParam) {
    // Avoid classification as a taint bug.
    final String projectName = Laundromat.launderInput(projectNameParam);
    Project project = env.getProjects().get(projectName);
    if (project == null) {
        LOGGER.log(Level.WARNING, "cannot find project {0} to mark as indexed", projectName);
        throw new NotFoundException(String.format("project '%s' does not exist", projectName));
    }
    project.setIndexed(true);
    return ApiTaskManager.getInstance().submitApiTask(PROJECTS_PATH, new ApiTask(request.getRequestURI(), () -> {
        // Refresh current version of the project's repositories.
        List<RepositoryInfo> riList = env.getProjectRepositoriesMap().get(project);
        if (riList != null) {
            for (RepositoryInfo ri : riList) {
                Repository repo = getRepository(ri, CommandTimeoutType.RESTFUL);
                if (repo != null && repo.getCurrentVersion() != null && repo.getCurrentVersion().length() > 0) {
                    // getRepository() always creates fresh instance
                    // of the Repository object so there is no need
                    // to call setCurrentVersion() on it.
                    ri.setCurrentVersion(repo.determineCurrentVersion());
                }
            }
        }
        CompletableFuture.runAsync(() -> suggester.rebuild(projectName));
        // In case this project has just been incrementally indexed,
        // its IndexSearcher needs a poke.
        env.maybeRefreshIndexSearchers(Collections.singleton(projectName));
        env.refreshDateForLastIndexRun();
        return null;
    }));
}
Also used : Project(org.opengrok.indexer.configuration.Project) Repository(org.opengrok.indexer.history.Repository) RepositoryFactory.getRepository(org.opengrok.indexer.history.RepositoryFactory.getRepository) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) NotFoundException(jakarta.ws.rs.NotFoundException) ArrayList(java.util.ArrayList) List(java.util.List) ApiTask(org.opengrok.web.api.ApiTask) Path(jakarta.ws.rs.Path) Consumes(jakarta.ws.rs.Consumes) PUT(jakarta.ws.rs.PUT)

Aggregations

NotFoundException (jakarta.ws.rs.NotFoundException)2 Consumes (jakarta.ws.rs.Consumes)1 PUT (jakarta.ws.rs.PUT)1 Path (jakarta.ws.rs.Path)1 Response (jakarta.ws.rs.core.Response)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ClientResponse (org.glassfish.jersey.client.ClientResponse)1 JerseyTest (org.glassfish.jersey.test.JerseyTest)1 Test (org.junit.Test)1 Project (org.opengrok.indexer.configuration.Project)1 Repository (org.opengrok.indexer.history.Repository)1 RepositoryFactory.getRepository (org.opengrok.indexer.history.RepositoryFactory.getRepository)1 RepositoryInfo (org.opengrok.indexer.history.RepositoryInfo)1 ApiTask (org.opengrok.web.api.ApiTask)1