Package org.xsocket.connection

Examples of org.xsocket.connection.BlockingConnection


      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


      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

    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

    IHttpServer server = new HttpServer(chain);
    server.start();
   
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
   
    con.write("GET /test HTTP/1.1\r\n" +
              "Host: localhost:" + server.getLocalPort() + "\r\n" +
              "User-Agent: me\r\n\r\n");
   
    String header = con.readStringByDelimiter("\r\n\r\n");
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertFalse(h1.isForwardedRef.get());
   
    h1.reset();
    h2.reset();
    con.close();
   
    con = new BlockingConnection("localhost", server.getLocalPort());
    con.write("GET /bs HTTP/1.1\r\n" +
                "Host: localhost:" + server.getLocalPort() + "\r\n" +
                "User-Agent: me\r\n\r\n");
     
    header = con.readStringByDelimiter("\r\n\r\n");
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertTrue(h1.isForwardedRef.get());
      Assert.assertFalse(h2.isForwardedRef.get());
     
        con.close();
    con.close();
    server.close();
  }
View Full Code Here

        IHttpServer server = new HttpServer(chain);
        server.start();
       
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
       
       
        con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("GET /bs HTTP/1.1\r\n" +
                "Host: localhost:" + server.getLocalPort() + "\r\n" +
                "User-Agent: me\r\n\r\n");
     
        String header = con.readStringByDelimiter("\r\n\r\n");
        Assert.assertTrue(header.indexOf("200") != -1);
        Assert.assertTrue(h1.isForwardedRef.get());
        Assert.assertFalse(h2.isForwardedRef.get());
       
        h1.reset();
        h2.reset();
       
        con.close();
        server.close();  
    }
View Full Code Here

        IHttpServer server = new HttpServer(chain);
        server.start();
       
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
       
        con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("GET /tztz HTTP/1.1\r\n" +
                "Host: localhost:" + server.getLocalPort() + "\r\n" +
                "User-Agent: me\r\n\r\n");
     
        String header = con.readStringByDelimiter("\r\n\r\n");
        Assert.assertTrue(header.indexOf("404") != -1);
        Assert.assertTrue(h1.isForwardedRef.get());
        Assert.assertTrue(h2.isForwardedRef.get());
       
        con.close();
        server.close();
    }
View Full Code Here

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

       
        IHttpServer server = new HttpServer(chain);
        server.start();
       
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
       
        con.write("POST /test HTTP/1.1\r\n" +
                  "Host: localhost:" + server.getLocalPort() + "\r\n" +
                  "User-Agent: me\r\n" +
                  "Content-Length: 5\r\n" +
                  "\r\n" +
                  "12345");
       
        String header = con.readStringByDelimiter("\r\n\r\n");
        Assert.assertTrue(header.indexOf("200") != -1);
       
        QAUtil.sleep(1000);
        Assert.assertEquals("addedLine\r\n12345", con.readStringByLength(16));
       
        con.close();
        server.close();
    }
View Full Code Here

        String basepath = file.getParentFile().getAbsolutePath();
       
        IServer server = new HttpServer(new FileServiceRequestHandler(basepath, true));
        server.start();
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());

        con.write("GET /" + file.getName() + " 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";

        if (header.indexOf("200") == -1) {
            String txt = "unexpected response " + header;
            System.out.println("ERROR " + txt);
            Assert.fail(txt);
        }

        int contentLength = QAUtil.readContentLength(header);
        File tempFile = QAUtil.createTempfile();
       
        RandomAccessFile raf = new RandomAccessFile(tempFile, "rw");
        FileChannel fc = raf.getChannel();
       
        con.transferTo(fc, contentLength);
       
        fc.close();
        raf.close();
       
        Assert.assertTrue(QAUtil.isEquals(file, tempFile));

        tempFile.delete();
        file.delete();
        con.close();
        server.close();
   
View Full Code Here

    IServer server = new HttpServer(new FileServiceRequestHandler(basepath));
    server.start();
   

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

    con.write("GET /doesntExists 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.readStringByLength(contentLength);

    Assert.assertTrue(header.indexOf("404") != -1);
   
    file.delete();
    con.close();   
    server.close();
  }
View Full Code Here

TOP

Related Classes of org.xsocket.connection.BlockingConnection

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.