Search in sources :

Example 66 with NotFoundException

use of javax.ws.rs.NotFoundException in project graylog2-server by Graylog2.

the class ClusterConfigResource method update.

@PUT
@Timed
@Path("{configClass}")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update configuration in database")
@RequiresPermissions({ RestPermissions.CLUSTER_CONFIG_ENTRY_CREATE, RestPermissions.CLUSTER_CONFIG_ENTRY_EDIT })
@AuditEvent(type = AuditEventTypes.CLUSTER_CONFIGURATION_UPDATE)
public Response update(@ApiParam(name = "configClass", value = "The name of the cluster configuration class", required = true) @PathParam("configClass") @NotBlank String configClass, @ApiParam(name = "body", value = "The payload of the cluster configuration", required = true) @NotNull InputStream body) throws IOException {
    final Class<?> cls = classFromName(configClass);
    if (cls == null) {
        throw new NotFoundException("Couldn't find configuration class \"" + configClass + "\"");
    }
    final Object o;
    try {
        o = objectMapper.readValue(body, cls);
    } catch (Exception e) {
        final String msg = "Couldn't parse cluster configuration \"" + configClass + "\".";
        LOG.error(msg, e);
        throw new BadRequestException(msg);
    }
    try {
        clusterConfigService.write(o);
    } catch (Exception e) {
        final String msg = "Couldn't write cluster config \"" + configClass + "\".";
        LOG.error(msg, e);
        throw new InternalServerErrorException(msg, e);
    }
    return Response.accepted(o).build();
}
Also used : NotFoundException(javax.ws.rs.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) IOException(java.io.IOException) NotFoundException(javax.ws.rs.NotFoundException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT)

Example 67 with NotFoundException

use of javax.ws.rs.NotFoundException in project graylog2-server by Graylog2.

the class LoggersResource method setSubsystemLoggerLevel.

@PUT
@Timed
@ApiOperation(value = "Set the loglevel of a whole subsystem", notes = "Provided level is falling back to DEBUG if it does not exist")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such subsystem.") })
@Path("/subsystems/{subsystem}/level/{level}")
@AuditEvent(type = AuditEventTypes.LOG_LEVEL_UPDATE)
public void setSubsystemLoggerLevel(@ApiParam(name = "subsystem", required = true) @PathParam("subsystem") @NotEmpty String subsystemTitle, @ApiParam(name = "level", required = true) @PathParam("level") @NotEmpty String level) {
    if (!SUBSYSTEMS.containsKey(subsystemTitle)) {
        final String msg = "No such logging subsystem: [" + subsystemTitle + "]";
        LOG.warn(msg);
        throw new NotFoundException(msg);
    }
    checkPermission(RestPermissions.LOGGERS_EDITSUBSYSTEM, subsystemTitle);
    final Subsystem subsystem = SUBSYSTEMS.get(subsystemTitle);
    final Level newLevel = Level.toLevel(level.toUpperCase(Locale.ENGLISH));
    setLoggerLevel(subsystem.getCategory(), newLevel);
    LOG.debug("Successfully set log level for subsystem \"{}\" to \"{}\"", subsystem.getTitle(), newLevel);
}
Also used : NotFoundException(javax.ws.rs.NotFoundException) Level(org.apache.logging.log4j.Level) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 68 with NotFoundException

use of javax.ws.rs.NotFoundException in project ddf by codice.

the class EndpointUtil method getMetacard.

public Metacard getMetacard(String id) throws UnsupportedQueryException, SourceUnavailableException, FederationException {
    Filter idFilter = filterBuilder.attribute(Metacard.ID).is().equalTo().text(id);
    Filter tagsFilter = filterBuilder.attribute(Metacard.TAGS).is().like().text("*");
    Filter filter = filterBuilder.allOf(idFilter, tagsFilter);
    QueryResponse queryResponse = catalogFramework.query(new QueryRequestImpl(new QueryImpl(filter), false));
    if (queryResponse.getResults().isEmpty()) {
        throw new NotFoundException("Could not find metacard for id: " + id);
    }
    Result result = queryResponse.getResults().get(0);
    return result.getMetacard();
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryResponse(ddf.catalog.operation.QueryResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) NotFoundException(javax.ws.rs.NotFoundException) Result(ddf.catalog.data.Result)

Aggregations

NotFoundException (javax.ws.rs.NotFoundException)68 Path (javax.ws.rs.Path)46 Timed (com.codahale.metrics.annotation.Timed)45 ApiOperation (io.swagger.annotations.ApiOperation)27 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)25 GET (javax.ws.rs.GET)22 ApiResponses (io.swagger.annotations.ApiResponses)20 DELETE (javax.ws.rs.DELETE)20 Produces (javax.ws.rs.Produces)18 AuditEvent (org.graylog2.audit.jersey.AuditEvent)16 HashMap (java.util.HashMap)15 PUT (javax.ws.rs.PUT)15 Group (keywhiz.api.model.Group)14 SanitizedSecret (keywhiz.api.model.SanitizedSecret)14 Event (keywhiz.log.Event)14 Consumes (javax.ws.rs.Consumes)12 Client (keywhiz.api.model.Client)11 POST (javax.ws.rs.POST)10 BadRequestException (javax.ws.rs.BadRequestException)9 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)9