Examples of BlockingConnection


Examples of org.xsocket.connection.BlockingConnection

   
    HttpServer server = new HttpServer(root);
    server.setRequestTimeoutMillis(1000);
    ConnectionUtils.start(server);
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());

    con.write("POST / HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "Content-Length: 4\r\n" +
          "\r\n" +
          "1234");
     
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
   
    con.readByteBufferByLength(contentLength);
    Assert.assertTrue(header.indexOf("200") != -1);
       
    Assert.assertNotNull(filter.getRequest());
    Assert.assertTrue(filter.getThreadName().startsWith("xServerPool"));
    Assert.assertTrue(rh.onRequestThreadname.startsWith("xServerPool"));
View Full Code Here

Examples of org.xsocket.connection.BlockingConnection

    HttpServer server = new HttpServer(root);
    server.setRequestTimeoutMillis(1000);
    server.start();
    ConnectionUtils.registerMBean(server);
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());

    con.write("POST / HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "Content-Length: 4\r\n" +
          "\r\n" +
          "1234");
     
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
   
    con.readByteBufferByLength(contentLength);
    Assert.assertTrue(header.indexOf("200") != -1);
   
   
    Assert.assertNotNull(filter.getRequest());
    Assert.assertTrue(filter.getThreadName().startsWith("xServerPool"));
View Full Code Here

Examples of org.xsocket.connection.BlockingConnection

   
    final IServer server = new HttpServer(chain);
    ConnectionUtils.start(server);

   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());

    con.write("POST / HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "Content-Length: 4\r\n" +
          "\r\n");
     
    con.write("12");

    QAUtil.sleep(400);
    con.write("34");
   
    QAUtil.sleep(500);
   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
   
    String body = con.readStringByLength(contentLength);
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertEquals("1234", body);
   

View Full Code Here

Examples of org.xsocket.connection.BlockingConnection

    RequestHandlerChain root = new RequestHandlerChain();
   
    IServer server = new HttpServer(root);
    ConnectionUtils.start(server);
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
 
    con.write("POST / HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "Content-Length: 4\r\n" +
          "\r\n" +
          "1234");
     
   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
    con.readStringByLength(contentLength);
   
    Assert.assertTrue(header.indexOf("404") != -1);
  }
View Full Code Here

Examples of org.xsocket.connection.BlockingConnection

    root.addLast(doNothingFilter);
   
    IServer server = new HttpServer(root);
    ConnectionUtils.start(server);
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
 
    con.write("POST /test/path?param1=value1 HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "Content-Length: 4\r\n" +
          "\r\n" +
          "1234");
     
   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
    con.readStringByLength(contentLength);
   
    Assert.assertTrue(header.indexOf("404") != -1);
    Assert.assertTrue(doNothingFilter.isOnResponseCalled());
  }
View Full Code Here

Examples of org.xsocket.connection.BlockingConnection

    System.out.println("testHttp1_1");
   
    HttpServer server = new HttpServer(new RequestHandler());
    server.start();

    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
    con.write("GET /test HTTP/1.1\r\n");
    con.write("Host: localhost:" +  server.getLocalPort() + "\r\n");
    con.write("User-Agent:me\r\n");
    con.write("\r\n");
   
    String header = con.readStringByDelimiter("\r\n\r\n");
    Assert.assertTrue(header.indexOf("OK") != -1);
    Assert.assertTrue(header.indexOf("chunked") != -1);
   
    con.close();
    server.close();
  }
View Full Code Here

Examples of org.xsocket.connection.BlockingConnection

    System.out.println("testHttp1_0");
       
    HttpServer server = new HttpServer(new RequestHandler());
    server.start();

    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
    con.write("GET /test HTTP/1.0\r\n");
    con.write("\r\n");
   
    String header = con.readStringByDelimiter("\r\n\r\n");
    Assert.assertTrue(header.indexOf("OK") != -1);
    Assert.assertEquals("test123456", con.readStringByLength(10));
   
    try {
      con.readByte();
      Assert.fail("ClosedChannelException expected");
    } catch (ClosedChannelException expected) { }
   
    con.close();
    server.close();
  }
View Full Code Here

Examples of org.xsocket.connection.BlockingConnection

    @Test
    public void testServerMixedHandler() throws Exception {
        HttpServer server = new HttpServer(new MixedRequestHandler());
        server.start();

        BlockingConnection bc = new BlockingConnection("localhost", server.getLocalPort());

        bc.write("GET / HTTP/1.1\r\n"+
                 "Host: localhost:" + server.getLocalPort() + "\r\n"+
                 "User-Agent: xLightweb/2.11\r\n"+
                 "Upgrade: WebSocket\r\n"+
                 "Connection: Upgrade\r\n"+
                 "Origin: http://localhost:5161/\r\n"+
                 "\r\n");

        bc.readStringByDelimiter("\r\n\r\n");

       
        byte[] msg1 = bc.readBytesByLength(11);
        Assert.assertArrayEquals(new byte[] { 0x00, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x79, 0x6f, 0x75, (byte) 0xFF}, msg1);

    

        bc.close();
        server.close();
    }    
View Full Code Here

Examples of org.xsocket.connection.BlockingConnection

    public void testServer() throws Exception {
  
        HttpServer server = new HttpServer(new WebHandler());
        server.start();

        BlockingConnection bc = new BlockingConnection("localhost", server.getLocalPort());

        bc.write("GET /0123456 HTTP/1.1\r\n"+
                 "Host: localhost:" + server.getLocalPort() + "\r\n"+
                 "User-Agent: xLightweb/2.11\r\n"+
                 "Upgrade: WebSocket\r\n"+
                 "Connection: Upgrade\r\n"+
                 "Origin: http://localhost:5161/\r\n"+
                 "\r\n");

        System.out.println(bc.readStringByDelimiter("\r\n\r\n"));
       
       
        byte[] msg1 = bc.readBytesByLength(11);
        Assert.assertArrayEquals(new byte[] { 0x00, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x79, 0x6f, 0x75, (byte) 0xFF}, msg1);

        bc.close();
        server.close();
    }    
View Full Code Here

Examples of org.xsocket.connection.BlockingConnection

      System.out.println("testMaxTransactions");
   
    IServer server = new HttpServer(new TransactionServerHandler());
    ConnectionUtils.start(server);

    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());

    for (int i = 5; i > 0; --i) {
   
      con.write("GET / HTTP/1.1\r\n" +
            "Host: localhost\r\n" +
            "User-Agent: me\r\n" +
            "\r\n");
     
      String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
      int contentLength = QAUtil.readContentLength(header);
     
      con.readByteBufferByLength(contentLength);

      if (i == 1) {
        Assert.assertTrue(header.indexOf("Connection: close") != -1);
       
        QAUtil.sleep(400);
       
        try {
          con.readByte();
          Assert.fail("ClosedChannelException expected");
        } catch (ClosedChannelException expected) { }

       
      } else {
        int start = header.indexOf("Keep-Alive: max=");
        int end = header.indexOf("\r\n", start + 1);
        int count = Integer.parseInt(header.substring(start + "Keep-Alive: max=".length(), end));
        Assert.assertEquals(i - 1, count);
        Assert.assertTrue(con.isOpen());
      }
    }

    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.