Examples of BlockingConnection


Examples of org.fusesource.mqtt.client.BlockingConnection

    public void testSendAndReceiveAtMostOnce() throws Exception {
        addMQTTConnector(brokerService);
        brokerService.start();
        MQTT mqtt = createMQTTConnection();
        mqtt.setKeepAlive(Short.MAX_VALUE);
        BlockingConnection connection = mqtt.blockingConnection();

        connection.connect();


        Topic[] topics = {new Topic(utf8("foo"), QoS.AT_MOST_ONCE)};
        connection.subscribe(topics);
        for (int i = 0; i < numberOfMessages; i++) {
            String payload = "Test Message: " + i;
            connection.publish("foo", payload.getBytes(), QoS.AT_MOST_ONCE, false);
            Message message = connection.receive();
            assertEquals(payload, new String(message.getPayload()));
        }
        connection.disconnect();
    }
View Full Code Here

Examples of org.fusesource.stomp.client.BlockingConnection

public class StompConsumerTest extends StompBaseTest {

    @Test
    public void testConsume() throws Exception {
        Stomp stomp = new Stomp("tcp://localhost:" + getPort());
        final BlockingConnection producerConnection = stomp.connectBlocking();

        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedMinimumMessageCount(numberOfMessages);

        for (int i = 0; i < numberOfMessages; i++) {
            StompFrame frame = new StompFrame(SEND);
            frame.addHeader(DESTINATION, StompFrame.encodeHeader("/queue/test"));
            frame.addHeader(MESSAGE_ID, StompFrame.encodeHeader("msg:" + i));
            frame.content(utf8("Important Message " + i));
            producerConnection.send(frame);
        }

        mock.await(5, TimeUnit.SECONDS);
        mock.assertIsSatisfied();
    }
View Full Code Here

Examples of org.xsocket.connection.BlockingConnection

  public void testAutoContinue() throws Exception {

    HttpServer server = new HttpServer(new ItWorksHandler());
    server.start();
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
    con.write("POST / HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "Expect: 100-Continue\r\n" +
          "Content-Length: 2000\r\n" +
          "\r\n");
   
   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    Assert.assertTrue(header.indexOf("100") != -1);
   
   
    con.write(QAUtil.generateByteArray(2000));
   
    header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    Assert.assertTrue(header.indexOf("200") != -1);
   
   
   
    con.close();
    server.close();
  }
View Full Code Here

Examples of org.xsocket.connection.BlockingConnection

        ContinueHandler hdl = new ContinueHandler();
        HttpServer server = new HttpServer(hdl);
        server.start();
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("POST / HTTP/1.1\r\n" +
                  "Host: localhost\r\n" +
                  "User-Agent: me\r\n" +
                  "Expect: 100-Continue\r\n" +
                  "Content-Length: 2000\r\n" +
                  "\r\n");
       
       
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);
       
        QAUtil.sleep(300);
       
        Assert.assertTrue(hdl.is100ContinueSent());
       
        con.write(QAUtil.generateByteArray(2000));

        header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("200") != -1);
        int length = QAUtil.readContentLength(header);
        String txt = con.readStringByLength(length);
        Assert.assertEquals("OK", txt);
       
       
       
        con.close();
        server.close();
    }
View Full Code Here

Examples of org.xsocket.connection.BlockingConnection

        ContinueHandler2 hdl = new ContinueHandler2();
        HttpServer server = new HttpServer(hdl);
        server.start();
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("POST / HTTP/1.1\r\n" +
                  "Host: localhost\r\n" +
                  "User-Agent: me\r\n" +
                  "Expect: 100-Continue\r\n" +
                  "Content-Length: 2000\r\n" +
                  "\r\n");
       
       
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);
        QAUtil.sleep(300);
       
        Assert.assertTrue(hdl.is100ContinueSent());
       
        con.write(QAUtil.generateByteArray(2000));

        header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("200") != -1);
        int length = QAUtil.readContentLength(header);
        String txt = con.readStringByLength(length);
        Assert.assertEquals("OK", txt);
       
       
       
        con.close();
        server.close();
    }
View Full Code Here

Examples of org.xsocket.connection.BlockingConnection

        };

        HttpServer server = new HttpServer(hdl);
        server.start();
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("POST / HTTP/1.1\r\n" +
                  "Host: localhost\r\n" +
                  "User-Agent: me\r\n" +
                  "Expect: 100-Continue\r\n" +
                  "Content-Length: 2000\r\n" +
                  "\r\n");
       
       
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);
       
        QAUtil.sleep(300);
       
        con.write(QAUtil.generateByteArray(2000));

        header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("200") != -1);
        int length = QAUtil.readContentLength(header);
        String txt = con.readStringByLength(length);
        Assert.assertEquals("OK", txt);
       
       
       
        con.close();
        server.close();
    }
View Full Code Here

Examples of org.xsocket.connection.BlockingConnection

       
       
        HttpServer server = new HttpServer(hdl);
        server.start();
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("POST / HTTP/1.1\r\n" +
                  "Host: localhost\r\n" +
                  "User-Agent: me\r\n" +
                  "Expect: 100-Continue\r\n" +
                  "Content-Length: 2000\r\n" +
                  "\r\n");
       
       
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);
       
        QAUtil.sleep(300);
       
        con.write(QAUtil.generateByteArray(2000));

        header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("200") != -1);
        int length = QAUtil.readContentLength(header);
        String txt = con.readStringByLength(length);
        Assert.assertEquals("OK", txt);
       
       
       
        con.close();
        server.close();
    }
View Full Code Here

Examples of org.xsocket.connection.BlockingConnection

        MissingAnnotationContinueHandler hdl = new MissingAnnotationContinueHandler();
        HttpServer server = new HttpServer(hdl);
        server.start();
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("POST / HTTP/1.1\r\n" +
                  "Host: localhost\r\n" +
                  "User-Agent: me\r\n" +
                  "Expect: 100-Continue\r\n" +
                  "Content-Length: 2000\r\n" +
                  "\r\n");
       
       
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);
        Assert.assertFalse(hdl.is100ContinueSent());
       
        con.write(QAUtil.generateByteArray(2000));

        header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("200") != -1);
        int length = QAUtil.readContentLength(header);
        String txt = con.readStringByLength(length);
        Assert.assertEquals("OK", txt);
       
       
       
        con.close();
        server.close();
    }
View Full Code Here

Examples of org.xsocket.connection.BlockingConnection

        chain.addLast(new ItWorksHandler());
       
        HttpServer server = new HttpServer(chain);
        server.start();
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("POST / HTTP/1.1\r\n" +
                  "Host: localhost\r\n" +
                  "User-Agent: me\r\n" +
                  "Expect: 100-Continue\r\n" +
                  "Content-Length: 2000\r\n" +
                  "\r\n");
       
       
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);
       
        con.write(QAUtil.generateByteArray(2000));

        header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("200") != -1);
        Assert.assertTrue(header.indexOf("X-Intercepted") != -1);
        int length = QAUtil.readContentLength(header);
        String txt = con.readStringByLength(length);
        Assert.assertEquals("OK", txt);
       
       
       
        con.close();
        server.close();
    }
View Full Code Here

Examples of org.xsocket.connection.BlockingConnection

       
       
        HttpServer server = new HttpServer(outerChain);
        server.start();
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("POST / HTTP/1.1\r\n" +
                  "Host: localhost\r\n" +
                  "User-Agent: me\r\n" +
                  "Expect: 100-Continue\r\n" +
                  "Content-Length: 2000\r\n" +
                  "\r\n");
       
       
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);
       
        con.write(QAUtil.generateByteArray(2000));

        header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("200") != -1);
        Assert.assertTrue(header.indexOf("X-Intercepted1") != -1);
        Assert.assertTrue(header.indexOf("X-Intercepted2") != -1);
        int length = QAUtil.readContentLength(header);
        String txt = con.readStringByLength(length);
        Assert.assertEquals("OK", txt);
       
       
       
        con.close();
        server.close();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.