Package org.xsocket.connection

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-Agent: me\r\n" +
          "Cookie: pA_c[p]=rZNBCsIwEEXvkhNkZpIa05VgFx5ANyJStWpRbKGgC9u7m1qo;\r\n" +
          " pA_c[p340358058568d1f]=S7QysqoutjIytF;\r\n" +
          " pA_c[p3403580662066ea]=S7QysqoutjIytFIqyChwTC;\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);

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


   
    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-Agent: me\r\n" +
          "\r\n");
   
    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

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

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