Package com.ning.http.client

Examples of com.ning.http.client.AsyncHttpClient


        ExecutorService applicationThreadPool = Executors.newFixedThreadPool((Runtime.getRuntime().availableProcessors() * 2)+1,
                       new NamingThreadFactory("CHMQ-HttpClient-Callback", true));
  httpConfigBuilder.setExecutorService(applicationThreadPool);
  httpConfigBuilder.setIOThreadMultiplier(2); //This is the default

  http = new AsyncHttpClient(httpConfigBuilder.build());
  // in the old Apache HTTP client
        // - turn off TCP_NODELAY
        // - disable using http 100 expect
    }
View Full Code Here


    AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()
        .addRequestFilter(new ThrottleRequestFilter(MAX_CONNECTIONS))
        .setConnectionTimeoutInMs(CONNECTION_TIMEOUT)
        .setIdleConnectionInPoolTimeoutInMs(IDLE_CONNECTION_TIMEOUT)
        .setRequestTimeoutInMs(REQUEST_TIMEOUT).setMaxRequestRetry(0).build();
    this.asyncHttpClient = new AsyncHttpClient(config);
  }
View Full Code Here

            prov = new com.ning.http.client.providers.netty.NettyAsyncHttpProvider(ahcConfig);
        } else {
            if (true) throw new UnsupportedOperationException("No Grizzly provider");
    //         prov = new com.ning.http.client.providers.grizzly.GrizzlyAsyncHttpProvider(ahcConfig);
        }
        _ahc = new AsyncHttpClient(prov, ahcConfig);
    }
View Full Code Here

        builder.setConnectionTimeoutInMs( (int) configuration.getConnectionTimeOut() );
        builder.setMaximumConnectionsTotal( configuration.getMaxConcurentConnections() );

        String httpProviderClassName = configuration.getHttpProviderClassName();

        asyncHttpClient = new AsyncHttpClient(
            httpProviderClassName != null ? httpProviderClassName : NettyAsyncHttpProvider.class.getName(),
            configuration.getAsyncHttpClientConfig() == null
                ? builder.build()
                : configuration.getAsyncHttpClientConfig() );
    }
View Full Code Here

    @Produce(uri = "direct:shop")
    private ProducerTemplate producer;

    @Test
    public void testWSHttpCall() throws Exception {
        AsyncHttpClient c = new AsyncHttpClient();

        WebSocket websocket = c.prepareGet("ws://127.0.0.1:9292/shop").execute(
            new WebSocketUpgradeHandler.Builder()
                .addWebSocketListener(new WebSocketTextListener() {
                    @Override
                    public void onMessage(String message) {
                        received.add(message);
                        log.info("received --> " + message);
                        latch.countDown();
                    }

                    @Override
                    public void onFragment(String fragment, boolean last) {
                    }

                    @Override
                    public void onOpen(WebSocket websocket) {
                    }

                    @Override
                    public void onClose(WebSocket websocket) {
                    }

                    @Override
                    public void onError(Throwable t) {
                        t.printStackTrace();
                    }
                }).build()).get();

        // Send message to the direct endpoint
        producer.sendBodyAndHeader("Beer on stock at Apache Mall", WebsocketConstants.SEND_TO_ALL, "true");

        assertTrue(latch.await(10, TimeUnit.SECONDS));

        assertEquals(1, received.size());
        assertEquals("Beer on stock at Apache Mall", received.get(0));

        websocket.close();
        c.close();
    }
View Full Code Here

        // We call the route WebSocket BAR
        received.clear();
        latch = new CountDownLatch(1);

        AsyncHttpClient c = new AsyncHttpClient();

        WebSocket websocket = c.prepareGet("ws://127.0.0.1:9292/bar").execute(
            new WebSocketUpgradeHandler.Builder()
                .addWebSocketListener(new WebSocketTextListener() {
                    @Override
                    public void onMessage(String message) {
                        received.add(message);
                        log.info("received --> " + message);
                        latch.countDown();
                    }

                    @Override
                    public void onFragment(String fragment, boolean last) {
                    }

                    @Override
                    public void onOpen(WebSocket websocket) {
                    }

                    @Override
                    public void onClose(WebSocket websocket) {
                    }

                    @Override
                    public void onError(Throwable t) {
                        t.printStackTrace();
                    }
                }).build()).get();

        websocket.sendTextMessage("Beer");
        assertTrue(latch.await(10, TimeUnit.SECONDS));

        assertEquals(1, received.size());
        assertEquals("The bar has Beer", received.get(0));

        websocket.close();
        c.close();

        // We call the route WebSocket PUB
        received.clear();
        latch = new CountDownLatch(1);

        c = new AsyncHttpClient();

        websocket = c.prepareGet("ws://127.0.0.1:9292/pub").execute(
                new WebSocketUpgradeHandler.Builder()
                        .addWebSocketListener(new WebSocketTextListener() {
                            @Override
                            public void onMessage(String message) {
                                received.add(message);
                                log.info("received --> " + message);
                                latch.countDown();
                            }

                            @Override
                            public void onFragment(String fragment, boolean last) {
                            }

                            @Override
                            public void onOpen(WebSocket websocket) {
                            }

                            @Override
                            public void onClose(WebSocket websocket) {
                            }

                            @Override
                            public void onError(Throwable t) {
                                t.printStackTrace();
                            }
                        }).build()).get();

        websocket.sendTextMessage("wine");
        assertTrue(latch.await(10, TimeUnit.SECONDS));

        assertEquals(1, received.size());
        assertEquals("The pub has wine", received.get(0));

        websocket.close();
        c.close();
    }
View Full Code Here

public class WebsocketConsumerRouteTest extends CamelTestSupport {
   
    @Test
    public void testWSHttpCall() throws Exception {
        AsyncHttpClient c = new AsyncHttpClient();

        WebSocket websocket = c.prepareGet("ws://127.0.0.1:9292/echo").execute(
            new WebSocketUpgradeHandler.Builder()
                .addWebSocketListener(new WebSocketTextListener() {
                    @Override
                    public void onMessage(String message) {
                       
                    }

                    @Override
                    public void onFragment(String fragment, boolean last) {
                    }

                    @Override
                    public void onOpen(WebSocket websocket) {
                    }

                    @Override
                    public void onClose(WebSocket websocket) {
                    }

                    @Override
                    public void onError(Throwable t) {
                        t.printStackTrace();
                    }
                }).build()).get();
       
        MockEndpoint result = getMockEndpoint("mock:result");
        result.expectedBodiesReceived("Test");

        websocket.sendTextMessage("Test");

        result.assertIsSatisfied();
       
        websocket.close();
        c.close();
    }
View Full Code Here

        originalValues.put(key, originalValue != null ? originalValue : NULL_VALUE_MARKER);
    }

    protected AsyncHttpClient createAsyncHttpSSLClient() throws IOException, GeneralSecurityException {

        AsyncHttpClient c;
        AsyncHttpClientConfig config;

        AsyncHttpClientConfig.Builder builder =
                new AsyncHttpClientConfig.Builder();

        builder.setSSLContext(new SSLContextParameters().createSSLContext());
        config = builder.build();
        c = new AsyncHttpClient(config);

        return c;
    }
View Full Code Here

    }

    @Test
    public void testWSHttpCall() throws Exception {

        AsyncHttpClient c = createAsyncHttpSSLClient();
        WebSocket websocket = c.prepareGet("wss://127.0.0.1:8443/test").execute(
                new WebSocketUpgradeHandler.Builder()
                        .addWebSocketListener(new WebSocketTextListener() {
                            @Override
                            public void onMessage(String message) {
                                received.add(message);
                                log.info("received --> " + message);
                                latch.countDown();
                            }

                            @Override
                            public void onFragment(String fragment, boolean last) {
                            }

                            @Override
                            public void onOpen(WebSocket websocket) {
                            }

                            @Override
                            public void onClose(WebSocket websocket) {
                            }

                            @Override
                            public void onError(Throwable t) {
                                t.printStackTrace();
                            }
                        }).build()).get();

        getMockEndpoint("mock:client").expectedBodiesReceived("Hello from WS client");

        websocket.sendTextMessage("Hello from WS client");
        assertTrue(latch.await(10, TimeUnit.SECONDS));

        assertMockEndpointsSatisfied();

        assertEquals(10, received.size());
        for (int i = 0; i < 10; i++) {
            assertEquals(">> Welcome on board!", received.get(i));
        }

        websocket.close();
        c.close();
    }
View Full Code Here

    private static List<String> received = new ArrayList<String>();
    private static CountDownLatch latch = new CountDownLatch(1);

    @Test
    public void testWSHttpCall() throws Exception {
        AsyncHttpClient c = new AsyncHttpClient();

        WebSocket websocket = c.prepareGet("ws://localhost:9494/echo").execute(
            new WebSocketUpgradeHandler.Builder()
                .addWebSocketListener(new WebSocketTextListener() {
                    @Override
                    public void onMessage(String message) {
                        received.add(message);
                        log.info("received --> " + message);
                        latch.countDown();
                    }

                    @Override
                    public void onFragment(String fragment, boolean last) {
                    }

                    @Override
                    public void onOpen(WebSocket websocket) {
                    }

                    @Override
                    public void onClose(WebSocket websocket) {
                    }

                    @Override
                    public void onError(Throwable t) {
                        t.printStackTrace();
                    }
                }).build()).get();

        websocket.sendTextMessage("Beer");
        assertTrue(latch.await(10, TimeUnit.SECONDS));

        assertEquals(1, received.size());
        assertEquals("BeerBeer", received.get(0));

        websocket.close();
        c.close();
    }
View Full Code Here

TOP

Related Classes of com.ning.http.client.AsyncHttpClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.