use of javax.ws.rs.PathParam in project kylo by Teradata.
the class ConnectorController method getAllowedActions.
@GET
@Path("{id}/actions/allowed")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Gets the list of actions permitted for the given username and/or groups.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the actions.", response = ActionGroup.class), @ApiResponse(code = 404, message = "A connector with the given ID does not exist.", response = RestResponseStatus.class) })
public Response getAllowedActions(@PathParam("id") final String connectorIdStr, @QueryParam("user") final Set<String> userNames, @QueryParam("group") final Set<String> groupNames) {
log.debug("Get allowed actions for connector: {}", connectorIdStr);
Set<? extends Principal> users = Arrays.stream(this.securityTransform.asUserPrincipals(userNames)).collect(Collectors.toSet());
Set<? extends Principal> groups = Arrays.stream(this.securityTransform.asGroupPrincipals(groupNames)).collect(Collectors.toSet());
return this.securityService.getAllowedConnectorActions(connectorIdStr, Stream.concat(users.stream(), groups.stream()).collect(Collectors.toSet())).map(g -> Response.ok(g).build()).orElseThrow(() -> new WebApplicationException("A connector with the given ID does not exist: " + connectorIdStr, Response.Status.NOT_FOUND));
}
use of javax.ws.rs.PathParam in project cxf by apache.
the class Validator method checkMethodsForInvalidURITemplates.
private static void checkMethodsForInvalidURITemplates(Class<?> userType, Method[] methods) throws RestClientDefinitionException {
Path classPathAnno = userType.getAnnotation(Path.class);
URITemplate classTemplate = null;
if (classPathAnno != null) {
classTemplate = new URITemplate(classPathAnno.value());
}
URITemplate template;
for (Method method : methods) {
Path methodPathAnno = method.getAnnotation(Path.class);
if (methodPathAnno != null) {
template = classPathAnno == null ? new URITemplate(methodPathAnno.value()) : new URITemplate(classPathAnno.value() + "/" + methodPathAnno.value());
} else {
template = classTemplate;
}
if (template == null) {
continue;
}
List<String> foundParams = new ArrayList<>();
for (Parameter p : method.getParameters()) {
PathParam pathParam = p.getAnnotation(PathParam.class);
if (pathParam != null) {
foundParams.add(pathParam.value());
}
}
Set<String> allVariables = new HashSet<>(template.getVariables());
if (!allVariables.isEmpty()) {
for (String variable : template.getVariables()) {
if (!foundParams.contains(variable)) {
throwException("VALIDATION_UNRESOLVED_PATH_PARAMS", userType, method);
}
}
} else if (!foundParams.isEmpty()) {
throwException("VALIDATION_EXTRA_PATH_PARAMS", userType, method);
}
}
}
use of javax.ws.rs.PathParam in project che by eclipse.
the class WorkspaceService method updateProject.
@PUT
@Path("/{id}/project/{path:.*}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Update the workspace project by replacing it with a new one", notes = "This operation can be performed only by the workspace owner")
@ApiResponses({ @ApiResponse(code = 200, message = "The project successfully updated"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 403, message = "The user does not have access to update the project"), @ApiResponse(code = 404, message = "The workspace or the project not found"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public WorkspaceDto updateProject(@ApiParam("The workspace id") @PathParam("id") String id, @ApiParam("The path to the project") @PathParam("path") String path, @ApiParam(value = "The project update", required = true) ProjectConfigDto update) throws ServerException, BadRequestException, NotFoundException, ConflictException, ForbiddenException {
requiredNotNull(update, "Project config");
final WorkspaceImpl workspace = workspaceManager.getWorkspace(id);
final List<ProjectConfigImpl> projects = workspace.getConfig().getProjects();
final String normalizedPath = path.startsWith("/") ? path : '/' + path;
if (!projects.removeIf(project -> project.getPath().equals(normalizedPath))) {
throw new NotFoundException(format("Workspace '%s' doesn't contain project with path '%s'", id, normalizedPath));
}
projects.add(new ProjectConfigImpl(update));
validator.validateConfig(workspace.getConfig());
return linksInjector.injectLinks(asDto(workspaceManager.updateWorkspace(id, workspace)), getServiceContext());
}
use of javax.ws.rs.PathParam in project swagger-core by swagger-api.
the class DefaultParameterExtension method extractParameters.
@Override
public List<Parameter> extractParameters(List<Annotation> annotations, Type type, Set<Type> typesToSkip, Iterator<SwaggerExtension> chain) {
if (shouldIgnoreType(type, typesToSkip)) {
return new ArrayList<Parameter>();
}
List<Parameter> parameters = new ArrayList<Parameter>();
Parameter parameter = null;
for (Annotation annotation : annotations) {
if (annotation instanceof QueryParam) {
QueryParam param = (QueryParam) annotation;
QueryParameter qp = new QueryParameter().name(param.value());
Property schema = createProperty(type);
if (schema != null) {
qp.setProperty(schema);
}
parameter = qp;
} else if (annotation instanceof PathParam) {
PathParam param = (PathParam) annotation;
PathParameter pp = new PathParameter().name(param.value());
Property schema = createProperty(type);
if (schema != null) {
pp.setProperty(schema);
}
parameter = pp;
} else if (annotation instanceof HeaderParam) {
HeaderParam param = (HeaderParam) annotation;
HeaderParameter hp = new HeaderParameter().name(param.value());
Property schema = createProperty(type);
if (schema != null) {
hp.setProperty(schema);
}
parameter = hp;
} else if (annotation instanceof CookieParam) {
CookieParam param = (CookieParam) annotation;
CookieParameter cp = new CookieParameter().name(param.value());
Property schema = createProperty(type);
if (schema != null) {
cp.setProperty(schema);
}
parameter = cp;
} else if (annotation instanceof FormParam) {
FormParam param = (FormParam) annotation;
FormParameter fp = new FormParameter().name(param.value());
Property schema = createProperty(type);
if (schema != null) {
fp.setProperty(schema);
}
parameter = fp;
} else {
handleAdditionalAnnotation(parameters, annotation, type, typesToSkip);
}
}
if (parameter != null) {
parameters.add(parameter);
}
return parameters;
}
use of javax.ws.rs.PathParam in project pulsar by yahoo.
the class DestinationLookup method lookupDestinationAsync.
@GET
@Path("persistent/{property}/{cluster}/{namespace}/{dest}")
@Produces(MediaType.APPLICATION_JSON)
public void lookupDestinationAsync(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("dest") @Encoded String dest, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative, @Suspended AsyncResponse asyncResponse) {
dest = Codec.decode(dest);
DestinationName topic = DestinationName.get("persistent", property, cluster, namespace, dest);
if (!pulsar().getBrokerService().getLookupRequestSemaphore().tryAcquire()) {
log.warn("No broker was found available for topic {}", topic);
asyncResponse.resume(new WebApplicationException(Response.Status.SERVICE_UNAVAILABLE));
return;
}
try {
validateClusterOwnership(topic.getCluster());
checkConnect(topic);
validateReplicationSettingsOnNamespace(pulsar(), topic.getNamespaceObject());
} catch (WebApplicationException we) {
// Validation checks failed
log.error("Validation check failed: {}", we.getMessage());
completeLookupResponseExceptionally(asyncResponse, we);
return;
} catch (Throwable t) {
// Validation checks failed with unknown error
log.error("Validation check failed: {}", t.getMessage(), t);
completeLookupResponseExceptionally(asyncResponse, new RestException(t));
return;
}
CompletableFuture<LookupResult> lookupFuture = pulsar().getNamespaceService().getBrokerServiceUrlAsync(topic, authoritative);
lookupFuture.thenAccept(result -> {
if (result == null) {
log.warn("No broker was found available for topic {}", topic);
completeLookupResponseExceptionally(asyncResponse, new WebApplicationException(Response.Status.SERVICE_UNAVAILABLE));
return;
}
if (result.isRedirect()) {
boolean newAuthoritative = this.isLeaderBroker();
URI redirect;
try {
String redirectUrl = isRequestHttps() ? result.getLookupData().getHttpUrlTls() : result.getLookupData().getHttpUrl();
redirect = new URI(String.format("%s%s%s?authoritative=%s", redirectUrl, "/lookup/v2/destination/", topic.getLookupName(), newAuthoritative));
} catch (URISyntaxException e) {
log.error("Error in preparing redirect url for {}: {}", topic, e.getMessage(), e);
completeLookupResponseExceptionally(asyncResponse, e);
return;
}
if (log.isDebugEnabled()) {
log.debug("Redirect lookup for topic {} to {}", topic, redirect);
}
completeLookupResponseExceptionally(asyncResponse, new WebApplicationException(Response.temporaryRedirect(redirect).build()));
} else {
if (log.isDebugEnabled()) {
log.debug("Lookup succeeded for topic {} -- broker: {}", topic, result.getLookupData());
}
completeLookupResponseSuccessfully(asyncResponse, result.getLookupData());
}
}).exceptionally(exception -> {
log.warn("Failed to lookup broker for topic {}: {}", topic, exception.getMessage(), exception);
completeLookupResponseExceptionally(asyncResponse, exception);
return null;
});
}
Aggregations