Search in sources :

Example 11 with AsyncHttpClient

use of com.ning.http.client.AsyncHttpClient in project rxrabbit by meltwater.

the class RxRabbitTests method setup.

@Before
public void setup() throws Exception {
    dockerContainers.rabbit().assertUp();
    rabbitTcpPort = dockerContainers.rabbit().tcpPort();
    rabbitAdminPort = dockerContainers.rabbit().adminPort();
    log.infoWithParams("****** Rabbit broker is up and running *****");
    BrokerAddresses addresses = new BrokerAddresses("amqp://localhost:" + rabbitTcpPort);
    channelFactory = new DefaultChannelFactory(addresses, connectionSettings);
    consumerFactory = new DefaultConsumerFactory(channelFactory, consumeSettings);
    publisherFactory = new DefaultPublisherFactory(channelFactory, publishSettings);
    httpClient = new AsyncHttpClient();
    messagesSeen.clear();
    createQueues(channelFactory, inputQueue, new Exchange(inputExchange));
    publisher = publisherFactory.createPublisher();
    RxJavaHooks.setOnIOScheduler(null);
}
Also used : DefaultChannelFactory(com.meltwater.rxrabbit.impl.DefaultChannelFactory) AsyncHttpClient(com.ning.http.client.AsyncHttpClient) Before(org.junit.Before)

Example 12 with AsyncHttpClient

use of com.ning.http.client.AsyncHttpClient in project pinpoint by naver.

the class NingAsyncHttpClientIT method test.

@Test
public void test() throws Exception {
    AsyncHttpClient client = new AsyncHttpClient();
    try {
        Future<Response> f = client.preparePost(webServer.getCallHttpUrl()).addParameter("param1", "value1").execute();
        Response response = f.get();
    } finally {
        client.close();
    }
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    verifier.printCache();
    String destinationId = webServer.getHostAndPort();
    String httpUrl = webServer.getCallHttpUrl();
    verifier.verifyTrace(event("ASYNC_HTTP_CLIENT", AsyncHttpClient.class.getMethod("executeRequest", Request.class, AsyncHandler.class), null, null, destinationId, annotation("http.url", httpUrl)));
    verifier.verifyTraceCount(0);
}
Also used : Response(com.ning.http.client.Response) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) AsyncHttpClient(com.ning.http.client.AsyncHttpClient) Test(org.junit.Test)

Example 13 with AsyncHttpClient

use of com.ning.http.client.AsyncHttpClient in project apex-malhar by apache.

the class WebSocketOutputOperator method openConnection.

private void openConnection() throws IOException, ExecutionException, InterruptedException, TimeoutException {
    final AsyncHttpClientConfigBean config = new AsyncHttpClientConfigBean();
    config.setIoThreadMultiplier(ioThreadMultiplier);
    config.setApplicationThreadPool(Executors.newCachedThreadPool(new ThreadFactory() {

        @Override
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r);
            t.setName(ClassUtils.getShortClassName(this.getClass()) + "-AsyncHttpClient-" + count++);
            return t;
        }
    }));
    client = new AsyncHttpClient(config);
    // force reparse after deserialization
    uri = URI.create(uri.toString());
    LOG.info("Opening URL: {}", uri);
    connection = client.prepareGet(uri.toString()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketTextListener() {

        @Override
        public void onMessage(String string) {
        }

        @Override
        public void onOpen(WebSocket ws) {
            LOG.debug("Connection opened");
        }

        @Override
        public void onClose(WebSocket ws) {
            LOG.debug("Connection closed.");
        }

        @Override
        public void onError(Throwable t) {
            LOG.error("Caught exception", t);
        }
    }).build()).get(5, TimeUnit.SECONDS);
}
Also used : AsyncHttpClientConfigBean(org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClientConfigBean) ThreadFactory(java.util.concurrent.ThreadFactory) WebSocketTextListener(org.apache.apex.shaded.ning19.com.ning.http.client.ws.WebSocketTextListener) WebSocketUpgradeHandler(org.apache.apex.shaded.ning19.com.ning.http.client.ws.WebSocketUpgradeHandler) AsyncHttpClient(org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClient) WebSocket(org.apache.apex.shaded.ning19.com.ning.http.client.ws.WebSocket)

Example 14 with AsyncHttpClient

use of com.ning.http.client.AsyncHttpClient in project apex-malhar by apache.

the class WebSocketInputOperator method run.

@Override
public void run() {
    try {
        connectionClosed = false;
        AsyncHttpClientConfigBean config = new AsyncHttpClientConfigBean();
        config.setIoThreadMultiplier(ioThreadMultiplier);
        config.setApplicationThreadPool(Executors.newCachedThreadPool(new ThreadFactory() {

            private long count = 0;

            @Override
            public Thread newThread(Runnable r) {
                Thread t = new Thread(r);
                t.setName(ClassUtils.getShortClassName(this.getClass()) + "-AsyncHttpClient-" + count++);
                return t;
            }
        }));
        if (client != null) {
            client.closeAsynchronously();
        }
        client = new AsyncHttpClient(config);
        connection = client.prepareGet(uri.toString()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketTextListener() {

            @Override
            public void onMessage(String string) {
                try {
                    T o = convertMessage(string);
                    if (!(skipNull && o == null)) {
                        outputPort.emit(o);
                    }
                } catch (IOException ex) {
                    LOG.error("Got exception: ", ex);
                }
            }

            @Override
            public void onOpen(WebSocket ws) {
                LOG.debug("Connection opened");
            }

            @Override
            public void onClose(WebSocket ws) {
                LOG.debug("Connection connectionClosed.");
                connectionClosed = true;
            }

            @Override
            public void onError(Throwable t) {
                LOG.error("Caught exception", t);
            }
        }).build()).get(5, TimeUnit.SECONDS);
    } catch (Exception ex) {
        LOG.error("Error reading from " + uri, ex);
        if (client != null) {
            client.close();
        }
        connectionClosed = true;
    }
}
Also used : AsyncHttpClientConfigBean(org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClientConfigBean) ThreadFactory(java.util.concurrent.ThreadFactory) WebSocketTextListener(org.apache.apex.shaded.ning19.com.ning.http.client.ws.WebSocketTextListener) IOException(java.io.IOException) WebSocketUpgradeHandler(org.apache.apex.shaded.ning19.com.ning.http.client.ws.WebSocketUpgradeHandler) IOException(java.io.IOException) WebSocket(org.apache.apex.shaded.ning19.com.ning.http.client.ws.WebSocket) AsyncHttpClient(org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClient)

Aggregations

AsyncHttpClient (com.ning.http.client.AsyncHttpClient)12 AsyncHttpClientConfig (com.ning.http.client.AsyncHttpClientConfig)6 RequestBuilder (com.ning.http.client.RequestBuilder)5 Response (com.ning.http.client.Response)5 IOException (java.io.IOException)5 Test (org.junit.Test)5 Request (com.ning.http.client.Request)3 NettyAsyncHttpProvider (com.ning.http.client.providers.netty.NettyAsyncHttpProvider)3 HttpRequest (io.netty.handler.codec.http.HttpRequest)3 URISyntaxException (java.net.URISyntaxException)3 DefaultChannelFactory (com.meltwater.rxrabbit.impl.DefaultChannelFactory)2 HttpResponseBodyPart (com.ning.http.client.HttpResponseBodyPart)2 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ExecutionException (java.util.concurrent.ExecutionException)2 ThreadFactory (java.util.concurrent.ThreadFactory)2 AsyncHttpClient (org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClient)2 AsyncHttpClientConfigBean (org.apache.apex.shaded.ning19.com.ning.http.client.AsyncHttpClientConfigBean)2 WebSocket (org.apache.apex.shaded.ning19.com.ning.http.client.ws.WebSocket)2 WebSocketTextListener (org.apache.apex.shaded.ning19.com.ning.http.client.ws.WebSocketTextListener)2