Package org.xlightweb.client

Examples of org.xlightweb.client.HttpClient


       
        IServer server = new Server(dh);
        server.start();


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


       
        IServer server = new Server(dh);
        server.start();


        HttpClient httpClient = new HttpClient();
        httpClient.setMaxRetries(4);
        httpClient.setCallReturnOnMessage(true);
       
        try {
            httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/test"));
            Assert.fail("IOException expected");
        } catch (IOException expected) { }
       
       
        httpClient.close();
        server.close();
    }
View Full Code Here

   
    HttpProxy2 proxy = new HttpProxy2(false);
    proxy.start();
   
   
    HttpClient httpClient = new HttpClient(SSLTestContextFactory.getSSLContext());
    httpClient.setProxyHost("localhost");
    httpClient.setProxyPort(proxy.getLocalPort());

    GetRequest request = new GetRequest("http://www.amazon.de/");
    IHttpResponse response = httpClient.call(request);
   
    Assert.assertEquals(200, response.getStatus());
    Assert.assertTrue(response.getBlockingBody().readString().indexOf("amazon") != -1);
   
   
    httpClient.close();
    proxy.close();
 
View Full Code Here

    HttpProxy2 proxy = new HttpProxy2(false);
    proxy.start();
   
   
    HttpClient httpClient = new HttpClient(SSLTestContextFactory.getSSLContext());
    httpClient.setProxySecuredHost("localhost");
    httpClient.setProxySecuredPort(proxy.getLocalPort());
    httpClient.setProxyUser("test");
    httpClient.setProxyPassword("test");

    IHttpResponse response = httpClient.call(new GetRequest("https://localhost:" + server.getLocalPort() + "/"));
   
    String body = response.getBlockingBody().readString();

    Assert.assertEquals(200, response.getStatus());
    Assert.assertTrue(body.indexOf("it works") != -1);
   
   
    httpClient.close();
    proxy.close();
    server.close();
 
View Full Code Here

        HttpProxy2 proxy = new HttpProxy2(false);
        proxy.start();
       
       
        HttpClient httpClient = new HttpClient(SSLTestContextFactory.getSSLContext());
        httpClient.setProxyHost("localhost");
        httpClient.setProxyPort(proxy.getLocalPort());
        httpClient.setProxyUser("test");
        httpClient.setProxyPassword("test");

        IHttpResponse response = httpClient.call(new GetRequest("https://localhost:" + server.getLocalPort() + "/"));
       
        String body = response.getBlockingBody().readString();

        Assert.assertEquals(200, response.getStatus());
        Assert.assertTrue(body.indexOf("it works") != -1);
       
       
        httpClient.close();
        proxy.close();
        server.close();
    }    
View Full Code Here

   
    HttpProxy2 proxy = new HttpProxy2(true);
    proxy.start();
   
   
    HttpClient httpClient = new HttpClient();
    httpClient.setProxyHost("localhost");
    httpClient.setProxyPort(proxy.getLocalPort());
    httpClient.setProxyUser("test");
    httpClient.setProxyPassword("test");
   

    IHttpResponse response = httpClient.call(new GetRequest("http://www.amazon.de/"));
   
    Assert.assertEquals(200, response.getStatus());
    Assert.assertTrue(response.getBlockingBody().readString().indexOf("amazon") != -1);
   
   
    httpClient.close();
    proxy.close();
 
View Full Code Here

    LOG.fine("start proxy");
    HttpProxy2 proxy = new HttpProxy2(true);
    proxy.start();
   
   
    HttpClient httpClient = new HttpClient();
    httpClient.setProxyHost("localhost");
    httpClient.setProxyPort(proxy.getLocalPort());
    httpClient.setProxyUser("test");
   

    try {
      LOG.fine("call");
      httpClient.call(new GetRequest("http://www.amazon.de/"));
      Assert.fail("IOException expected");
    } catch (IOException expected) {  }
   
   
    LOG.fine("returned");
    httpClient.close();
    proxy.close();
 
View Full Code Here

        };
       
        HttpServer server = new HttpServer(reqHdl);
        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setCacheMaxSizeKB(100);
       
        IHttpResponse resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/test"));
        Assert.assertEquals(301, resp.getStatus());
        Assert.assertNotNull(resp.getHeader("Location"));
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
       
        QAUtil.sleep(1000);
       
        resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/test"));
        Assert.assertEquals(301, resp.getStatus());
        Assert.assertNotNull(resp.getHeader("Location"));
        Assert.assertTrue(resp.getHeader(CacheHandler.XHEADER_NAME).startsWith("HIT"));
       
       
        Assert.assertEquals(1, httpClient.getNumCacheHit());
        Assert.assertEquals(1, httpClient.getNumCacheMiss());
       
        httpClient.close();
        server.close();
  }  
View Full Code Here

        };
       
        HttpServer server = new HttpServer(reqHdl);
        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setCacheMaxSizeKB(100);
       
        IHttpResponse resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/test"));
        Assert.assertEquals(301, resp.getStatus());
        Assert.assertNotNull(resp.getHeader("Location"));
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
       
        QAUtil.sleep(1000);
       
        resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/test"));
        Assert.assertEquals(301, resp.getStatus());
        Assert.assertNotNull(resp.getHeader("Location"));
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
       
       
        Assert.assertEquals(0, httpClient.getNumCacheHit());
        Assert.assertEquals(2, httpClient.getNumCacheMiss());
       
        httpClient.close();
        server.close();
    }  
View Full Code Here

        };
       
        HttpServer server = new HttpServer(reqHdl);
        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setCacheMaxSizeKB(100);
       
        IHttpResponse resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/test"));
        Assert.assertEquals(302, resp.getStatus());
        Assert.assertNotNull(resp.getHeader("Location"));
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
       
        QAUtil.sleep(1000);
       
        resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/test"));
        Assert.assertEquals(302, resp.getStatus());
        Assert.assertNotNull(resp.getHeader("Location"));
        Assert.assertTrue(resp.getHeader(CacheHandler.XHEADER_NAME).startsWith("HIT"));
       
       
        Assert.assertEquals(1, httpClient.getNumCacheHit());
        Assert.assertEquals(1, httpClient.getNumCacheMiss());
       
        httpClient.close();
        server.close();
    }
View Full Code Here

TOP

Related Classes of org.xlightweb.client.HttpClient

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.