use of javax.ws.rs.core.Context in project ovirt-engine by oVirt.
the class V3Server method setHttpHeaders.
// We need to have the HTTP headers injected, as we need to manually inject into the V4 implementation of the
// service.
@Context
public void setHttpHeaders(HttpHeaders httpHeaders) {
if (delegate instanceof BaseBackendResource) {
BaseBackendResource resource = (BaseBackendResource) delegate;
resource.setHttpHeaders(httpHeaders);
}
}
use of javax.ws.rs.core.Context in project streamline by hortonworks.
the class NamespaceCatalogResource method setServicesToClusterInNamespace.
@POST
@Path("/namespaces/{id}/mapping/bulk")
@Timed
public Response setServicesToClusterInNamespace(@PathParam("id") Long namespaceId, List<NamespaceServiceClusterMap> mappings, @Context SecurityContext securityContext) {
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_SUPER_ADMIN, Namespace.NAMESPACE, namespaceId, WRITE);
Namespace namespace = environmentService.getNamespace(namespaceId);
if (namespace == null) {
throw EntityNotFoundException.byId(namespaceId.toString());
}
String streamingEngine = namespace.getStreamingEngine();
String timeSeriesDB = namespace.getTimeSeriesDB();
Collection<NamespaceServiceClusterMap> existing = environmentService.listServiceClusterMapping(namespaceId);
Optional<NamespaceServiceClusterMap> existingStreamingEngine = existing.stream().filter(m -> m.getServiceName().equals(streamingEngine)).findFirst();
// indicates that mapping of streaming engine has been changed or removed
if (existingStreamingEngine.isPresent() && !mappings.contains(existingStreamingEngine.get())) {
assertNoTopologyReferringNamespaceIsRunning(namespaceId, WSUtils.getUserFromSecurityContext(securityContext));
}
// we're OK to just check with new mappings since we will remove existing mappings
assertServiceIsUnique(mappings, streamingEngine);
assertServiceIsUnique(mappings, timeSeriesDB);
// remove any existing mapping for (namespace, service name) pairs
Collection<NamespaceServiceClusterMap> existingMappings = environmentService.listServiceClusterMapping(namespaceId);
if (existingMappings != null) {
existingMappings.forEach(m -> environmentService.removeServiceClusterMapping(m.getNamespaceId(), m.getServiceName(), m.getClusterId()));
}
List<NamespaceServiceClusterMap> newMappings = mappings.stream().map(environmentService::addOrUpdateServiceClusterMapping).collect(toList());
return WSUtils.respondEntities(newMappings, CREATED);
}
use of javax.ws.rs.core.Context in project streamline by hortonworks.
the class NamespaceCatalogResource method unmapAllServicesToClusterInNamespace.
@DELETE
@Path("/namespaces/{id}/mapping")
@Timed
public Response unmapAllServicesToClusterInNamespace(@PathParam("id") Long namespaceId, @Context SecurityContext securityContext) {
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_ENVIRONMENT_SUPER_ADMIN, Namespace.NAMESPACE, namespaceId, WRITE);
Namespace namespace = environmentService.getNamespace(namespaceId);
if (namespace == null) {
throw EntityNotFoundException.byId(namespaceId.toString());
}
String streamingEngine = namespace.getStreamingEngine();
Collection<NamespaceServiceClusterMap> mappings = environmentService.listServiceClusterMapping(namespaceId);
boolean containsStreamingEngine = mappings.stream().anyMatch(m -> m.getServiceName().equals(streamingEngine));
if (containsStreamingEngine) {
assertNoTopologyReferringNamespaceIsRunning(namespaceId, WSUtils.getUserFromSecurityContext(securityContext));
}
List<NamespaceServiceClusterMap> removed = mappings.stream().map((x) -> environmentService.removeServiceClusterMapping(x.getNamespaceId(), x.getServiceName(), x.getClusterId())).collect(toList());
return WSUtils.respondEntities(removed, OK);
}
use of javax.ws.rs.core.Context in project component-runtime by Talend.
the class ProjectResource method createZip.
@POST
@Path("zip/form")
@Produces("application/zip")
public Response createZip(@FormParam("project") final String compressedModel, @Context final Providers providers) {
final MessageBodyReader<ProjectModel> jsonReader = providers.getMessageBodyReader(ProjectModel.class, ProjectModel.class, NO_ANNOTATION, APPLICATION_JSON_TYPE);
final ProjectModel model;
try (final InputStream gzipInputStream = new ByteArrayInputStream(Base64.getUrlDecoder().decode(compressedModel))) {
model = jsonReader.readFrom(ProjectModel.class, ProjectModel.class, NO_ANNOTATION, APPLICATION_JSON_TYPE, new MultivaluedHashMap<>(), gzipInputStream);
} catch (final IOException e) {
throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new ErrorMessage(e.getMessage())).type(APPLICATION_JSON_TYPE).build());
}
final String filename = ofNullable(model.getArtifact()).orElse("zip") + ".zip";
return Response.ok().entity((StreamingOutput) out -> {
generator.generate(toRequest(model), out);
out.flush();
}).header("Content-Disposition", "inline; filename=" + filename).build();
}
use of javax.ws.rs.core.Context in project neo4j by neo4j.
the class AbstractCypherResource method commitNewTransaction.
@POST
@Path("/commit")
public Response commitNewTransaction(InputEventStream inputEventStream, @Context HttpServletRequest request, @Context HttpHeaders headers) {
try (var memoryTracker = createMemoryTracker()) {
InputEventStream inputStream = ensureNotNull(inputEventStream);
Optional<GraphDatabaseAPI> graphDatabaseAPI = httpTransactionManager.getGraphDatabaseAPI(databaseName);
return graphDatabaseAPI.map(databaseAPI -> {
if (isDatabaseNotAvailable(databaseAPI)) {
return createNonAvailableDatabaseResponse(inputStream.getParameters());
}
memoryTracker.allocateHeap(Invocation.SHALLOW_SIZE);
final TransactionFacade transactionFacade = httpTransactionManager.createTransactionFacade(databaseAPI, memoryTracker);
TransactionHandle transactionHandle = createNewTransactionHandle(transactionFacade, request, headers, memoryTracker, true);
Invocation invocation = new Invocation(log, transactionHandle, null, memoryPool, inputStream, true);
OutputEventStreamImpl outputStream = new OutputEventStreamImpl(inputStream.getParameters(), transactionHandle, uriScheme, invocation::execute);
return Response.ok(outputStream).build();
}).orElse(createNonExistentDatabaseResponse(inputStream.getParameters()));
}
}
Aggregations