Search in sources :

Example 46 with AsyncResponse

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));
}
Also used : AsyncResponse(javax.ws.rs.container.AsyncResponse) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Test(org.junit.Test)

Example 47 with AsyncResponse

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());
}
Also used : TopicLookup(org.apache.pulsar.broker.lookup.TopicLookup) Field(java.lang.reflect.Field) WebApplicationException(javax.ws.rs.WebApplicationException) AsyncResponse(javax.ws.rs.container.AsyncResponse) URI(java.net.URI) UriInfo(javax.ws.rs.core.UriInfo) Test(org.testng.annotations.Test)

Example 48 with AsyncResponse

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);
}
Also used : TopicLookup(org.apache.pulsar.broker.lookup.TopicLookup) Field(java.lang.reflect.Field) Policies(org.apache.pulsar.common.policies.data.Policies) AsyncResponse(javax.ws.rs.container.AsyncResponse) UriInfo(javax.ws.rs.core.UriInfo) Test(org.testng.annotations.Test)

Example 49 with AsyncResponse

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);
}
Also used : AsyncResponseHandler.bindAsyncResponse(com.facebook.airlift.http.server.AsyncResponseHandler.bindAsyncResponse) AsyncResponse(javax.ws.rs.container.AsyncResponse) Response(javax.ws.rs.core.Response) QueryResourceUtil.toResponse(com.facebook.presto.server.protocol.QueryResourceUtil.toResponse) Duration(io.airlift.units.Duration) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 50 with AsyncResponse

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);
}
Also used : ProxyResponse(com.facebook.presto.proxy.ProxyResponseHandler.ProxyResponse) AsyncResponse(javax.ws.rs.container.AsyncResponse) Response(javax.ws.rs.core.Response) AsyncResponseHandler.bindAsyncResponse(com.facebook.airlift.http.server.AsyncResponseHandler.bindAsyncResponse) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(com.facebook.airlift.http.client.Request)

Aggregations

AsyncResponse (javax.ws.rs.container.AsyncResponse)54 Response (javax.ws.rs.core.Response)20 Test (org.junit.Test)14 CompletableFuture (java.util.concurrent.CompletableFuture)12 Path (javax.ws.rs.Path)11 Slf4j (lombok.extern.slf4j.Slf4j)11 List (java.util.List)10 GET (javax.ws.rs.GET)10 Suspended (javax.ws.rs.container.Suspended)10 WebApplicationException (javax.ws.rs.WebApplicationException)9 Status (javax.ws.rs.core.Response.Status)9 ArrayList (java.util.ArrayList)8 Context (javax.ws.rs.core.Context)8 MediaType (javax.ws.rs.core.MediaType)8 AuthHandler (io.pravega.auth.AuthHandler)6 READ (io.pravega.auth.AuthHandler.Permissions.READ)6 READ_UPDATE (io.pravega.auth.AuthHandler.Permissions.READ_UPDATE)6 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)6 ReaderGroupManagerImpl (io.pravega.client.admin.impl.ReaderGroupManagerImpl)6 ConnectionFactory (io.pravega.client.netty.impl.ConnectionFactory)6