Package org.xsocket.connection

Examples of org.xsocket.connection.IServer


       
        return true;
      }
    };
   
    IServer server = new Server(hdl);
    server.start();
   
   
    HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
    IHttpResponse response = con.call(new GetRequest("/"));
   
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("12345", response.getBlockingBody().readString());
   
    con.close();
    server.close();
  }
View Full Code Here


       
        return true;
      }
    };
   
    IServer server = new Server(hdl);
    server.start();
   
   
    HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
    IHttpResponse response = con.call(new GetRequest("/"));
   
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("12345", response.getBlockingBody().readString());
   
    con.close();
    server.close();
  }
View Full Code Here

       
        return true;
      }
    };
   
    IServer server = new Server(hdl);
    server.start();

    HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
    IHttpResponse response = con.call(new GetRequest("/"));
   
    String body = response.getBlockingBody().readString();
   
    Assert.assertEquals(200, response.getStatus());
    Assert.assertTrue(response.getContentType() == null);
    Assert.assertEquals("<html> <body>this is a plain body </body></html>", body);
   
    con.close();
    server.close();
  }
View Full Code Here

               
                return true;
            }
        };
       
        IServer server = new Server(hdl);
        server.start();
       
       
        HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
        IHttpResponse response = con.call(new GetRequest("/"));
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("12345", response.getBlockingBody().readString());
        Assert.assertEquals("me", response.getServer());
       
        con.close();
        server.close();
    }
View Full Code Here

               
                return true;
            }
        };
       
        IServer server = new Server(hdl);
        server.start();
       
       
        HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
        IHttpResponse response = con.call(new GetRequest("/"));
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("12345", response.getBlockingBody().readString());
        Assert.assertEquals("me", response.getServer());
       
        con.close();
        server.close();
    }   
View Full Code Here

  }
 
 
  @Test
  public void testIdleTimeout2() throws Exception {
    IServer server = new HttpServer(new ServerHandler());
    ConnectionUtils.start(server);
   
    HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
    con.setIdleTimeoutMillis(500);
   
    GetRequest request = new GetRequest("/");
    request.setHeader("sleep-time", Integer.toString(1000));
    try {
      con.call(request);
      Assert.fail("SocketTimeoutException expected");
    } catch (IOException expected) { }
   
    con.close();
    server.close();
  }
View Full Code Here

 
  @Test
  public void testBodyDataReceiveTimeout() throws Exception {
   
    IServer server = new HttpServer(new ServerHandler2());
    server.start();
 
    HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
    con.setBodyDataReceiveTimeoutMillis(1000);

    IHttpResponse response = con.call(new GetRequest("/?loops=3&waittime=200"));
    response.getBody().readString();
   
    response = con.call(new GetRequest("/?loops=1&waittime=20000"));
   
    try {
      response.getBody().readString();
      Assert.fail("ReceiveTimeoutException expected");
    } catch (ReceiveTimeoutException expected) { }

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

 
  @Test
  public void testResponseTimeoutHandler() throws Exception {

    IServer server = new HttpServer(new ServerHandler());
    ConnectionUtils.start(server);
   
    HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
    con.setResponseTimeoutMillis(1000);
   
    ResponseHandler respHdl = new ResponseHandler();
    HttpRequestHeader reqHdr = new HttpRequestHeader("GET", "/");
    reqHdr.setHeader("sleep-time", Integer.toString(1000));

    con.send(reqHdr, respHdl);
   
    QAUtil.sleep(1500);
   
    Assert.assertEquals(0, respHdl.getCountIOException());
    Assert.assertEquals(1, respHdl.getCountSocketException());
   
    con.close();
    server.close();
  }
View Full Code Here

 
 
  @Test
  public void testResponseTimeout() throws Exception {

    IServer server = new HttpServer(new ServerHandler());
    ConnectionUtils.start(server);
   
    HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
    con.setResponseTimeoutMillis(1000);
   
    ResponseHandler2 respHdl = new ResponseHandler2();
    HttpRequestHeader reqHdr = new HttpRequestHeader("GET", "/");
    reqHdr.setHeader("sleep-time", Integer.toString(1000));

    con.send(reqHdr, respHdl);
   
    QAUtil.sleep(1500);
   
    Assert.assertEquals(1, respHdl.getCountIOException());
   
    con.close();
    server.close();
  }
View Full Code Here

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

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.