Package org.xsocket.connection

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


    chain.addLast(new FileServiceRequestHandler(basepath));
    IServer server = new HttpServer(chain);
    server.start();
   
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());

    con.write("GET /doenstExists 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

   
    IServer server = new HttpServer(chain);
    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);
    String body = con.readStringByLength(contentLength);

    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertEquals("OK", body);

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

        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

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

        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("GET /picture/?name=value 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("name=value", request.getQueryString());
        Assert.assertEquals("value", request.getParameter("name"));

        con.close();
        server.close();
    }     
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 /picture/?name= 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("name=", request.getQueryString());
        Assert.assertEquals("", request.getParameter("name"));

        con.close();
        server.close();
    }     
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 /picture/?name=value&name2= 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("name=value&name2=", request.getQueryString());
        Assert.assertEquals("value", request.getParameter("name"));
        Assert.assertEquals("", request.getParameter("name2"));

        con.close();
        server.close();
    }     
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 /picture/?name=value& 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("name=value", request.getQueryString());
        Assert.assertEquals("value", request.getParameter("name"));

        con.close();
        server.close();
    }     
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 /picture/?blablabla 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("blablabla", request.getQueryString());
        Assert.assertEquals(0, request.getParameterNameSet().size());

        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.