use of javax.ws.rs.container.AsyncResponse in project presto by prestodb.
the class ExecutingStatementResource method getQueryResults.
@GET
@Path("/v1/statement/executing/{queryId}/{token}")
@Produces(MediaType.APPLICATION_JSON)
public void getQueryResults(@PathParam("queryId") QueryId queryId, @PathParam("token") long token, @QueryParam("slug") String slug, @QueryParam("maxWait") Duration maxWait, @QueryParam("targetResultSize") DataSize targetResultSize, @HeaderParam(X_FORWARDED_PROTO) String proto, @Context UriInfo uriInfo, @Suspended AsyncResponse asyncResponse) {
Duration wait = WAIT_ORDERING.min(MAX_WAIT_TIME, maxWait);
if (targetResultSize == null) {
targetResultSize = DEFAULT_TARGET_RESULT_SIZE;
} else {
targetResultSize = Ordering.natural().min(targetResultSize, MAX_TARGET_RESULT_SIZE);
}
if (isNullOrEmpty(proto)) {
proto = uriInfo.getRequestUri().getScheme();
}
Query query = queryProvider.getQuery(queryId, slug);
ListenableFuture<Response> queryResultsFuture = transform(query.waitForResults(token, uriInfo, proto, wait, targetResultSize), results -> toResponse(query, results, compressionEnabled), directExecutor());
bindAsyncResponse(asyncResponse, queryResultsFuture, responseExecutor);
}
use of javax.ws.rs.container.AsyncResponse in project presto by prestodb.
the class ProxyResource method performRequest.
private void performRequest(HttpServletRequest servletRequest, AsyncResponse asyncResponse, Request.Builder requestBuilder, Function<ProxyResponse, Response> responseBuilder) {
setupXForwardedFor(servletRequest, requestBuilder);
setupBearerToken(servletRequest, requestBuilder);
for (String name : list(servletRequest.getHeaderNames())) {
if (isPrestoHeader(name) || name.equalsIgnoreCase(COOKIE)) {
for (String value : list(servletRequest.getHeaders(name))) {
requestBuilder.addHeader(name, value);
}
} else if (name.equalsIgnoreCase(USER_AGENT)) {
for (String value : list(servletRequest.getHeaders(name))) {
requestBuilder.addHeader(name, "[Presto Proxy] " + value);
}
}
}
Request request = requestBuilder.setPreserveAuthorizationOnRedirect(true).build();
ListenableFuture<Response> future = executeHttp(request).transform(responseBuilder::apply, executor).catching(ProxyException.class, e -> handleProxyException(request, e), directExecutor());
setupAsyncResponse(asyncResponse, future);
}
use of javax.ws.rs.container.AsyncResponse in project component-runtime by Talend.
the class ExecutionResource method read.
/**
* Read inputs from an instance of mapper. The number of returned records if enforced to be limited to 1000.
* The format is a JSON based format where each like is a json record.
*
* @param family the component family.
* @param component the component name.
* @param size the maximum number of records to read.
* @param configuration the component configuration as key/values.
*/
@POST
@Deprecated
@Produces("talend/stream")
@Path("read/{family}/{component}")
public void read(@Suspended final AsyncResponse response, @Context final Providers providers, @PathParam("family") final String family, @PathParam("component") final String component, @QueryParam("size") @DefaultValue("50") final long size, final Map<String, String> configuration) {
final long maxSize = Math.min(size, MAX_RECORDS);
response.setTimeoutHandler(asyncResponse -> log.warn("Timeout on dataset retrieval"));
response.setTimeout(appConfiguration.datasetRetrieverTimeout(), SECONDS);
executorService.submit(() -> {
final Optional<Mapper> mapperOptional = manager.findMapper(family, component, getConfigComponentVersion(configuration), configuration);
if (!mapperOptional.isPresent()) {
response.resume(new WebApplicationException(Response.status(BAD_REQUEST).entity(new ErrorPayload(COMPONENT_MISSING, "Didn't find the input component")).build()));
return;
}
final Mapper mapper = mapperOptional.get();
mapper.start();
try {
final Input input = mapper.create();
try {
input.start();
response.resume((StreamingOutput) output -> {
Object data;
int current = 0;
while (current++ < maxSize && (data = input.next()) != null) {
if (CharSequence.class.isInstance(data) || Number.class.isInstance(data) || Boolean.class.isInstance(data)) {
final PrimitiveWrapper wrapper = new PrimitiveWrapper();
wrapper.setValue(data);
data = wrapper;
}
inlineStreamingMapper.toJson(data, output);
output.write(EOL);
}
});
} finally {
input.stop();
}
} finally {
mapper.stop();
}
});
}
Aggregations