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);
}
}
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;
}
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);
}
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);
}
}
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);
}
Aggregations