Package org.xsocket.connection

Examples of org.xsocket.connection.IServer


 
  @Test
  public void testGodHttp11RequestWithQuery0() 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?test=12&test=two"));

    Assert.assertEquals(200, response.getStatus());
    List<String> values = Arrays.asList(rh.getRequest().getParameterValues("test"));
    Assert.assertTrue(values.contains("12"));
    Assert.assertTrue(values.contains("two"));
   
    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


 
  @Test
  public void testGodHttp11RequestWithQuery2() 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="));

    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("value1", rh.getRequest().getParameter("param1"));
    Assert.assertEquals("", rh.getRequest().getParameter("param2"));

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

 
  @Test
  public void testGodHttp11RequestWithQuery3() 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"));

    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("value1", rh.getRequest().getParameter("param1"));

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

 
  @Test
  public void testGodHttp11RequestWithQuery4() 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="));

    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("", rh.getRequest().getParameter("param1"));

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

 
  @Test
  public void testGodHttp11RequestWithQuery5() 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?filename=C%3A%5CDOKUME%7E1%5Cgrro%5CLOKALE%7E1%5CTemp%5CxSocketTest23878.html"));

    Assert.assertEquals(200, response.getStatus());
   
    String filename = rh.getRequest().getParameter("filename");
    Assert.assertEquals("C:\\DOKUME~1\\grro\\LOKALE~1\\Temp\\xSocketTest23878.html", filename);
   
    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

 
  @Test
  public void testGodHttp11RequestWithQuery6() 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=&param2=2"));

    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("", rh.getRequest().getParameter("param1"));
    Assert.assertEquals("2", rh.getRequest().getParameter("param2"));

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

  @Test
  public void testGodHttp11RequestWithQuery7() 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=&param2=2&param1=3"));

    Assert.assertEquals(200, response.getStatus());
    List<String> params = Arrays.asList(rh.getRequest().getParameterValues("param1"));
    Assert.assertTrue(params.contains(""));
    Assert.assertTrue(params.contains("3"));
    Assert.assertEquals("2", rh.getRequest().getParameter("param2"));

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

    @Test
    public void testGodHttp11RequestWithQuery8() throws Exception {
       
        RequestHandler rh = new RequestHandler();
        IServer server = new HttpServer(rh);
        server.start();
       
        HttpClient httpClient = new HttpClient();
       
        MultivalueMap entity = new MultivalueMap("UTF-8", new NameValuePair("param1", ""), new NameValuePair("param2", " 2  "), new NameValuePair("param1", "3 "));
        IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/test/?" + entity.toString()));

        Assert.assertEquals(200, response.getStatus());
        List<String> params = Arrays.asList(rh.getRequest().getParameterValues("param1"));
        Assert.assertTrue(params.contains(""));
        Assert.assertTrue(params.contains("3 "));
        Assert.assertEquals(" 2  ", rh.getRequest().getParameter("param2"));

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

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

 
 
  @Test
  public void testGodHttp10Request_2() throws Exception {
   
    IServer server = new HttpServer(new RequestHandler());
    server.start();
   

    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
    con.write("GET / HTTP/1.0\n" +
          "\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.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.