use of javax.ws.rs.PUT 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();
markDeprecated(builder, alt);
};
return handler.doCreate(packageType, type, name, path, request, new EventMetadata(), uriSupplier, deprecated);
}
use of javax.ws.rs.PUT in project stanbol by apache.
the class UserResource method createUser.
/*
* RESTful creation of user
* @TODO validity check input
*/
@PUT
@Path("users/{username}")
@Consumes(SupportedFormat.TURTLE)
public Response createUser(@Context UriInfo uriInfo, @PathParam("username") String userName, ImmutableGraph inputGraph) {
Lock writeLock = systemGraph.getLock().writeLock();
writeLock.lock();
systemGraph.addAll(inputGraph);
writeLock.unlock();
UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
URI createdResource = uriBuilder.replacePath("/user-management/users/" + userName).build();
return Response.created(createdResource).build();
}
use of javax.ws.rs.PUT in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method setWorkerInstances.
/**
* Sets the number of instances of a worker.
*/
@PUT
@Path("/apps/{app-id}/workers/{worker-id}/instances")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void setWorkerInstances(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("worker-id") String workerId) throws Exception {
int instances = getInstances(request);
try {
lifecycleService.setInstances(new ProgramId(namespaceId, appId, ProgramType.WORKER, workerId), instances);
responder.sendStatus(HttpResponseStatus.OK);
} catch (SecurityException e) {
responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
} catch (Throwable e) {
if (respondIfElementNotFound(e, responder)) {
return;
}
throw e;
}
}
use of javax.ws.rs.PUT in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method setServiceInstances.
/**
* Set instances of a service.
*/
@PUT
@Path("/apps/{app-id}/services/{service-id}/instances")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void setServiceInstances(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("service-id") String serviceId) throws Exception {
try {
ProgramId programId = new ProgramId(namespaceId, appId, ProgramType.SERVICE, serviceId);
if (!store.programExists(programId)) {
responder.sendString(HttpResponseStatus.NOT_FOUND, "Service not found");
return;
}
int instances = getInstances(request);
lifecycleService.setInstances(programId, instances);
responder.sendStatus(HttpResponseStatus.OK);
} catch (SecurityException e) {
responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
} catch (Throwable throwable) {
if (respondIfElementNotFound(throwable, responder)) {
return;
}
throw throwable;
}
}
use of javax.ws.rs.PUT in project cdap by caskdata.
the class MonitorHandler method updateServiceLogLevels.
/**
* Update log levels for this service.
*/
@Path("system/services/{service-name}/loglevels")
@PUT
public void updateServiceLogLevels(HttpRequest request, HttpResponder responder, @PathParam("service-name") String serviceName) throws Exception {
if (!serviceManagementMap.containsKey(serviceName)) {
throw new NotFoundException(String.format("Invalid service name %s", serviceName));
}
MasterServiceManager masterServiceManager = serviceManagementMap.get(serviceName);
if (!masterServiceManager.isServiceEnabled()) {
throw new ForbiddenException(String.format("Failed to update log levels for service %s " + "because the service is not enabled", serviceName));
}
try {
// we are decoding the body to Map<String, String> instead of Map<String, LogEntry.Level> here since Gson will
// serialize invalid enum values to null, which is allowed for log level, instead of throw an Exception.
masterServiceManager.updateServiceLogLevels(transformLogLevelsMap(decodeArguments(request)));
responder.sendStatus(HttpResponseStatus.OK);
} catch (IllegalStateException ise) {
throw new ServiceUnavailableException(String.format("Failed to update log levels for service %s " + "because the service may not be ready yet", serviceName));
} catch (IllegalArgumentException e) {
throw new BadRequestException(e.getMessage());
} catch (JsonSyntaxException e) {
throw new BadRequestException("Invalid Json in the body");
}
}
Aggregations