Search in sources :

Example 66 with ApiResponse

use of io.swagger.annotations.ApiResponse in project indy by Commonjava.

the class FoloAdminResource method getRecord.

@ApiOperation("Alias of /{id}/record, returns the tracking record for the specified key")
@ApiResponses({ @ApiResponse(code = 404, message = "No such tracking record exists."), @ApiResponse(code = 200, message = "Tracking record", response = TrackedContentDTO.class) })
@Path("/{id}/record")
@GET
public Response getRecord(@ApiParam("User-assigned tracking session key") @PathParam("id") final String id, @Context final UriInfo uriInfo) {
    Response response;
    try {
        final String baseUrl = uriInfo.getBaseUriBuilder().path("api").build().toString();
        final TrackedContentDTO record = controller.getRecord(id, baseUrl);
        if (record == null) {
            response = Response.status(Status.NOT_FOUND).build();
        } else {
            response = responseHelper.formatOkResponseWithJsonEntity(record);
        }
    } catch (final IndyWorkflowException e) {
        logger.error(String.format("Failed to retrieve tracking report for: %s. Reason: %s", id, e.getMessage()), e);
        response = responseHelper.formatResponse(e);
    }
    return response;
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 67 with ApiResponse

use of io.swagger.annotations.ApiResponse in project graylog2-server by Graylog2.

the class IndexSetsResource method get.

@GET
@Path("{id}")
@Timed
@ApiOperation(value = "Get index set")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized"), @ApiResponse(code = 404, message = "Index set not found") })
public IndexSetSummary get(@ApiParam(name = "id", required = true) @PathParam("id") String id) {
    checkPermission(RestPermissions.INDEXSETS_READ, id);
    final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
    return indexSetService.get(id).map(config -> IndexSetSummary.fromIndexSetConfig(config, config.equals(defaultIndexSet))).orElseThrow(() -> new NotFoundException("Couldn't load index set with ID <" + id + ">"));
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Produces(javax.ws.rs.Produces) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) ClientErrorException(javax.ws.rs.ClientErrorException) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) ClusterConfigService(org.graylog2.plugin.cluster.ClusterConfigService) Consumes(javax.ws.rs.Consumes) Indices(org.graylog2.indexer.indices.Indices) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) BadRequestException(javax.ws.rs.BadRequestException) IndexSet(org.graylog2.indexer.IndexSet) IndexSetStats(org.graylog2.rest.resources.system.indexer.responses.IndexSetStats) DELETE(javax.ws.rs.DELETE) IndexSetStatsCreator(org.graylog2.indexer.IndexSetStatsCreator) Set(java.util.Set) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) SystemJobManager(org.graylog2.system.jobs.SystemJobManager) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) IndexSetService(org.graylog2.indexer.indexset.IndexSetService) Response(javax.ws.rs.core.Response) AuditEventTypes(org.graylog2.audit.AuditEventTypes) Optional(java.util.Optional) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) DuplicateKeyException(com.mongodb.DuplicateKeyException) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) IndexSetCleanupJob(org.graylog2.indexer.indices.jobs.IndexSetCleanupJob) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) IndexSetValidator(org.graylog2.indexer.IndexSetValidator) SystemJobConcurrencyException(org.graylog2.system.jobs.SystemJobConcurrencyException) Objects.requireNonNull(java.util.Objects.requireNonNull) AuditEvent(org.graylog2.audit.jersey.AuditEvent) IndexSetUpdateRequest(org.graylog2.rest.resources.system.indexer.requests.IndexSetUpdateRequest) IndexStatistics(org.graylog2.indexer.indices.stats.IndexStatistics) IndexSetResponse(org.graylog2.rest.resources.system.indexer.responses.IndexSetResponse) Api(io.swagger.annotations.Api) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) RestResource(org.graylog2.shared.rest.resources.RestResource) IndexSetSummary(org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary) ApiResponse(io.swagger.annotations.ApiResponse) RestPermissions(org.graylog2.shared.security.RestPermissions) PUT(javax.ws.rs.PUT) Collections(java.util.Collections) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) NotFoundException(javax.ws.rs.NotFoundException) 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)

Example 68 with ApiResponse

use of io.swagger.annotations.ApiResponse in project graylog2-server by Graylog2.

the class IndexSetsResource method list.

@GET
@Timed
@ApiOperation(value = "Get a list of all index sets")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized") })
public IndexSetResponse list(@ApiParam(name = "skip", value = "The number of elements to skip (offset).", required = true) @QueryParam("skip") @DefaultValue("0") int skip, @ApiParam(name = "limit", value = "The maximum number of elements to return.", required = true) @QueryParam("limit") @DefaultValue("0") int limit, @ApiParam(name = "stats", value = "Include index set stats.") @QueryParam("stats") @DefaultValue("false") boolean computeStats) {
    final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
    List<IndexSetSummary> indexSets;
    int count;
    if (limit > 0) {
        // First collect all index set ids the user is allowed to see.
        final Set<String> allowedIds = indexSetService.findAll().stream().filter(indexSet -> isPermitted(RestPermissions.INDEXSETS_READ, indexSet.id())).map(IndexSetConfig::id).collect(Collectors.toSet());
        indexSets = indexSetService.findPaginated(allowedIds, limit, skip).stream().map(config -> IndexSetSummary.fromIndexSetConfig(config, config.equals(defaultIndexSet))).collect(Collectors.toList());
        count = allowedIds.size();
    } else {
        indexSets = indexSetService.findAll().stream().filter(indexSetConfig -> isPermitted(RestPermissions.INDEXSETS_READ, indexSetConfig.id())).map(config -> IndexSetSummary.fromIndexSetConfig(config, config.equals(defaultIndexSet))).collect(Collectors.toList());
        count = indexSets.size();
    }
    final Map<String, IndexSetStats> stats;
    if (computeStats) {
        stats = indexSetRegistry.getAll().stream().collect(Collectors.toMap(indexSet -> indexSet.getConfig().id(), indexSetStatsCreator::getForIndexSet));
    } else {
        stats = Collections.emptyMap();
    }
    return IndexSetResponse.create(count, indexSets, stats);
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Produces(javax.ws.rs.Produces) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) ClientErrorException(javax.ws.rs.ClientErrorException) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) ClusterConfigService(org.graylog2.plugin.cluster.ClusterConfigService) Consumes(javax.ws.rs.Consumes) Indices(org.graylog2.indexer.indices.Indices) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) BadRequestException(javax.ws.rs.BadRequestException) IndexSet(org.graylog2.indexer.IndexSet) IndexSetStats(org.graylog2.rest.resources.system.indexer.responses.IndexSetStats) DELETE(javax.ws.rs.DELETE) IndexSetStatsCreator(org.graylog2.indexer.IndexSetStatsCreator) Set(java.util.Set) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) SystemJobManager(org.graylog2.system.jobs.SystemJobManager) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) IndexSetService(org.graylog2.indexer.indexset.IndexSetService) Response(javax.ws.rs.core.Response) AuditEventTypes(org.graylog2.audit.AuditEventTypes) Optional(java.util.Optional) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) DuplicateKeyException(com.mongodb.DuplicateKeyException) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) IndexSetCleanupJob(org.graylog2.indexer.indices.jobs.IndexSetCleanupJob) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) IndexSetValidator(org.graylog2.indexer.IndexSetValidator) SystemJobConcurrencyException(org.graylog2.system.jobs.SystemJobConcurrencyException) Objects.requireNonNull(java.util.Objects.requireNonNull) AuditEvent(org.graylog2.audit.jersey.AuditEvent) IndexSetUpdateRequest(org.graylog2.rest.resources.system.indexer.requests.IndexSetUpdateRequest) IndexStatistics(org.graylog2.indexer.indices.stats.IndexStatistics) IndexSetResponse(org.graylog2.rest.resources.system.indexer.responses.IndexSetResponse) Api(io.swagger.annotations.Api) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) RestResource(org.graylog2.shared.rest.resources.RestResource) IndexSetSummary(org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary) ApiResponse(io.swagger.annotations.ApiResponse) RestPermissions(org.graylog2.shared.security.RestPermissions) PUT(javax.ws.rs.PUT) Collections(java.util.Collections) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) IndexSetStats(org.graylog2.rest.resources.system.indexer.responses.IndexSetStats) IndexSetSummary(org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 69 with ApiResponse

use of io.swagger.annotations.ApiResponse in project graylog2-server by Graylog2.

the class Generator method determineResponses.

private List<Map<String, Object>> determineResponses(Method method) {
    final List<Map<String, Object>> result = Lists.newArrayList();
    final ApiResponses annotation = method.getAnnotation(ApiResponses.class);
    if (null != annotation) {
        for (ApiResponse response : annotation.value()) {
            final Map<String, Object> responseDescription = ImmutableMap.<String, Object>of("code", response.code(), "message", response.message());
            result.add(responseDescription);
        }
    }
    return result;
}
Also used : Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) ApiResponses(io.swagger.annotations.ApiResponses) ApiResponse(io.swagger.annotations.ApiResponse)

Example 70 with ApiResponse

use of io.swagger.annotations.ApiResponse in project java-chassis by ServiceComb.

the class MultiErrorCodeService method errorCodeWithHeader.

@Path("/errorCodeWithHeader")
@POST
@ApiResponses({ @ApiResponse(code = 200, response = MultiResponse200.class, message = ""), @ApiResponse(code = 400, response = MultiResponse400.class, message = ""), @ApiResponse(code = 500, response = MultiResponse500.class, message = "") })
@ResponseHeaders({ @ResponseHeader(name = "x-code", response = String.class) })
public Response errorCodeWithHeader(MultiRequest request) {
    Response response = new Response();
    if (request.getCode() == 400) {
        MultiResponse400 r = new MultiResponse400();
        r.setCode(400);
        r.setMessage("bad request");
        response.setStatus(Status.BAD_REQUEST);
        // If got many types for different status code, we can only using InvocationException for failed error code like 400-500.
        // The result for Failed Family(e.g. 400-500), can not set return value as target type directly or will give exception.
        response.setResult(new InvocationException(Status.BAD_REQUEST, r));
        response.setHeader("x-code", "400");
    } else if (request.getCode() == 500) {
        MultiResponse500 r = new MultiResponse500();
        r.setCode(500);
        r.setMessage("internal error");
        response.setStatus(Status.INTERNAL_SERVER_ERROR);
        response.setResult(new InvocationException(Status.INTERNAL_SERVER_ERROR, r));
        response.setHeader("x-code", "500");
    } else {
        MultiResponse200 r = new MultiResponse200();
        r.setCode(200);
        r.setMessage("success result");
        response.setStatus(Status.OK);
        // If error code is OK family(like 200), we can use the target type.
        response.setResult(r);
        response.setHeader("x-code", "200");
    }
    return response;
}
Also used : ApiResponse(io.swagger.annotations.ApiResponse) Response(org.apache.servicecomb.swagger.invocation.Response) MultiResponse200(org.apache.servicecomb.demo.multiErrorCode.MultiResponse200) MultiResponse400(org.apache.servicecomb.demo.multiErrorCode.MultiResponse400) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) MultiResponse500(org.apache.servicecomb.demo.multiErrorCode.MultiResponse500) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ResponseHeaders(org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ApiResponse (io.swagger.annotations.ApiResponse)156 ApiOperation (io.swagger.annotations.ApiOperation)130 Path (javax.ws.rs.Path)124 Response (javax.ws.rs.core.Response)120 ApiResponses (io.swagger.annotations.ApiResponses)116 GET (javax.ws.rs.GET)93 Produces (javax.ws.rs.Produces)83 Api (io.swagger.annotations.Api)64 Consumes (javax.ws.rs.Consumes)60 POST (javax.ws.rs.POST)58 PathParam (javax.ws.rs.PathParam)58 DELETE (javax.ws.rs.DELETE)55 QueryParam (javax.ws.rs.QueryParam)46 List (java.util.List)45 Inject (javax.inject.Inject)45 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)45 ApiParam (io.swagger.annotations.ApiParam)44 Collectors (java.util.stream.Collectors)42 Logger (org.slf4j.Logger)42 LoggerFactory (org.slf4j.LoggerFactory)42