Examples of HttpClient


Examples of org.xlightweb.client.HttpClient

    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

Examples of org.xlightweb.client.HttpClient

       
        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

Examples of org.xlightweb.client.HttpClient

       
        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

Examples of org.xlightweb.client.HttpClient

       
        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

Examples of org.xlightweb.client.HttpClient

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

       
        HttpClient httpClient = new HttpClient();
       
        GetRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/test");
        ResponseHandler respHdl = new ResponseHandler();
        httpClient.send(request, respHdl);
       
       
        while (respHdl.getResponse() == null) {
            QAUtil.sleep(100);
        }
       
        IHttpResponse response = respHdl.getResponse();
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("12345", response.getBlockingBody().readString());
       
        httpClient.close();
        server.close();
    }
View Full Code Here

Examples of org.xlightweb.client.HttpClient

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

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

Examples of org.xlightweb.client.HttpClient

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

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

Examples of org.xlightweb.client.HttpClient

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

       
        HttpClient httpClient = new HttpClient();
       
        DeleteRequest request = new DeleteRequest("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

Examples of org.xlightweb.client.HttpClient

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

Examples of org.xlightweb.client.HttpClient

        };
       
        IServer server = new Server(dh);
        server.start();
       
        HttpClient httpClient = new HttpClient();
       
        PutRequest request = new PutRequest("http://localhost:" + server.getLocalPort() + "/test", "text/plain", "12345");
        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
Copyright © 2018 www.massapi.com. 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.