Search in sources :

Example 1 with DocumentNotFoundException

use of org.graylog2.indexer.messages.DocumentNotFoundException in project graylog2-server by Graylog2.

the class MessageResource method search.

@GET
@Path("/{index}/{messageId}")
@Timed
@ApiOperation(value = "Get a single message.")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Specified index does not exist."), @ApiResponse(code = 404, message = "Message does not exist.") })
public ResultMessage search(@ApiParam(name = "index", value = "The index this message is stored in.", required = true) @PathParam("index") String index, @ApiParam(name = "messageId", required = true) @PathParam("messageId") String messageId) {
    checkPermission(RestPermissions.MESSAGES_READ, messageId);
    try {
        final ResultMessage resultMessage = messages.get(messageId, index);
        final Message message = resultMessage.getMessage();
        checkMessageReadPermission(message);
        return resultMessage;
    } catch (IndexNotFoundException e) {
        final String msg = "Index " + e.getIndex() + " does not exist.";
        LOG.error(msg, e);
        throw new NotFoundException(msg, e);
    } catch (DocumentNotFoundException e) {
        final String msg = "Message " + messageId + " does not exist in index " + index;
        LOG.error(msg, e);
        throw new NotFoundException(msg, e);
    }
}
Also used : ResultMessage(org.graylog2.indexer.results.ResultMessage) RawMessage(org.graylog2.plugin.journal.RawMessage) Message(org.graylog2.plugin.Message) DocumentNotFoundException(org.graylog2.indexer.messages.DocumentNotFoundException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) DocumentNotFoundException(org.graylog2.indexer.messages.DocumentNotFoundException) ResultMessage(org.graylog2.indexer.results.ResultMessage) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 GET (javax.ws.rs.GET)1 NotFoundException (javax.ws.rs.NotFoundException)1 Path (javax.ws.rs.Path)1 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)1 DocumentNotFoundException (org.graylog2.indexer.messages.DocumentNotFoundException)1 ResultMessage (org.graylog2.indexer.results.ResultMessage)1 Message (org.graylog2.plugin.Message)1 RawMessage (org.graylog2.plugin.journal.RawMessage)1