Search in sources :

Example 6 with Hello

use of io.fabric8.demo.cxf.Hello in project fabric8 by jboss-fuse.

the class ExtendedBurnIn method startHttpGateway.

public HttpGatewayServer startHttpGateway() {
    if (restEndpointServer != null) {
        LoadBalancer loadBalancer = new RoundRobinLoadBalancer();
        ServiceDTO serviceDetails = new ServiceDTO();
        serviceDetails.setContainer("local");
        serviceDetails.setVersion("1");
        mappedServices.put("/hello/world", new MappedServices("http://localhost:8181", serviceDetails, loadBalancer, false));
    }
    DetectingGatewayWebSocketHandler websocketHandler = new DetectingGatewayWebSocketHandler();
    HttpGatewayHandler handler = new HttpGatewayHandler(vertx, new HttpGateway() {

        @Override
        public void addMappingRuleConfiguration(HttpMappingRule mappingRule) {
        }

        @Override
        public void removeMappingRuleConfiguration(HttpMappingRule mappingRule) {
        }

        @Override
        public Map<String, MappedServices> getMappedServices() {
            return mappedServices;
        }

        @Override
        public boolean isEnableIndex() {
            return true;
        }

        @Override
        public InetSocketAddress getLocalAddress() {
            return new InetSocketAddress("0.0.0.0", 8080);
        }

        @Override
        public void addCallDetailRecord(CallDetailRecord cdr) {
        }
    });
    websocketHandler.setPathPrefix("");
    httpGatewayServer = new HttpGatewayServer(vertx, handler, websocketHandler, 8080);
    httpGatewayServer.setHost("localhost");
    httpGatewayServer.init();
    return httpGatewayServer;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) RoundRobinLoadBalancer(io.fabric8.gateway.loadbalancer.RoundRobinLoadBalancer) LoadBalancer(io.fabric8.gateway.loadbalancer.LoadBalancer) RoundRobinLoadBalancer(io.fabric8.gateway.loadbalancer.RoundRobinLoadBalancer) DetectingGatewayWebSocketHandler(io.fabric8.gateway.handlers.detecting.DetectingGatewayWebSocketHandler)

Example 7 with Hello

use of io.fabric8.demo.cxf.Hello in project fabric8 by jboss-fuse.

the class ExtendedBurnIn method lotsOfClientLoad.

@Test
public void lotsOfClientLoad() throws Exception {
    startRestEndpoint();
    startHttpGateway();
    DetectingGateway gateway = startDetectingGateway();
    final ShutdownTracker tracker = new ShutdownTracker();
    // Run some concurrent load against the broker via the gateway...
    final StompJmsConnectionFactory factory = new StompJmsConnectionFactory();
    factory.setBrokerURI("tcp://localhost:" + gateway.getBoundPort());
    for (int client = 0; client < 10; client++) {
        new Thread("JMS Client: " + client) {

            @Override
            public void run() {
                while (tracker.attemptRetain()) {
                    try {
                        Connection connection = factory.createConnection();
                        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                        MessageConsumer consumer = session.createConsumer(session.createTopic("FOO"));
                        MessageProducer producer = session.createProducer(session.createTopic("FOO"));
                        producer.send(session.createTextMessage("Hello"));
                        consumer.receive(1000);
                        connection.close();
                    } catch (JMSException e) {
                        e.printStackTrace();
                    } finally {
                        tracker.release();
                    }
                }
            }
        }.start();
    }
    int httpPort = gateway.getBoundPort();
    final URL httpUrl = new URL("http://localhost:" + httpPort + "/hello/world");
    for (int client = 0; client < 10; client++) {
        new Thread("HTTP Client: " + client) {

            @Override
            public void run() {
                while (tracker.attemptRetain()) {
                    try {
                        InputStream is = httpUrl.openConnection().getInputStream();
                        try {
                            ByteArrayOutputStream baos = new ByteArrayOutputStream();
                            int c = 0;
                            while ((c = is.read()) >= 0) {
                                baos.write(c);
                            }
                            assertEquals("Hello World!", new String(baos.toByteArray()));
                        } finally {
                            is.close();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        tracker.release();
                    }
                }
            }
        }.start();
    }
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    // Lets monitor memory usage for 5 min..
    for (int i = 0; i < 60 * 5; i++) {
        Thread.sleep(900);
        Runtime.getRuntime().gc();
        Thread.sleep(100);
        long usedMB = ((Long) ((CompositeData) mBeanServer.getAttribute(new ObjectName("java.lang:type=Memory"), "HeapMemoryUsage")).get("used")).longValue() / (1024 * 1024);
        System.out.println("Using " + usedMB + " MB of heap.");
    }
    tracker.stop();
}
Also used : DetectingGateway(io.fabric8.gateway.handlers.detecting.DetectingGateway) InputStream(java.io.InputStream) CompositeData(javax.management.openmbean.CompositeData) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URL(java.net.URL) ObjectName(javax.management.ObjectName) ShutdownTracker(io.fabric8.common.util.ShutdownTracker) StompJmsConnectionFactory(org.fusesource.stomp.jms.StompJmsConnectionFactory) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 8 with Hello

use of io.fabric8.demo.cxf.Hello in project fabric8 by jboss-fuse.

the class HttpGatewayConnectionTimeoutTest method testConnectionTimeout.

@Test
public void testConnectionTimeout() throws Exception {
    startRestEndpoint();
    startHttpGateway();
    LOG.info("Requesting...");
    final FutureHandler<HttpClientResponse> future = new FutureHandler<>();
    vertx.createHttpClient().setHost("localhost").setPort(8080).get("/hello/world?wsdl", new Handler<HttpClientResponse>() {

        @Override
        public void handle(HttpClientResponse event) {
            future.handle(event);
        }
    }).end();
    HttpClientResponse response = future.await();
    assertEquals(response.statusCode(), 504);
    stopHttpGateway();
    stopVertx();
}
Also used : HttpClientResponse(org.vertx.java.core.http.HttpClientResponse) HttpGatewayHandler(io.fabric8.gateway.handlers.http.HttpGatewayHandler) FutureHandler(io.fabric8.gateway.handlers.detecting.FutureHandler) Handler(org.vertx.java.core.Handler) FutureHandler(io.fabric8.gateway.handlers.detecting.FutureHandler) Test(org.junit.Test)

Example 9 with Hello

use of io.fabric8.demo.cxf.Hello in project fabric8 by jboss-fuse.

the class HttpGatewayRequestTimeoutTest method testRequestTimeout.

@Test
public void testRequestTimeout() throws Exception {
    startRestEndpoint();
    startHttpGateway();
    LOG.info("Requesting...");
    final FutureHandler<HttpClientResponse> future = new FutureHandler<>();
    vertx.createHttpClient().setHost("localhost").setPort(8080).get("/hello/world?wsdl", new Handler<HttpClientResponse>() {

        @Override
        public void handle(HttpClientResponse event) {
            future.handle(event);
        }
    }).end();
    HttpClientResponse response = future.await();
    assertEquals(response.statusCode(), 504);
    stopHttpGateway();
    stopVertx();
}
Also used : HttpClientResponse(org.vertx.java.core.http.HttpClientResponse) HttpGatewayHandler(io.fabric8.gateway.handlers.http.HttpGatewayHandler) Handler(org.vertx.java.core.Handler) FutureHandler(io.fabric8.gateway.handlers.detecting.FutureHandler) FutureHandler(io.fabric8.gateway.handlers.detecting.FutureHandler) Test(org.junit.Test)

Example 10 with Hello

use of io.fabric8.demo.cxf.Hello in project fabric8 by jboss-fuse.

the class HttpGatewayTest method testENTESB7600.

@Test
public void testENTESB7600() throws Exception {
    // response can not contain CONTENT_LENGTH and TRANSFER_ENCODING see https://tools.ietf.org/html/rfc7230#section-3.3.3
    startRestEndpoint();
    startHttpGateway();
    System.out.println("Requesting...");
    final FutureHandler<HttpClientResponse> future = new FutureHandler<>();
    vertx.createHttpClient().setHost("localhost").setPort(8080).get("/hello/world?wsdl", new Handler<HttpClientResponse>() {

        @Override
        public void handle(HttpClientResponse event) {
            future.handle(event);
        }
    }).end();
    MultiMap responseHeaders = future.await().headers();
    assertTrue((responseHeaders.contains(CONTENT_LENGTH) && !responseHeaders.contains(TRANSFER_ENCODING)) || (!responseHeaders.contains(CONTENT_LENGTH) && responseHeaders.contains(TRANSFER_ENCODING)));
    stopHttpGateway();
    stopVertx();
}
Also used : MultiMap(org.vertx.java.core.MultiMap) HttpClientResponse(org.vertx.java.core.http.HttpClientResponse) HttpGatewayHandler(io.fabric8.gateway.handlers.http.HttpGatewayHandler) FutureHandler(io.fabric8.gateway.handlers.detecting.FutureHandler) Handler(org.vertx.java.core.Handler) FutureHandler(io.fabric8.gateway.handlers.detecting.FutureHandler) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 HashMap (java.util.HashMap)8 ServerInvoker (io.fabric8.dosgi.io.ServerInvoker)7 ClientInvokerImpl (io.fabric8.dosgi.tcp.ClientInvokerImpl)7 ServerInvokerImpl (io.fabric8.dosgi.tcp.ServerInvokerImpl)7 InvocationHandler (java.lang.reflect.InvocationHandler)7 DispatchQueue (org.fusesource.hawtdispatch.DispatchQueue)7 HttpGatewayHandler (io.fabric8.gateway.handlers.http.HttpGatewayHandler)6 LoadBalancer (io.fabric8.gateway.loadbalancer.LoadBalancer)4 RoundRobinLoadBalancer (io.fabric8.gateway.loadbalancer.RoundRobinLoadBalancer)4 InetSocketAddress (java.net.InetSocketAddress)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 FutureHandler (io.fabric8.gateway.handlers.detecting.FutureHandler)3 HttpGateway (io.fabric8.gateway.handlers.http.HttpGateway)3 HttpGatewayServer (io.fabric8.gateway.handlers.http.HttpGatewayServer)3 HttpMappingRule (io.fabric8.gateway.handlers.http.HttpMappingRule)3 MappedServices (io.fabric8.gateway.handlers.http.MappedServices)3 Map (java.util.Map)3 Handler (org.vertx.java.core.Handler)3 HttpClientResponse (org.vertx.java.core.http.HttpClientResponse)3