Search in sources :

Example 76 with Response

use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.

the class HttpsProxyTest method testRequestProxy.

@Test(groups = "standalone")
public void testRequestProxy() throws Exception {
    try (AsyncHttpClient asyncHttpClient = asyncHttpClient(config().setFollowRedirect(true).setUseInsecureTrustManager(true))) {
        RequestBuilder rb = get(getTargetUrl2()).setProxyServer(proxyServer("localhost", port1));
        Response r = asyncHttpClient.executeRequest(rb.build()).get();
        assertEquals(r.getStatusCode(), 200);
    }
}
Also used : Response(org.asynchttpclient.Response) RequestBuilder(org.asynchttpclient.RequestBuilder) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test) AbstractBasicTest(org.asynchttpclient.AbstractBasicTest)

Example 77 with Response

use of org.asynchttpclient.Response in project async-http-client by AsyncHttpClient.

the class HttpsProxyTest method testPooledConnectionsWithProxy.

@Test(groups = "standalone")
public void testPooledConnectionsWithProxy() throws Exception {
    try (AsyncHttpClient asyncHttpClient = asyncHttpClient(config().setFollowRedirect(true).setUseInsecureTrustManager(true).setKeepAlive(true))) {
        RequestBuilder rb = get(getTargetUrl2()).setProxyServer(proxyServer("localhost", port1));
        Response r1 = asyncHttpClient.executeRequest(rb.build()).get();
        assertEquals(r1.getStatusCode(), 200);
        Response r2 = asyncHttpClient.executeRequest(rb.build()).get();
        assertEquals(r2.getStatusCode(), 200);
    }
}
Also used : Response(org.asynchttpclient.Response) RequestBuilder(org.asynchttpclient.RequestBuilder) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test) AbstractBasicTest(org.asynchttpclient.AbstractBasicTest)

Example 78 with Response

use of org.asynchttpclient.Response in project RestyPass by darren-fu.

the class RestyFuture method get.

@SuppressWarnings("NullableProblems")
@Override
public T get(long timeout, TimeUnit unit) throws RestyException {
    Response response;
    try {
        response = future.get(timeout, unit);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        future.abort(e);
        log.error("获取响应失败:{}", e.getMessage());
        if (this.getRestyCommand().isAsyncArg() || this.getRestyCommand().isAsyncReturn()) {
            throw new RestyException(e);
        }
        response = FailedResponse.create(new ConnectionException(e));
    }
    T resp = (T) ResponseConverterContext.DEFAULT.convertResponse(restyCommand, response);
    if (restyCommand.isAsyncReturn() || restyCommand.isAsyncArg()) {
        if (RestyCommandStatus.FAILED == restyCommand.getStatus() && restyCommand.getFailException() != null) {
            throw restyCommand.getFailException();
        }
    }
    return resp;
}
Also used : FailedResponse(com.github.df.restypass.http.pojo.FailedResponse) Response(org.asynchttpclient.Response) RestyException(com.github.df.restypass.exception.execute.RestyException) ExecutionException(java.util.concurrent.ExecutionException) ConnectionException(com.github.df.restypass.exception.execute.ConnectionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 79 with Response

use of org.asynchttpclient.Response in project bullet-core by yahoo.

the class RESTPubSubTest method mockBuilderWith.

public static BoundRequestBuilder mockBuilderWith(CompletableFuture<Response> future) throws Exception {
    ListenableFuture<Response> mockListenable = (ListenableFuture<Response>) mock(ListenableFuture.class);
    doReturn(future.get()).when(mockListenable).get();
    doReturn(future).when(mockListenable).toCompletableFuture();
    BoundRequestBuilder mockBuilder = mock(BoundRequestBuilder.class);
    doReturn(mockBuilder).when(mockBuilder).setHeader(any(), anyString());
    doReturn(mockBuilder).when(mockBuilder).setBody(anyString());
    doReturn(mockListenable).when(mockBuilder).execute();
    return mockBuilder;
}
Also used : Response(org.asynchttpclient.Response) BoundRequestBuilder(org.asynchttpclient.BoundRequestBuilder) ListenableFuture(org.asynchttpclient.ListenableFuture)

Example 80 with Response

use of org.asynchttpclient.Response in project bullet-core by yahoo.

the class RESTQueryPublisherTest method testSendMetadataCreated.

@Test
public void testSendMetadataCreated() throws Exception {
    CompletableFuture<Response> response = getOkFuture(getOkResponse(null));
    BoundRequestBuilder mockBuilder = mockBuilderWith(response);
    AsyncHttpClient mockClient = mockClientWith(mockBuilder);
    RESTQueryPublisher publisher = new RESTQueryPublisher(mockClient, "my/custom/query/url", "my/custom/result/url");
    publisher.send("foo", "bar");
    verify(mockClient).preparePost("my/custom/query/url");
    verify(mockBuilder).setBody("{\"id\":\"foo\",\"sequence\":-1,\"content\":\"bar\",\"metadata\":{\"signal\":null,\"content\":\"my/custom/result/url\"}}");
    verify(mockBuilder).setHeader(RESTPublisher.CONTENT_TYPE, RESTPublisher.APPLICATION_JSON);
}
Also used : Response(org.asynchttpclient.Response) RESTPubSubTest.getOkResponse(com.yahoo.bullet.pubsub.rest.RESTPubSubTest.getOkResponse) RESTPubSubTest.getNotOkResponse(com.yahoo.bullet.pubsub.rest.RESTPubSubTest.getNotOkResponse) BoundRequestBuilder(org.asynchttpclient.BoundRequestBuilder) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient) Test(org.testng.annotations.Test)

Aggregations

Response (org.asynchttpclient.Response)142 Test (org.testng.annotations.Test)85 AsyncHttpClient (org.asynchttpclient.AsyncHttpClient)79 AbstractBasicTest (org.asynchttpclient.AbstractBasicTest)55 HttpServletResponse (javax.servlet.http.HttpServletResponse)42 BoundRequestBuilder (org.asynchttpclient.BoundRequestBuilder)32 Request (org.asynchttpclient.Request)29 IOException (java.io.IOException)21 Test (org.junit.Test)20 ExecutionException (java.util.concurrent.ExecutionException)16 PubSubMessage (com.yahoo.bullet.pubsub.PubSubMessage)14 RESTPubSubTest.getOkResponse (com.yahoo.bullet.pubsub.rest.RESTPubSubTest.getOkResponse)11 TimeoutException (java.util.concurrent.TimeoutException)11 RequestBuilder (org.asynchttpclient.RequestBuilder)11 UnitEvent (org.apache.druid.java.util.emitter.service.UnitEvent)10 RESTPubSubTest.getNotOkResponse (com.yahoo.bullet.pubsub.rest.RESTPubSubTest.getNotOkResponse)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 Map (java.util.Map)9 AuthorizationException (org.apache.shiro.authz.AuthorizationException)9 TestUtils.createTempFile (org.asynchttpclient.test.TestUtils.createTempFile)9