Package org.xlightweb

Examples of org.xlightweb.GetRequest


        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setCacheMaxSizeKB(100);
       
        IHttpResponse resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertEquals("test", resp.getBody().readString());
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
       
        QAUtil.sleep(2000);
       
        resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
        Assert.assertEquals("test", resp.getBody().readString());
       
        QAUtil.sleep(1000);
View Full Code Here


   
    @Test
    public void testSSL() throws Exception {
    HttpClient httpClient = new HttpClient(SSLTestContextFactory.getSSLContext());
   
    IHttpResponse response = httpClient.call(new GetRequest("https://localhost:" + proxySslServer.getLocalPort() + "/test"));
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("isSecured=true", response.getBlockingBody().readString());
   
    httpClient.close();
  }
View Full Code Here

   
    @Test
    public void testPlain() throws Exception {
        HttpClient httpClient = new HttpClient(SSLTestContextFactory.getSSLContext());
       
        IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + proxyServer.getLocalPort() + "/test"));
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("isSecured=false", response.getBlockingBody().readString());
       
        httpClient.close();
    }
View Full Code Here

  public void testClientInitiated() throws Exception {
    IServer server = new HttpServer(0, new RequestHandler(), SSLTestContextFactory.getSSLContext(), false);
    server.start();
   
   
    GetRequest request = new GetRequest("/");
    request.setHeader("Host", "localhost");
    request.setHeader("User-Agent", "me");
    request.setHeader("Upgrade", "TLS/1.0");
    request.setHeader("Connection", "Upgrade");
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort(), SSLTestContextFactory.getSSLContext(), false);
    con.write(request.toString());
     
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
     
    Assert.assertTrue(header.indexOf("101") != -1);
    Assert.assertTrue(header.indexOf("Upgrade: TLS/1.0, HTTP/1.1") != -1);
   
    System.out.println("activating secured mode");
    con.activateSecuredMode();
   
    QAUtil.sleep(500);
    Assert.assertTrue(con.isSecure());

    System.out.println("send 2.te request");
    request = new GetRequest("/");
    request.setHeader("Host", "localhost");
    request.setHeader("User-Agent", "me");

    con.write(request.toString());
     
    header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
   
    System.out.println("got 2.te response header");
    int contentLength = QAUtil.readContentLength(header);
View Full Code Here

   
    IServer server = new HttpServer(0, new RequestHandler());
    ConnectionUtils.start(server);
   
   
    GetRequest request = new GetRequest("/");
    request.setHeader("Host", "localhost");
    request.setHeader("User-Agent", "me");
    request.setHeader("Upgrade", "TLS/1.0");
    request.setHeader("Connection", "Upgrade");
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort(), SSLTestContextFactory.getSSLContext(), false);
    con.write(request.toString());
     
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
   
    String msg = con.readStringByLength(contentLength);
View Full Code Here

        httpClient.setMaxActivePerServer(2);


        System.out.println(System.currentTimeMillis() + " start first thread");
       
        httpClient.send(new GetRequest("http://localhost:" + server.getLocalPort() + "/?delay=3000"), new ResponseHandler());
        QAUtil.sleep(300);

       
        System.out.println(System.currentTimeMillis() + " start second thread");
        httpClient.send(new GetRequest("http://localhost:" + server.getLocalPort() + "/?delay=3000"), new ResponseHandler());

       
        System.out.println("waiting util started");
        while(reqHdl.getRunning() < 2) {
            QAUtil.sleep(100);
        }

       
        System.out.println("perform third call (should fail)");
        try {
            httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort()));
            Assert.fail("MaxConnectionsExceededException expected");
        } catch (MaxConnectionsExceededException expected) { }
       
       
       
        System.out.println("waiting until less than 2 threads are running");
        while(reqHdl.getRunning() >= 2) {
            QAUtil.sleep(100);
        }
        QAUtil.sleep(1000);
       
       
        System.out.println("try again calling (should be successful)");
        IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort()));
        Assert.assertEquals(200, response.getStatus());
       
        httpClient.close();
        server.close();
  }
View Full Code Here

        final HttpClient httpClient = new HttpClient();
        httpClient.setCacheMaxSizeKB(100);
        httpClient.setMaxActivePerServer(2);

        System.out.println(System.currentTimeMillis() + " start first thread");
        httpClient.send(new GetRequest("http://localhost:" + server.getLocalPort() + "/?delay=3000"), new ResponseHandler());
        QAUtil.sleep(300);

       
        System.out.println(System.currentTimeMillis() + " start second thread");
        httpClient.send(new GetRequest("http://localhost:" + server.getLocalPort() + "/?delay=3000"));

       
        while(reqHdl.getRunning() < 2) {
            QAUtil.sleep(100);
        }
       
        try {
            httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/?delay=2000"));
            Assert.fail("MaxConnectionsExceededException expected");
        } catch (MaxConnectionsExceededException expected) { }
       
       
        while(reqHdl.getRunning() >= 2) {
            QAUtil.sleep(100);
        }
        QAUtil.sleep(1000);

       
        IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort()));
        Assert.assertEquals(200, response.getStatus());
       
        httpClient.close();
        server.close();
    }
View Full Code Here

        final HttpClient httpClient = new HttpClient();
        httpClient.setMaxActivePerServer(100);


        for (int i = 0; i < 50; i++) {
            httpClient.send(new GetRequest("http://localhost:" + server.getLocalPort() + "/?delay=3000"), new ResponseHandler());
        }
       
        QAUtil.sleep(1000);
       
        httpClient.close();
View Full Code Here

   
      HttpClient client = new HttpClient();
      client.setAutoHandleCookies(false);
      client.setMaxRetries(0);
     
      GetRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/");
      request.setHeader("Upgrade", "WebSocket");
      request.setHeader("Connection", "upgrade");
      request.setHeader("Origin", "http://websockets.org:" + server.getLocalPort());

      IHttpResponse response = client.call(request);
     
      IHttpConnection con = (IHttpConnection) response.getAttribute("org.xlightweb.client.connection");
      Assert.assertTrue(con.isOpen());
View Full Code Here

        IServer server = new Server(dh);
        server.start();
     
        HttpClient client = new HttpClient();
       
        GetRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/");
        request.setHeader("Upgrade", "WebSocket");
        request.setHeader("Connection", "upgrade");
        request.setHeader("Origin", "http://websockets.org:" + server.getLocalPort());

        IHttpResponse response = client.call(request);
       
        IHttpConnection con = (IHttpConnection) response.getAttribute("org.xlightweb.client.connection");
        Assert.assertTrue(con.isOpen());
View Full Code Here

TOP

Related Classes of org.xlightweb.GetRequest

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.