Package org.xlightweb.client

Examples of org.xlightweb.client.HttpClient


  public void testSimple() throws Exception {
     
      HttpServer server = new HttpServer(new RequestHandler());
      server.start();
     
      HttpClient client = new HttpClient();
     
      IHttpResponse resp = client.call(new GetRequest("Http://localhost:" + server.getLocalPort() + "/"));
     
      BodyDataSource bodyDataSource = resp.getBody();

      for (int i = 0; i < 10000; i++) {
          String value = bodyDataSource.readStringByDelimiter("\r\n\r\n");
          Assert.assertEquals(Integer.toString(i), value);
      }
     
      client.close();
      server.close();
  }
View Full Code Here


        };
        HttpServer server = new HttpServer(hdl);
        server.start();

       
      HttpClient httpClient = new HttpClient();

      for (int i = 0; i < 10; i++) {
          HttpResponseHandler respHdl = new HttpResponseHandler();
          httpClient.send(new GetRequest("http://localhost:" + server.getLocalPort() + "/test"), respHdl);
         
          while (respHdl.getResponse() == null) {
              QAUtil.sleep(50);
          }
     
View Full Code Here

        };
        HttpServer server = new HttpServer(hdl);
        server.start();

       
        HttpClient httpClient = new HttpClient();

        for (int i = 0; i < 10; i++) {
            IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/test"));
            Assert.assertEquals(200, response.getStatus());
        }
    }
View Full Code Here

    public void testHttpClient() throws Exception {
        HttpServer server = new HttpServer(new RequestHandler());
        server.start();
       
       
        HttpClient client = new HttpClient();
        IFutureResponse futureResponse = client.send(new GetRequest("http://localhost:" + server.getLocalPort() + "/?pauseMillis=10"));

        IHttpResponse response = futureResponse.getResponse();
       
        Assert.assertTrue(futureResponse.isDone());
        Assert.assertFalse(futureResponse.isCancelled());
       
        Assert.assertEquals(200, response.getStatus());
       
        Assert.assertFalse(futureResponse.cancel(true));
        Assert.assertFalse(futureResponse.isCancelled());
       
        client.close();
        server.close();
    }
View Full Code Here

    public void testHttpClientTimeout() throws Exception {
        HttpServer server = new HttpServer(new RequestHandler());
        server.start();
       
       
        HttpClient client = new HttpClient();
        IFutureResponse futureResponse = client.send(new GetRequest("http://localhost:" + server.getLocalPort() + "/?pauseMillis=50000"));

        try {
            futureResponse.getResponse(100, TimeUnit.MILLISECONDS);
            Assert.fail("SocketTimeoutException expected");
        } catch (SocketTimeoutException expected) { }
       
        Assert.assertFalse(futureResponse.isCancelled());
        Assert.assertTrue(futureResponse.isDone());
       
        client.close();
        server.close();
    }   
View Full Code Here

    public void testHttpClientCancel() throws Exception {
        HttpServer server = new HttpServer(new RequestHandler());
        server.start();
       
       
        HttpClient client = new HttpClient();
        IFutureResponse futureResponse = client.send(new GetRequest("http://localhost:" + server.getLocalPort() + "/?pauseMillis=500"));

        futureResponse.cancel(true);
       
        Assert.assertTrue(futureResponse.isCancelled());
        Assert.assertTrue(futureResponse.isDone());
       
        client.close();
        server.close();
    }
View Full Code Here

     
    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

   
    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

   
    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

   
    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

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.