Examples of BlockingConnection


Examples of org.xsocket.connection.BlockingConnection

        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

Examples of org.xsocket.connection.BlockingConnection

    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

Examples of org.xsocket.connection.BlockingConnection

    IServer server = new HttpServer(chain);

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

    int contentLength = QAUtil.readContentLength(header);
    con.readStringByLength(contentLength);

    Assert.assertTrue(header.indexOf("200") != -1);

    file.delete();
    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.