Examples of IBlockingConnection


Examples of org.xsocket.connection.IBlockingConnection

    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.IBlockingConnection

   
    IServer server = new HttpServer(new RequestHandler());
    server.start();
   

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

    con.write("GET / HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-");

    QAUtil.sleep(200);

    con.write("Agent: me\r\n" +
          "\r\n");

    QAUtil.sleep(200);

   
    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);
    String body = con.readStringByLength(contentLength);
   
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertEquals("OK", body);


    header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    contentLength = QAUtil.readContentLength(header);
    body = con.readStringByLength(contentLength);
   
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertEquals("OK", body);

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

Examples of org.xsocket.connection.IBlockingConnection

   
    IServer server = new HttpServer(new RequestHandler());
    server.start();
   

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

    con.write("GET / HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-");

    QAUtil.sleep(200);

    con.write("Agent: me\r\n" +
          "\r\nGET / HT");

   
    QAUtil.sleep(200);

    con.write("TP/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);
    String body = con.readStringByLength(contentLength);
   
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertEquals("OK", body);


    header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    contentLength = QAUtil.readContentLength(header);
    body = con.readStringByLength(contentLength);
   
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertEquals("OK", body);

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

Examples of org.xsocket.connection.IBlockingConnection

    RequestHandler rh = new RequestHandler();
    IServer server = new HttpServer(rh);
    server.start();
   
 
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
    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);
    String body = con.readStringByLength(contentLength);
   
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertEquals("OK", body);
   
    Assert.assertEquals("localhost", rh.getRequest().getHeader("Host"));
   
    Set<String> headerNames = rh.getRequest().getHeaderNameSet();
    Assert.assertTrue(headerNames.remove("User-Agent"));
    Assert.assertTrue(headerNames.remove("Host"));
    Assert.assertTrue(headerNames.isEmpty());
 
    con.close();
    server.close();
  }
View Full Code Here

Examples of org.xsocket.connection.IBlockingConnection

      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

Examples of org.xsocket.connection.IBlockingConnection

     
    HttpServer server = new HttpServer(new ServerHandler());
    server.setMaxTransactions(5);
    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

Examples of org.xsocket.connection.IBlockingConnection

   
   
    IServer server = new HttpServer(new TransactionServerHandler());
    ConnectionUtils.start(server);

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

   
    con.write("GET / HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "Connection: close\r\n" +
          "\r\n");
     
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
     
    con.readByteBufferByLength(contentLength);
   
    Assert.assertTrue(header.indexOf("Connection: close") != -1);


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

Examples of org.xsocket.connection.IBlockingConnection

      System.out.println("testRequestTimeout");
     
    IServer server = new HttpServer(new RequestTimeoutServerHandler());
    server.start();
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());

    for (int i = 0; i < 3; i++) {
      QAUtil.sleep(200);
      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);

      Assert.assertTrue(header.indexOf("200") != -1);
    }
   
    QAUtil.sleep(1500);

    try {
      con.readByte();
      Assert.fail("ClosedChannelException expected");
    } catch (ClosedChannelException expected) { }

    server.close()
  }
View Full Code Here

Examples of org.xsocket.connection.IBlockingConnection

      System.out.println("testHttp1_0_Keep_Alive");
     
    IServer server = new HttpServer(new ServerHandler());
    ConnectionUtils.start(server);
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());

    QAUtil.sleep(200);
    con.write("GET / HTTP/1.0\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "Connection: Keep-Alive\r\n" +
          "\r\n");
     
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
    con.readStringByLength(contentLength);
   
    Assert.assertTrue(header.indexOf("HTTP/1.0") != -1);
    Assert.assertTrue(header.indexOf("Connection: close") != -1)// xSocket will ignore keep-alive if HTTP/1.0

    Assert.assertTrue(header.indexOf("200") != -1);
View Full Code Here

Examples of org.xsocket.connection.IBlockingConnection

        RequestHandler rh = new RequestHandler();
        IServer server = new HttpServer(rh);
        server.start();
       

        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("GET /picture/?21,32 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);
        String body = con.readStringByLength(contentLength);
       
        Assert.assertTrue(header.indexOf("200") != -1);
        Assert.assertEquals("OK", body);

       
        IHttpRequest request = rh.getRequest();
        Assert.assertEquals("21,32", request.getQueryString());
       
        Assert.assertEquals("localhost", request.getHost());
        Assert.assertEquals("me", request.getUserAgent());
        Assert.assertEquals(0, request.getParameterNameSet().size());
       
        request.setParameter("test1", "value1");

        Assert.assertEquals("21,32", request.getQueryString());
        Assert.assertEquals("value1", request.getParameter("test1"));


        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.