@GET @Path("/{id}") @RequiresPermissions(SidecarRestPermissions.CONFIGURATIONS_READ) @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Show configuration details") public Configuration getConfigurations(@ApiParam(name = "id", required = true) @PathParam("id") String id) { final Configuration configuration = this.configurationService.find(id); if (configuration == null) { throw new NotFoundException("Could not find Configuration <" + id + ">."); } return configuration; }
@Provider public class BadURIExceptionMapper implements ExceptionMapper<NotFoundException> { public Response toResponse(NotFoundException exception){ return Response.status(Response.Status.NOT_FOUND). entity(new ErrorResponse(exception.getClass().toString(), exception.getMessage()) ). build(); } }
@Path("assets/plugin/{plugin}/{filename}") @GET public Response get(@Context Request request, @PathParam("plugin") String pluginName, @PathParam("filename") String filename) { final Plugin plugin = getPluginForName(pluginName) .orElseThrow(() -> new NotFoundException("Couldn't find plugin " + pluginName)); try { final URL resourceUrl = getResourceUri(true, filename, plugin.metadata().getClass()); return getResponse(request, filename, resourceUrl, true); } catch (URISyntaxException | IOException e) { throw new NotFoundException("Couldn't find " + filename + " in plugin " + pluginName, e); } }
@GET @Timed @ApiOperation(value = "Get overview of current indexing state, including deflector config, cluster state, index ranges & message counts.") @Produces(MediaType.APPLICATION_JSON) @Deprecated public IndexerOverview index() throws TooManyAliasesException { if (!cluster.isConnected()) { throw new ServiceUnavailableException("Elasticsearch cluster is not available, check your configuration and logs for more information."); } try { return getIndexerOverview(indexSetRegistry.getDefault()); } catch (IllegalStateException e) { throw new NotFoundException("Default index set not found"); } }
private Person findSafely(long personId) { return peopleDAO.findById(personId).orElseThrow(() -> new NotFoundException("No such user.")); } }
/** * Construct a new "not found" exception. * * @param response error response. * @throws IllegalArgumentException in case the status code set in the response * is not HTTP {@code 404}. */ public NotFoundException(Response response) { super(validate(response, Response.Status.NOT_FOUND)); }
@Override public Response toResponse(NotFoundException exception) { // if there is an optional exception message, we add it to the response if (exception.getMessage() != null) { return Response.status(Response.Status.NOT_FOUND).entity(exception.getMessage()).build(); } return Response.status(Response.Status.NOT_FOUND).build(); } }
@Path("process/{id}") @Produces(MediaType.SERVER_SENT_EVENTS) @GET public void getProgress(@PathParam("id") int id, @DefaultValue("false") @QueryParam("testSource") boolean testSource, @Context SseEventSink eventSink) { final Process process = processes.get(id); if (process != null) { if (testSource) { process.release(); } process.getBroadcaster().register(eventSink); } else { throw new NotFoundException(); } }
private User loadUser(String username) { final User user = userService.load(username); if (user == null) { throw new NotFoundException("Unknown user " + username); } return user; }
/** * Construct a new "not found" exception. * * @param response error response. * @param cause the underlying cause of the exception. * @throws IllegalArgumentException in case the status code set in the response * is not HTTP {@code 404}. */ public NotFoundException(Response response, Throwable cause) { super(validate(response, Response.Status.NOT_FOUND), cause); }
@Override public Response toResponse(NotFoundException exception) { // if there is an optional exception message, we add it to the response if (exception.getMessage() != null) { return Response.status(Response.Status.NOT_FOUND).entity(exception.getMessage()).build(); } return Response.status(Response.Status.NOT_FOUND).build(); } }
@GET @Path("/{id}") @RequiresPermissions(SidecarRestPermissions.COLLECTORS_READ) @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Show collector details") public Collector getCollector(@ApiParam(name = "id", required = true) @PathParam("id") String id) { final Collector collector = this.collectorService.find(id); if (collector == null) { throw new NotFoundException("Cound not find collector <" + id + ">."); } return collector; }
@Path("process/{id}") @Produces(SseFeature.SERVER_SENT_EVENTS) @GET public EventOutput getProgress(@PathParam("id") int id, @DefaultValue("false") @QueryParam("testSource") boolean testSource) { final Process process = processes.get(id); if (process != null) { if (testSource) { process.release(); } final EventOutput eventOutput = new EventOutput(); process.getBroadcaster().add(eventOutput); return eventOutput; } else { throw new NotFoundException(); } }
protected IndexSet getIndexSet(final IndexSetRegistry indexSetRegistry, final String indexSetId) { return indexSetRegistry.get(indexSetId) .orElseThrow(() -> new NotFoundException("Index set <" + indexSetId + "> not found.")); } }
/** * Construct a new "not found" exception. * * @param response error response. * @throws IllegalArgumentException in case the status code set in the response * is not HTTP {@code 404}. */ public NotFoundException(Response response) { super(validate(response, Response.Status.NOT_FOUND)); }
@Override public Response toResponse(NotFoundException e) { return Response.status(Status.NOT_FOUND) .entity(e.getMessage()) .type(MediaType.TEXT_PLAIN) .build(); }
@GET @Timed @Path("/{index}") @ApiOperation(value = "Get information of an index and its shards.") @Produces(MediaType.APPLICATION_JSON) public IndexInfo single(@ApiParam(name = "index") @PathParam("index") String index) { checkPermission(RestPermissions.INDICES_READ, index); if (!indexSetRegistry.isManagedIndex(index)) { final String msg = "Index [" + index + "] doesn't look like an index managed by Graylog."; LOG.info(msg); throw new NotFoundException(msg); } return indices.getIndexStats(index) .map(this::toIndexInfo) .orElseThrow(() -> new NotFoundException("Index [" + index + "] not found.")); }
@GET() @Path("/song/{id}") @Produces(MediaType.APPLICATION_JSON) public SongBean song(@PathParam("id") Long songId) { final ReadOnlyKeyValueStore<Long, Song> songStore = streams.store(KafkaMusicExample.ALL_SONGS, QueryableStoreTypes.<Long, Song>keyValueStore()); final Song song = songStore.get(songId); if (song == null) { throw new NotFoundException(String.format("Song with id [%d] was not found", songId)); } return new SongBean(song.getArtist(), song.getAlbum(), song.getName()); }
private ConfigurationVariable findVariableOrFail(String id) { final ConfigurationVariable configurationVariable = configurationVariableService.find(id); if (configurationVariable == null) { throw new NotFoundException("Could not find ConfigurationVariable <" + id + ">."); } return configurationVariable; }
/** * Construct a new "not found" exception. * * @param message the detail message (which is saved for later retrieval * by the {@link #getMessage()} method). * @param response error response. * @throws IllegalArgumentException in case the status code set in the response * is not HTTP {@code 404}. */ public NotFoundException(String message, Response response) { super(message, validate(response, Response.Status.NOT_FOUND)); }