Package org.xsocket.connection

Examples of org.xsocket.connection.IServer


   
    @Test
    public void testQueryString2() throws Exception {
       
        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


   
    @Test
    public void testQueryString3() throws Exception {
       
        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

   
    @Test
    public void testQueryString4() throws Exception {
       
        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

   
    @Test
    public void testQueryString5() throws Exception {
       
        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

   
    @Test
    public void testQueryString6() throws Exception {
       
        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

   
    @Test
    public void testQueryString7() throws Exception {
       
        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

   
  @Test
  public void testGodHttp11Request() throws Exception {
   
    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

 
    @Test
    public void testEncoding() throws Exception {
       
        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

    @Test
    public void testQuotedEncoding() throws Exception {
       
        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

   
  @Test
  public void testGodHttp11RequestWithQuery() throws Exception {
     
    RequestHandler rh = new RequestHandler();
    IServer server = new HttpServer(rh);
    server.start();
   
    HttpClient httpClient = new HttpClient();
    IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/test/?param1=value1&param2=value2"));

    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("value1", rh.getRequest().getParameter("param1"));
    Assert.assertEquals("value2", rh.getRequest().getParameter("param2"));
   
    Set<String> headerNames = rh.getRequest().getHeaderNameSet();
    Assert.assertTrue(headerNames.remove("User-Agent"));
    Assert.assertTrue(headerNames.remove("Host"));
    Assert.assertTrue(headerNames.isEmpty());

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

TOP

Related Classes of org.xsocket.connection.IServer

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.