use of javax.ws.rs.container.AsyncResponse in project camunda-bpm-platform by camunda.
the class FetchAndLockHandlerTest method shouldResumeAsyncResponseImmediatelyDueToProcessEngineException.
@Test
public void shouldResumeAsyncResponseImmediatelyDueToProcessEngineException() {
// given
doThrow(new ProcessEngineException()).when(fetchTopicBuilder).execute();
// when
AsyncResponse asyncResponse = mock(AsyncResponse.class);
handler.addPendingRequest(createDto(5000L), asyncResponse, processEngine);
// Then
assertThat(handler.getPendingRequests().size(), is(0));
verify(handler, never()).suspend(anyLong());
verify(asyncResponse).resume(any(ProcessEngineException.class));
}
use of javax.ws.rs.container.AsyncResponse in project incubator-pulsar by apache.
the class HttpTopicLookupv2Test method crossColoLookup.
@Test
public void crossColoLookup() throws Exception {
TopicLookup destLookup = spy(new TopicLookup());
doReturn(false).when(destLookup).isRequestHttps();
destLookup.setPulsar(pulsar);
doReturn("null").when(destLookup).clientAppId();
Field uriField = PulsarWebResource.class.getDeclaredField("uri");
uriField.setAccessible(true);
UriInfo uriInfo = mock(UriInfo.class);
uriField.set(destLookup, uriInfo);
URI uri = URI.create("http://localhost:8080/lookup/v2/destination/topic/myprop/usc/ns2/topic1");
doReturn(uri).when(uriInfo).getRequestUri();
doReturn(true).when(config).isAuthorizationEnabled();
AsyncResponse asyncResponse = mock(AsyncResponse.class);
destLookup.lookupTopicAsync(TopicDomain.persistent.value(), "myprop", "usc", "ns2", "topic1", false, asyncResponse);
ArgumentCaptor<Throwable> arg = ArgumentCaptor.forClass(Throwable.class);
verify(asyncResponse).resume(arg.capture());
assertEquals(arg.getValue().getClass(), WebApplicationException.class);
WebApplicationException wae = (WebApplicationException) arg.getValue();
assertEquals(wae.getResponse().getStatus(), Status.TEMPORARY_REDIRECT.getStatusCode());
}
use of javax.ws.rs.container.AsyncResponse in project incubator-pulsar by apache.
the class HttpTopicLookupv2Test method testValidateReplicationSettingsOnNamespace.
@Test
public void testValidateReplicationSettingsOnNamespace() throws Exception {
final String property = "my-prop";
final String cluster = "global";
final String ns1 = "ns1";
final String ns2 = "ns2";
Policies policies1 = new Policies();
doReturn(Optional.of(policies1)).when(policiesCache).get(AdminResource.path(POLICIES, property, cluster, ns1));
Policies policies2 = new Policies();
policies2.replication_clusters = Lists.newArrayList("invalid-localCluster");
doReturn(Optional.of(policies2)).when(policiesCache).get(AdminResource.path(POLICIES, property, cluster, ns2));
TopicLookup destLookup = spy(new TopicLookup());
doReturn(false).when(destLookup).isRequestHttps();
destLookup.setPulsar(pulsar);
doReturn("null").when(destLookup).clientAppId();
Field uriField = PulsarWebResource.class.getDeclaredField("uri");
uriField.setAccessible(true);
UriInfo uriInfo = mock(UriInfo.class);
uriField.set(destLookup, uriInfo);
doReturn(false).when(config).isAuthorizationEnabled();
AsyncResponse asyncResponse = mock(AsyncResponse.class);
destLookup.lookupTopicAsync(TopicDomain.persistent.value(), property, cluster, ns1, "empty-cluster", false, asyncResponse);
ArgumentCaptor<Throwable> arg = ArgumentCaptor.forClass(Throwable.class);
verify(asyncResponse).resume(arg.capture());
assertEquals(arg.getValue().getClass(), RestException.class);
AsyncResponse asyncResponse2 = mock(AsyncResponse.class);
destLookup.lookupTopicAsync(TopicDomain.persistent.value(), property, cluster, ns2, "invalid-localCluster", false, asyncResponse2);
ArgumentCaptor<Throwable> arg2 = ArgumentCaptor.forClass(Throwable.class);
verify(asyncResponse2).resume(arg2.capture());
// Should have raised exception for invalid cluster
assertEquals(arg2.getValue().getClass(), RestException.class);
}
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);
}
Aggregations