Search in sources :

Example 11 with QueryParam

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

the class MessageResource method analyze.

@GET
@Path("/{index}/analyze")
@Timed
@ApiOperation(value = "Analyze a message string", notes = "Returns what tokens/terms a message string (message or full_message) is split to.")
@RequiresPermissions(RestPermissions.MESSAGES_ANALYZE)
@ApiResponses(value = { @ApiResponse(code = 404, message = "Specified index does not exist.") })
public MessageTokens analyze(@ApiParam(name = "index", value = "The index the message containing the string is stored in.", required = true) @PathParam("index") String index, @ApiParam(name = "analyzer", value = "The analyzer to use.") @QueryParam("analyzer") @Nullable String analyzer, @ApiParam(name = "string", value = "The string to analyze.", required = true) @QueryParam("string") @NotEmpty String string) {
    final String indexAnalyzer = indexSetRegistry.getForIndex(index).map(indexSet -> indexSet.getConfig().indexAnalyzer()).orElse("standard");
    final String messageAnalyzer = analyzer == null ? indexAnalyzer : analyzer;
    try {
        return MessageTokens.create(messages.analyze(string, index, messageAnalyzer));
    } catch (IndexNotFoundException e) {
        final String message = "Index " + index + " does not exist.";
        LOG.error(message, e);
        throw new NotFoundException(message);
    }
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) PathParam(javax.ws.rs.PathParam) UUID(com.eaio.uuid.UUID) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Tools(org.graylog2.plugin.Tools) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) MessageTokens(org.graylog2.rest.models.messages.responses.MessageTokens) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) ApiResponses(io.swagger.annotations.ApiResponses) CodecFactory(org.graylog2.inputs.codecs.CodecFactory) MessageParseRequest(org.graylog2.rest.models.messages.requests.MessageParseRequest) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) ResolvableInetSocketAddress(org.graylog2.plugin.ResolvableInetSocketAddress) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) ResultMessage(org.graylog2.indexer.results.ResultMessage) Consumes(javax.ws.rs.Consumes) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Objects.requireNonNull(java.util.Objects.requireNonNull) RawMessage(org.graylog2.plugin.journal.RawMessage) Messages(org.graylog2.indexer.messages.Messages) BadRequestException(javax.ws.rs.BadRequestException) Api(io.swagger.annotations.Api) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) Nullable(javax.annotation.Nullable) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) ForbiddenException(javax.ws.rs.ForbiddenException) RestResource(org.graylog2.shared.rest.resources.RestResource) InetSocketAddress(java.net.InetSocketAddress) NotFoundException(javax.ws.rs.NotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) Timed(com.codahale.metrics.annotation.Timed) Codec(org.graylog2.plugin.inputs.codecs.Codec) ApiResponse(io.swagger.annotations.ApiResponse) RestPermissions(org.graylog2.shared.security.RestPermissions) NotEmpty(org.hibernate.validator.constraints.NotEmpty) InetAddresses(com.google.common.net.InetAddresses) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) 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) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 12 with QueryParam

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

the class Generator method determineParameters.

private List<Parameter> determineParameters(Method method) {
    final List<Parameter> params = Lists.newArrayList();
    int i = 0;
    for (Annotation[] annotations : method.getParameterAnnotations()) {
        final Parameter param = new Parameter();
        Parameter.Kind paramKind = Parameter.Kind.BODY;
        for (Annotation annotation : annotations) {
            if (annotation instanceof ApiParam) {
                final ApiParam apiParam = (ApiParam) annotation;
                param.setName(apiParam.name());
                param.setDescription(apiParam.value());
                param.setIsRequired(apiParam.required());
                param.setType(method.getGenericParameterTypes()[i]);
                if (!isNullOrEmpty(apiParam.defaultValue())) {
                    param.setDefaultValue(apiParam.defaultValue());
                }
            }
            if (annotation instanceof DefaultValue) {
                final DefaultValue defaultValueAnnotation = (DefaultValue) annotation;
                // Only set if empty to make sure ApiParam's defaultValue has precedence!
                if (isNullOrEmpty(param.getDefaultValue()) && !isNullOrEmpty(defaultValueAnnotation.value())) {
                    param.setDefaultValue(defaultValueAnnotation.value());
                }
            }
            if (annotation instanceof QueryParam) {
                paramKind = Parameter.Kind.QUERY;
            } else if (annotation instanceof PathParam) {
                paramKind = Parameter.Kind.PATH;
            } else if (annotation instanceof HeaderParam) {
                paramKind = Parameter.Kind.HEADER;
            } else if (annotation instanceof FormParam) {
                paramKind = Parameter.Kind.FORM;
            }
        }
        param.setKind(paramKind);
        if (param.getType() != null) {
            params.add(param);
        }
        i++;
    }
    return params;
}
Also used : DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) QueryParam(javax.ws.rs.QueryParam) ApiParam(io.swagger.annotations.ApiParam) PathParam(javax.ws.rs.PathParam) FormParam(javax.ws.rs.FormParam) Annotation(java.lang.annotation.Annotation)

Example 13 with QueryParam

use of javax.ws.rs.QueryParam 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) 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) 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 14 with QueryParam

use of javax.ws.rs.QueryParam in project wildfly by wildfly.

the class DeploymentRestResourcesDefintion method addMethodParameters.

private void addMethodParameters(JaxrsResourceMethodDescription jaxrsRes, Method method) {
    for (Parameter param : method.getParameters()) {
        ParamInfo paramInfo = new ParamInfo();
        paramInfo.cls = param.getType();
        paramInfo.defaultValue = null;
        paramInfo.name = null;
        paramInfo.type = null;
        Annotation annotation;
        if ((annotation = param.getAnnotation(PathParam.class)) != null) {
            PathParam pathParam = (PathParam) annotation;
            paramInfo.name = pathParam.value();
            paramInfo.type = "@" + PathParam.class.getSimpleName();
        } else if ((annotation = param.getAnnotation(QueryParam.class)) != null) {
            QueryParam queryParam = (QueryParam) annotation;
            paramInfo.name = queryParam.value();
            paramInfo.type = "@" + QueryParam.class.getSimpleName();
        } else if ((annotation = param.getAnnotation(HeaderParam.class)) != null) {
            HeaderParam headerParam = (HeaderParam) annotation;
            paramInfo.name = headerParam.value();
            paramInfo.type = "@" + HeaderParam.class.getSimpleName();
        } else if ((annotation = param.getAnnotation(CookieParam.class)) != null) {
            CookieParam cookieParam = (CookieParam) annotation;
            paramInfo.name = cookieParam.value();
            paramInfo.type = "@" + CookieParam.class.getSimpleName();
        } else if ((annotation = param.getAnnotation(MatrixParam.class)) != null) {
            MatrixParam matrixParam = (MatrixParam) annotation;
            paramInfo.name = matrixParam.value();
            paramInfo.type = "@" + MatrixParam.class.getSimpleName();
        } else if ((annotation = param.getAnnotation(FormParam.class)) != null) {
            FormParam formParam = (FormParam) annotation;
            paramInfo.name = formParam.value();
            paramInfo.type = "@" + FormParam.class.getSimpleName();
        }
        if (paramInfo.name == null) {
            paramInfo.name = param.getName();
        }
        if ((annotation = param.getAnnotation(DefaultValue.class)) != null) {
            DefaultValue defaultValue = (DefaultValue) annotation;
            paramInfo.defaultValue = defaultValue.value();
        }
        jaxrsRes.parameters.add(paramInfo);
    }
}
Also used : CookieParam(javax.ws.rs.CookieParam) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) MatrixParam(javax.ws.rs.MatrixParam) QueryParam(javax.ws.rs.QueryParam) Parameter(java.lang.reflect.Parameter) PathParam(javax.ws.rs.PathParam) FormParam(javax.ws.rs.FormParam) Annotation(java.lang.annotation.Annotation)

Example 15 with QueryParam

use of javax.ws.rs.QueryParam in project indy by Commonjava.

the class DeprecatedContentAccessResource method doHead.

@ApiOperation("Store file/artifact content under the given artifact store (type/name) and path.")
@ApiResponses({ @ApiResponse(code = 404, message = "Content is not available"), @ApiResponse(code = 200, message = "Header metadata for content (or rendered listing when path ends with '/index.html' or '/'") })
@HEAD
@Path("/{path: (.*)}")
public Response doHead(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam(required = true) @PathParam("name") final String name, @PathParam("path") final String path, @QueryParam(CHECK_CACHE_ONLY) final Boolean cacheOnly, @Context final UriInfo uriInfo, @Context final HttpServletRequest request) {
    String packageType = MavenPackageTypeDescriptor.MAVEN_PKG_KEY;
    final String baseUri = uriInfo.getBaseUriBuilder().path(IndyDeployment.API_PREFIX).build().toString();
    final Consumer<Response.ResponseBuilder> deprecated = builder -> {
        String alt = Paths.get("/api/maven", type, name, path).toString();
        markDeprecated(builder, alt);
    };
    return handler.doHead(packageType, type, name, path, cacheOnly, baseUri, request, new EventMetadata(), deprecated);
}
Also used : PathParam(javax.ws.rs.PathParam) IndyDeployment(org.commonjava.indy.bind.jaxrs.IndyDeployment) CHECK_CACHE_ONLY(org.commonjava.indy.IndyContentConstants.CHECK_CACHE_ONLY) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) ApiResponses(io.swagger.annotations.ApiResponses) Supplier(java.util.function.Supplier) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) HttpServletRequest(javax.servlet.http.HttpServletRequest) MavenPackageTypeDescriptor(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor) QueryParam(javax.ws.rs.QueryParam) Api(io.swagger.annotations.Api) URI(java.net.URI) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) IndyResources(org.commonjava.indy.bind.jaxrs.IndyResources) StreamingOutput(javax.ws.rs.core.StreamingOutput) ResponseUtils.markDeprecated(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.markDeprecated) Consumer(java.util.function.Consumer) Response(javax.ws.rs.core.Response) Paths(java.nio.file.Paths) ApiResponse(io.swagger.annotations.ApiResponse) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) ApplicationScoped(javax.enterprise.context.ApplicationScoped) PUT(javax.ws.rs.PUT) UriInfo(javax.ws.rs.core.UriInfo) HEAD(javax.ws.rs.HEAD) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Path(javax.ws.rs.Path) HEAD(javax.ws.rs.HEAD) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

QueryParam (javax.ws.rs.QueryParam)19 PathParam (javax.ws.rs.PathParam)15 Path (javax.ws.rs.Path)12 GET (javax.ws.rs.GET)11 Produces (javax.ws.rs.Produces)11 Response (javax.ws.rs.core.Response)9 Logger (org.slf4j.Logger)9 LoggerFactory (org.slf4j.LoggerFactory)9 ApiParam (io.swagger.annotations.ApiParam)8 Annotation (java.lang.annotation.Annotation)8 POST (javax.ws.rs.POST)8 ApiOperation (io.swagger.annotations.ApiOperation)7 ApiResponse (io.swagger.annotations.ApiResponse)7 ApiResponses (io.swagger.annotations.ApiResponses)7 List (java.util.List)7 Inject (javax.inject.Inject)7 Consumes (javax.ws.rs.Consumes)7 DefaultValue (javax.ws.rs.DefaultValue)7 ArrayList (java.util.ArrayList)6 DELETE (javax.ws.rs.DELETE)6