Package org.xlightweb.client

Examples of org.xlightweb.client.HttpClient


    }
   
   
    @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.getBody().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.getBody().readString());
       
        httpClient.close();
    }
View Full Code Here

     
      private HttpClient httpClient;
     
     
      public void onInit() {
          httpClient = new HttpClient(SSLTestContextFactory.getSSLContext());
          httpClient.setTreat302RedirectAs303(true);
      }
View Full Code Here

        chain.addLast(new RequestHandler());
        HttpServer server = new HttpServer(chain);
        server.start();
       
       
        HttpClient httpClient = new HttpClient();
       
        FutureResponseHandler hdl = new FutureResponseHandler();
        BodyDataSink ds = httpClient.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/test"), 100, hdl);
        for (int i = 0; i < 10; i++) {
            ds.write("0123456789");
        }
        ds.close();
       
       
        IHttpResponse response = hdl.get();
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals(100, response.getBlockingBody().readBytes().length);
       
        httpClient.close();
        server.close();
    }
View Full Code Here

        chain.addLast(new RequestHandler());
        HttpServer server = new HttpServer(chain);
        server.start();
       
       
        HttpClient httpClient = new HttpClient();
       
        FutureResponseHandler hdl = new FutureResponseHandler();
        BodyDataSink ds = httpClient.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/test"), 100, hdl);
        for (int i = 0; i < 10; i++) {
            ds.write("0123456789");
        }
        ds.close();
       
       
        IHttpResponse response = hdl.get();
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals(100, response.getBlockingBody().readBytes().length);
       
        httpClient.close();
        server.close();
    }   
View Full Code Here

  public void testSimple() throws Exception {
     
      HttpServer server = new HttpServer(new RequestHandler());
      server.start();
     
    HttpClient httpClient = new HttpClient();

    FutureResponseHandler hdl = new FutureResponseHandler();
    BodyDataSink ds = httpClient.send(new HttpRequestHeader("POST", "http://localhost:"  +server.getLocalPort() + "/", "text/plain"), 200, hdl);
    for (int i = 0; i < 20; i++) {
        ds.write("0123456789");
        QAUtil.sleep(50);
    }
    ds.close();
       
    IHttpResponse response = hdl.get();
    Assert.assertEquals(200, response.getStatus());
   
    httpClient.close();
    server.close();
  }
View Full Code Here

    public void testCompletionHandler() throws Exception {
       
        HttpServer server = new HttpServer(new RequestHandler());
        server.start();
       
        HttpClient httpClient = new HttpClient();

        FutureResponseHandler hdl = new FutureResponseHandler();
        BodyDataSink ds = httpClient.send(new HttpRequestHeader("POST", "http://localhost:"  +server.getLocalPort() + "/", "text/plain"), 200, hdl);
      
       
        try {
            for (int i = 0; i < 20; i++) {
               
                IWriteCompletionHandler ch = new IWriteCompletionHandler() {
                    public void onWritten(int written) throws IOException {
                        System.out.println("written " + written);
                    }
                   
                    public void onException(IOException ioe) {
                        ioe.printStackTrace();
                    }
                };
               
                ds.write(new ByteBuffer[] { DataConverter.toByteBuffer("0123456789", "UTF-8") }, ch);
                QAUtil.sleep(50);
            }
            ds.close();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
           
        IHttpResponse response = hdl.get();
        Assert.assertEquals(200, response.getStatus());
       
        httpClient.close();
        server.close();
   
View Full Code Here

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

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

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

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

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

       
        HttpClient httpClient = new HttpClient();
       
        GetRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/test");
        IHttpResponse response = httpClient.call(request);
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("12345", response.getBlockingBody().readString());
       
        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.