Search in sources :

Example 36 with PathParam

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

the class DeprecatedContentAccessResource method doCreate.

@ApiOperation("Store file/artifact content under the given artifact store (type/name) and path.")
@ApiResponses({ @ApiResponse(code = 201, message = "Content was stored successfully"), @ApiResponse(code = 400, message = "No appropriate storage location was found in the specified store (this store, or a member if a group is specified).") })
@PUT
@Path("/{path: (.+)?}")
public Response doCreate(@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, @Context final UriInfo uriInfo, @Context final HttpServletRequest request) {
    String packageType = MavenPackageTypeDescriptor.MAVEN_PKG_KEY;
    final Supplier<URI> uriSupplier = () -> uriInfo.getBaseUriBuilder().path(getClass()).path(path).build(packageType, type, name);
    final Consumer<Response.ResponseBuilder> deprecated = builder -> {
        String alt = Paths.get("/api/maven", type, name, path).toString();
        responseHelper.markDeprecated(builder, alt);
    };
    final EventMetadata metadata = new EventMetadata().set(STORE_HTTP_HEADERS, RequestUtils.extractRequestHeadersToMap(request));
    return handler.doCreate(packageType, type, name, path, request, metadata, uriSupplier, deprecated);
}
Also used : PathParam(javax.ws.rs.PathParam) IndyDeployment(org.commonjava.indy.bind.jaxrs.IndyDeployment) REST(org.commonjava.indy.bind.jaxrs.util.REST) 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) STORE_HTTP_HEADERS(org.commonjava.maven.galley.spi.cache.CacheProvider.STORE_HTTP_HEADERS) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) ResponseHelper(org.commonjava.indy.bind.jaxrs.util.ResponseHelper) RequestUtils(org.commonjava.indy.core.bind.jaxrs.util.RequestUtils) IndyResources(org.commonjava.indy.bind.jaxrs.IndyResources) StreamingOutput(javax.ws.rs.core.StreamingOutput) 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) URI(java.net.URI) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Path(javax.ws.rs.Path) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) PUT(javax.ws.rs.PUT)

Example 37 with PathParam

use of javax.ws.rs.PathParam 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 38 with PathParam

use of javax.ws.rs.PathParam in project japid42 by branaway.

the class RouterMethod method extractArguments.

public Object[] extractArguments(play.mvc.Http.RequestHeader r) {
    String path = r.path();
    if (path.endsWith(withExtension))
        path = path.substring(0, path.lastIndexOf(withExtension));
    List<RegMatch> rootParamValueMatches = RegMatch.findAllMatchesIn(valueExtractionPattern, path);
    List<String> rootParamValues = new ArrayList<String>();
    for (RegMatch rm : rootParamValueMatches) {
        rootParamValues.addAll(rm.subgroups);
    }
    if (rootParamValues.size() != paramSpecList.size()) {
        throw new RuntimeException("param spec number does not match that from URI capturing. Spec contains: " + paramSpecList.size() + " while the URI contains: " + rootParamValues.size() + ". The route entry is: " + this.toString());
    }
    Map<String, Object> args = new java.util.HashMap<String, Object>();
    int c = 0;
    for (ParamSpec paramSpec : paramSpecList) {
        String name = paramSpec.name;
        String value = rootParamValues.get(c++);
        if (!paramSpec.formatPattern.matcher(value).matches()) {
            throw new IllegalArgumentException("format mismatch for : (" + name + ")" + value + ". The route entry is: " + this.toString());
        }
        Class<?> type = paramSpec.type;
        Object val = convertArgType(c, name, value, type);
        args.put(name, val);
    }
    // 
    Object[] argValues = new Object[0];
    List<Object> argVals = new ArrayList<Object>();
    Annotation[][] annos = meth.getParameterAnnotations();
    c = 0;
    int pos = 0;
    for (Annotation[] ans : annos) {
        PathParam pathParam = null;
        QueryParam queryParam = null;
        for (Annotation an : ans) {
            if (an instanceof PathParam)
                pathParam = (PathParam) an;
            else if (an instanceof QueryParam)
                queryParam = (QueryParam) an;
        }
        if (pathParam != null) {
            Object v = args.get(pathParam.value());
            if (v != null)
                argVals.add(v);
            else
                throw new IllegalArgumentException("can not find annotation value for argument " + pathParam.value() + "in " + meth.getDeclaringClass() + "#" + meth);
        } else if (queryParam != null) {
            String name = queryParam.value();
            // XXX should this
            String queryString = r.getQueryString(name);
            // be of
            // String[]?
            argVals.add(convertArgType(c, name, queryString, meth.getParameterTypes()[c]));
        } else if (autoRouting) {
            Object v = args.get("_" + pos++);
            if (v != null)
                argVals.add(v);
            else
                throw new IllegalArgumentException("can not find value for param No. " + c + " in " + meth.getDeclaringClass() + "#" + meth);
        } else
            throw new IllegalArgumentException("can not find how to map the value for an argument for method:" + meth.getDeclaringClass() + "#" + meth + ". The parameter position is(0-based): " + c);
        c++;
    }
    argValues = argVals.toArray(argValues);
    return argValues;
}
Also used : ArrayList(java.util.ArrayList) Annotation(java.lang.annotation.Annotation) QueryParam(javax.ws.rs.QueryParam) PathParam(javax.ws.rs.PathParam)

Example 39 with PathParam

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

the class AuthzRolesResource method getUsersForRole.

@GET
@ApiOperation(value = "Get a paginated list of users for a role")
@Path("/{roleId}/assignees")
@Produces(MediaType.APPLICATION_JSON)
@RequiresPermissions(RestPermissions.USERS_LIST)
public PaginatedResponse<UserOverviewDTO> getUsersForRole(@ApiParam(name = "roleId") @PathParam("roleId") @NotEmpty String roleId, @ApiParam(name = "page") @QueryParam("page") @DefaultValue("1") int page, @ApiParam(name = "per_page") @QueryParam("per_page") @DefaultValue("50") int perPage, @ApiParam(name = "query") @QueryParam("query") @DefaultValue("") String query, @ApiParam(name = "sort", value = "The field to sort the result on", required = true, allowableValues = "username,full_name,email") @DefaultValue(AuthzRoleDTO.FIELD_NAME) @QueryParam("sort") String sort, @ApiParam(name = "order", value = "The sort direction", allowableValues = "asc, desc") @DefaultValue("asc") @QueryParam("order") String order) {
    SearchQuery searchQuery;
    try {
        searchQuery = userSearchQueryParser.parse(query);
    } catch (IllegalArgumentException e) {
        throw new BadRequestException("Invalid argument in search query: " + e.getMessage());
    }
    final PaginatedList<UserOverviewDTO> result = paginatedUserService.findPaginatedByRole(searchQuery, page, perPage, sort, order, ImmutableSet.of(roleId));
    final Set<String> roleIds = result.stream().flatMap(u -> u.roles().stream()).collect(Collectors.toSet());
    final Map<String, String> rolesMap = authzRolesService.findPaginatedByIds(new SearchQuery(""), 0, 0, AuthzRoleDTO.FIELD_NAME, "asc", roleIds).stream().collect(Collectors.toMap(AuthzRoleDTO::id, AuthzRoleDTO::name));
    final List<UserOverviewDTO> users = result.stream().map(u -> {
        final Set<String> roleNames = u.roles().stream().map(rolesMap::get).collect(Collectors.toSet());
        return u.toBuilder().roles(roleNames).build();
    }).collect(Collectors.toList());
    final PaginatedList<UserOverviewDTO> enrichedResult = new PaginatedList<>(users, result.pagination().total(), result.pagination().page(), result.pagination().perPage());
    return PaginatedResponse.create("users", enrichedResult, query);
}
Also used : SearchQuery(org.graylog2.search.SearchQuery) PathParam(javax.ws.rs.PathParam) NotBlank(javax.validation.constraints.NotBlank) Produces(javax.ws.rs.Produces) SearchQueryParser(org.graylog2.search.SearchQueryParser) GET(javax.ws.rs.GET) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) HashMap(java.util.HashMap) NotAllowedException(javax.ws.rs.NotAllowedException) NotEmpty(javax.validation.constraints.NotEmpty) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) PaginatedList(org.graylog2.database.PaginatedList) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) SearchQueryField(org.graylog2.search.SearchQueryField) USERS_ROLESEDIT(org.graylog2.shared.security.RestPermissions.USERS_ROLESEDIT) Map(java.util.Map) AuditEvent(org.graylog2.audit.jersey.AuditEvent) DefaultValue(javax.ws.rs.DefaultValue) BadRequestException(javax.ws.rs.BadRequestException) Api(io.swagger.annotations.Api) SearchQuery(org.graylog2.search.SearchQuery) DELETE(javax.ws.rs.DELETE) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) RestResource(org.graylog2.shared.rest.resources.RestResource) Collectors(java.util.stream.Collectors) PaginatedUserService(org.graylog2.users.PaginatedUserService) NotFoundException(javax.ws.rs.NotFoundException) Objects(java.util.Objects) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) UserService(org.graylog2.shared.users.UserService) AuditEventTypes(org.graylog2.audit.AuditEventTypes) ValidationException(org.graylog2.plugin.database.ValidationException) RestPermissions(org.graylog2.shared.security.RestPermissions) Optional(java.util.Optional) PUT(javax.ws.rs.PUT) PaginatedResponse(org.graylog2.rest.models.PaginatedResponse) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) User(org.graylog2.plugin.database.users.User) UserOverviewDTO(org.graylog2.users.UserOverviewDTO) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) UserOverviewDTO(org.graylog2.users.UserOverviewDTO) BadRequestException(javax.ws.rs.BadRequestException) PaginatedList(org.graylog2.database.PaginatedList) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 40 with PathParam

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

the class IndicesResource method indexSetClosed.

@GET
@Timed
@Path("/{indexSetId}/closed")
@ApiOperation(value = "Get a list of closed indices that can be reopened.")
@Produces(MediaType.APPLICATION_JSON)
public ClosedIndices indexSetClosed(@ApiParam(name = "indexSetId") @PathParam("indexSetId") String indexSetId) {
    final IndexSet indexSet = getIndexSet(indexSetRegistry, indexSetId);
    final Set<String> closedIndices = indices.getClosedIndices(indexSet).stream().filter(index -> isPermitted(RestPermissions.INDICES_READ, index)).collect(Collectors.toSet());
    return ClosedIndices.create(closedIndices, closedIndices.size());
}
Also used : IndicesReadRequest(org.graylog2.rest.models.system.indexer.requests.IndicesReadRequest) PathParam(javax.ws.rs.PathParam) AllIndices(org.graylog2.rest.models.system.indexer.responses.AllIndices) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) ClosedIndices(org.graylog2.rest.models.system.indexer.responses.ClosedIndices) Inject(javax.inject.Inject) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) ShardRouting(org.graylog2.rest.models.system.indexer.responses.ShardRouting) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) MediaType(javax.ws.rs.core.MediaType) Indices(org.graylog2.indexer.indices.Indices) Map(java.util.Map) AuditEvent(org.graylog2.audit.jersey.AuditEvent) IndexStatistics(org.graylog2.indexer.indices.stats.IndexStatistics) Api(io.swagger.annotations.Api) IndexSet(org.graylog2.indexer.IndexSet) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) DELETE(javax.ws.rs.DELETE) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) ForbiddenException(javax.ws.rs.ForbiddenException) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) IndexInfo(org.graylog2.rest.models.system.indexer.responses.IndexInfo) Set(java.util.Set) RestResource(org.graylog2.shared.rest.resources.RestResource) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) ApiResponse(io.swagger.annotations.ApiResponse) AuditEventTypes(org.graylog2.audit.AuditEventTypes) OpenIndicesInfo(org.graylog2.rest.models.system.indexer.responses.OpenIndicesInfo) RestPermissions(org.graylog2.shared.security.RestPermissions) NodeInfoCache(org.graylog2.indexer.NodeInfoCache) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) IndexSet(org.graylog2.indexer.IndexSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

PathParam (javax.ws.rs.PathParam)127 Path (javax.ws.rs.Path)105 GET (javax.ws.rs.GET)96 Produces (javax.ws.rs.Produces)96 Response (javax.ws.rs.core.Response)93 QueryParam (javax.ws.rs.QueryParam)82 List (java.util.List)72 MediaType (javax.ws.rs.core.MediaType)72 POST (javax.ws.rs.POST)71 DELETE (javax.ws.rs.DELETE)70 Consumes (javax.ws.rs.Consumes)66 Inject (javax.inject.Inject)62 Api (io.swagger.annotations.Api)60 ApiOperation (io.swagger.annotations.ApiOperation)59 Map (java.util.Map)59 ApiResponse (io.swagger.annotations.ApiResponse)58 ApiResponses (io.swagger.annotations.ApiResponses)57 Collectors (java.util.stream.Collectors)57 Logger (org.slf4j.Logger)52 LoggerFactory (org.slf4j.LoggerFactory)52