Package org.xsocket.connection

Examples of org.xsocket.connection.IBlockingConnection


   
    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("xWorker"));
    Assert.assertTrue(rh.onRequestThreadname.startsWith("xWorker"));
View Full Code Here


    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("xWorker"));
View Full Code Here

   
    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

    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

    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

     
    IServer server = new HttpServer(reqHdl);
    server.start();
 
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
     
    con.write("GET /test HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: test\r\n" +
          "\r\n");
     
   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertTrue(header.indexOf("Connection: close") != -1);
    Assert.assertEquals("<html>this ...", con.readStringByLength(14));
   
    try {
      con.readByte();
      Assert.fail("ClosedChannelException expected");
    } catch (ClosedChannelException expected) { }
   
   
    oldServer.close();
View Full Code Here

   
    IServer server = new HttpServer(new ResponseServerHandler());
    ConnectionUtils.start(server);
 
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
     
    con.write("GET /test?chunked=false HTTP/1.0\r\n" +
          "\r\n");
     
   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
     
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertTrue(header.indexOf("HTTP/1.0") != -1);
    Assert.assertTrue(header.indexOf("Connection: close") != -1);
    con.close();
 
    server.close();
  }
View Full Code Here

   
    IServer server = new HttpServer(new ResponseServerHandler());
    ConnectionUtils.start(server);
 
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
     
    con.write("GET /test?chunked=false HTTP/1.0\r\n" +
          "Connection: keep-alive\r\n" +
          "\r\n");
     
   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
     
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertTrue(header.indexOf("HTTP/1.0") != -1);
    Assert.assertTrue(header.indexOf("Connection: close") != -1);
   
        con.readByteBufferByDelimiter("\r\n");

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

   
    IServer server = new HttpServer(new ResponseServerHandler());
    server.start();
 
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
     
    con.write("GET /test?chunked=true HTTP/1.0\r\n" +
          "\r\n");
     
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
     
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertTrue(header.indexOf("HTTP/1.0") != -1);
    Assert.assertTrue(header.indexOf("Connection: close") != -1);
   
        con.readByteBufferByDelimiter("\r\n");
   
    con.close();
    server.close();
  }
View Full Code Here

        IServer server = new HttpServer(new ResponseServerHandler());
        server.start();
   
       
        for (int i = 0; i < 1000; i++) {
            IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
               
            con.write("GET /test?chunked=true HTTP/1.0\r\n" +
                      "\r\n");
               
            String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
               
            Assert.assertTrue(header.indexOf("200") != -1);
            Assert.assertTrue(header.indexOf("HTTP/1.0") != -1);
            Assert.assertTrue(header.indexOf("Connection: close") != -1);
           
            con.readByteBufferByDelimiter("\r\n");
           
            con.close();
        }
       
       
        server.close();
    }
View Full Code Here

TOP

Related Classes of org.xsocket.connection.IBlockingConnection

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.