@GET @Path("{queryId}/{token}") @Produces(MediaType.APPLICATION_JSON) public void getQueryResults( @PathParam("queryId") QueryId queryId, @PathParam("token") long token, @QueryParam("maxWait") Duration maxWait, @QueryParam("targetResultSize") DataSize targetResultSize, @HeaderParam(X_FORWARDED_PROTO) String proto, @Context UriInfo uriInfo, @Suspended AsyncResponse asyncResponse) { Query query = queries.get(queryId); if (query == null) { asyncResponse.resume(Response.status(Status.NOT_FOUND).build()); return; } if (isNullOrEmpty(proto)) { proto = uriInfo.getRequestUri().getScheme(); } asyncQueryResults(query, OptionalLong.of(token), maxWait, targetResultSize, uriInfo, proto, asyncResponse); }
@GET @Path("async") public void suspendViaContextExample(@Suspended final AsyncResponse ar, @QueryParam("query") final String query) { TASK_EXECUTOR.submit(new Runnable() { @Override public void run() { try { Thread.sleep(SLEEP_TIME_IN_MILLIS); } catch (InterruptedException ex) { LOGGER.log(Level.SEVERE, "Response processing interrupted", ex); } ar.resume("Complex result for " + query); } }); } }
@POST @ManagedAsync @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.MULTIPART_FORM_DATA) @Path("/segments") @ApiOperation(value = "Upload a segment", notes = "Upload a segment as binary") // For the multipart endpoint, we will always move segment to final location regardless of the segment endpoint. public void uploadSegmentAsMultiPart(FormDataMultiPart multiPart, @ApiParam(value = "Whether to enable parallel push protection") @DefaultValue("false") @QueryParam(FileUploadDownloadClient.QueryParameters.ENABLE_PARALLEL_PUSH_PROTECTION) boolean enableParallelPushProtection, @Context HttpHeaders headers, @Context Request request, @Suspended final AsyncResponse asyncResponse) { try { asyncResponse.resume(uploadSegment(multiPart, enableParallelPushProtection, headers, request, true)); } catch (Throwable t) { asyncResponse.resume(t); } }
@DELETE @Path("/v1/proxy") @Produces(APPLICATION_JSON) public void cancelQuery( @QueryParam("uri") String uri, @QueryParam("hmac") String hash, @Context HttpServletRequest servletRequest, @Suspended AsyncResponse asyncResponse) { if (!hmac.hashString(uri, UTF_8).equals(HashCode.fromString(hash))) { throw badRequest(FORBIDDEN, "Failed to validate HMAC of URI"); } Request.Builder request = prepareDelete().setUri(URI.create(uri)); performRequest(servletRequest, asyncResponse, request, response -> responseWithHeaders(noContent(), response)); }
@GET @ManagedAsync public void longGet(@Suspended final AsyncResponse ar, @QueryParam("id") int requestId) { try { Thread.sleep(SLEEP_TIME_IN_MILLIS); } catch (InterruptedException ex) { LOGGER.log(Level.SEVERE, "Response processing interrupted", ex); } ar.resume(requestId + " - " + NOTIFICATION_RESPONSE); } }
@GET public void longGet(@Suspended final AsyncResponse ar) { TASK_EXECUTOR.submit(new Runnable() { @Override public void run() { try { Thread.sleep(SLEEP_TIME_IN_MILLIS); } catch (InterruptedException ex) { LOGGER.log(Level.SEVERE, "Response processing interrupted", ex); } ar.resume(NOTIFICATION_RESPONSE); } }); } }
@GET @Produces({ "application/json" }) @ApiOperation( value = "", notes = "List all scopes in the system", response = ScopesList.class, tags = { }) @ApiResponses(value = { @ApiResponse( code = 200, message = "List of scope objects", response = ScopesList.class), @ApiResponse( code = 500, message = "Server error", response = ScopesList.class) }) void listScopes(@Context SecurityContext securityContext, @Suspended final AsyncResponse asyncResponse);
@POST @Consumes({ "application/json" }) @Produces({ "application/json" }) @ApiOperation( value = "", notes = "Creates a new scope", response = ScopeProperty.class, tags = { }) @ApiResponses(value = { @ApiResponse( code = 201, message = "Successfully created the scope", response = ScopeProperty.class), @ApiResponse( code = 409, message = "Scope already exists", response = ScopeProperty.class), @ApiResponse( code = 500, message = "Server error", response = ScopeProperty.class) }) void createScope( @ApiParam(value = "The scope configuration", required = true) CreateScopeRequest createScopeRequest, @Context SecurityContext securityContext, @Suspended final AsyncResponse asyncResponse);
@GET @Path("/v1/proxy") @Produces(APPLICATION_JSON) public void getNext( @QueryParam("uri") String uri, @QueryParam("hmac") String hash, @Context HttpServletRequest servletRequest, @Context UriInfo uriInfo, @Suspended AsyncResponse asyncResponse) { if (!hmac.hashString(uri, UTF_8).equals(HashCode.fromString(hash))) { throw badRequest(FORBIDDEN, "Failed to validate HMAC of URI"); } Request.Builder request = prepareGet().setUri(URI.create(uri)); performRequest(servletRequest, asyncResponse, request, response -> buildResponse(uriInfo, response)); }
@POST @ManagedAsync @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.MULTIPART_FORM_DATA) @Path("/v2/segments") @ApiOperation(value = "Upload a segment", notes = "Upload a segment as binary") // This behavior does not differ from v1 of the same endpoint. public void uploadSegmentAsMultiPartV2(FormDataMultiPart multiPart, @ApiParam(value = "Whether to enable parallel push protection") @DefaultValue("false") @QueryParam(FileUploadDownloadClient.QueryParameters.ENABLE_PARALLEL_PUSH_PROTECTION) boolean enableParallelPushProtection, @Context HttpHeaders headers, @Context Request request, @Suspended final AsyncResponse asyncResponse) { try { asyncResponse.resume(uploadSegment(multiPart, enableParallelPushProtection, headers, request, true)); } catch (Throwable t) { asyncResponse.resume(t); } }
@POST @Path("/v1/statement") @Produces(APPLICATION_JSON) public void postStatement( String statement, @Context HttpServletRequest servletRequest, @Context UriInfo uriInfo, @Suspended AsyncResponse asyncResponse) { Request.Builder request = preparePost() .setUri(uriBuilderFrom(remoteUri).replacePath("/v1/statement").build()) .setBodyGenerator(createStaticBodyGenerator(statement, UTF_8)); performRequest(servletRequest, asyncResponse, request, response -> buildResponse(uriInfo, response)); }
@GET @Produces("application/json") public void mainfest(@Suspended AsyncResponse asyncResponse, @Context ServletContext context) { ReactiveSeq.of("/META-INF/MANIFEST.MF") .map(url->context.getResourceAsStream(url)) .map(this::getManifest) .foldFuture(WorkerThreads.ioExecutor.get(), s->s.forEach(Long.MAX_VALUE,result->asyncResponse.resume(result))); }
@DELETE @PreAuthorize("isAuthenticated() and hasPermission(null, 'MANAGE_PLUGIN')") @ApiOperation(value = "Delete Plugin", notes = "Deletes plugin in DH Server") @ApiResponses(value = { @ApiResponse(code = 403, message = "If principal does not have access to the plugin"), @ApiResponse(code = 404, message = "If plugin not found") }) void delete( @QueryParam("topicName") String topicName, @ApiParam(name = "Authorization", value = "Authorization token", required = true) @HeaderParam("Authorization") String authorization, @Suspended final AsyncResponse asyncResponse); }
@GET @Path("/{name}/value") @Produces(MediaType.APPLICATION_JSON) public void get(@PathParam("name") String name, @Suspended AsyncResponse response) { getPrimitive(name).thenCompose(value -> value.get()).whenComplete((result, error) -> { if (error == null) { response.resume(Response.ok(result).build()); } else { LOGGER.warn("{}", error); response.resume(Response.serverError().build()); } }); }
@GET @Path("/v1/info") @Produces(APPLICATION_JSON) public void getInfo( @Context HttpServletRequest servletRequest, @Suspended AsyncResponse asyncResponse) { Request.Builder request = prepareGet() .setUri(uriBuilderFrom(remoteUri).replacePath("/v1/info").build()); performRequest(servletRequest, asyncResponse, request, response -> responseWithHeaders(Response.ok(response.getBody()), response)); }
@POST @ManagedAsync @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Path("/segments") @ApiOperation(value = "Upload a segment", notes = "Upload a segment as json") // We use this endpoint with URI upload because a request sent with the multipart content type will reject the POST // request if a multipart object is not sent. This endpoint does not move the segment to its final location; // it keeps it at the downloadURI header that is set. We will not support this endpoint going forward. public void uploadSegmentAsJson(String segmentJsonStr, @ApiParam(value = "Whether to enable parallel push protection") @DefaultValue("false") @QueryParam(FileUploadDownloadClient.QueryParameters.ENABLE_PARALLEL_PUSH_PROTECTION) boolean enableParallelPushProtection, @Context HttpHeaders headers, @Context Request request, @Suspended final AsyncResponse asyncResponse) { try { asyncResponse.resume(uploadSegment(null, enableParallelPushProtection, headers, request, false)); } catch (Throwable t) { asyncResponse.resume(t); } }
@POST @PreAuthorize("isAuthenticated() and hasPermission(null, 'MANAGE_PLUGIN')") @ApiOperation(value = "Register Plugin", notes = "Registers plugin in DH Server") @ApiResponses(value = { @ApiResponse(code = 200, message = "Returns plugin uuid, topic name and health check period", response = PluginVO.class), }) void register( @BeanParam PluginReqisterQuery pluginReqisterQuery, @ApiParam(value = "Filter body", defaultValue = "{}", required = true) PluginUpdate filterToCreate, @ApiParam(name = "Authorization", value = "Authorization token", required = true) @HeaderParam("Authorization") String authorization, @Suspended final AsyncResponse asyncResponse);
@DELETE @Path("/{name}/lock") public void unlock(@PathParam("name") String name, @Suspended AsyncResponse response) { getPrimitive(name).thenCompose(lock -> lock.unlock()).whenComplete((result, error) -> { if (error == null) { response.resume(Response.ok().build()); } else { LOGGER.warn("{}", error); response.resume(Response.serverError().build()); } }); } }