Package org.xsocket.connection

Examples of org.xsocket.connection.IBlockingConnection


       
        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

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

        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("GET /picture/?blablabla&werwer 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&werwer", request.getQueryString());
        Assert.assertEquals(0, request.getParameterNameSet().size());

        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 / 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);
   
    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

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

        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: 5\r\n" +
                  "Content-Type: text/plain;charset=iso-8859-1\r\n" +
                  "\r\n" +
                  "12345");
       
        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);
       
        Set<String> headerNames = rh.getRequest().getHeaderNameSet();
        Assert.assertTrue(headerNames.remove("User-Agent"));
        Assert.assertTrue(headerNames.remove("Host"));
        Assert.assertEquals("iso-8859-1", rh.getRequest().getCharacterEncoding());
       
        Assert.assertEquals("12345", rh.getRequest().getBody().toString());


        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("POST / HTTP/1.1\r\n" +
                  "Host: localhost\r\n" +
                  "User-Agent: me\r\n" +
                  "Content-Length: 5\r\n" +
                  "Content-Type: text/plain;charset=\"iso-8859-1\"\r\n" +
                  "\r\n" +
                  "12345");
       
        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);
       
        Set<String> headerNames = rh.getRequest().getHeaderNameSet();
        Assert.assertTrue(headerNames.remove("User-Agent"));
        Assert.assertTrue(headerNames.remove("Host"));
        Assert.assertEquals("iso-8859-1", rh.getRequest().getCharacterEncoding());
       
        Assert.assertEquals("12345", rh.getRequest().getBody().toString());

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

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.