Package org.xlightweb.client

Examples of org.xlightweb.client.HttpClientConnection$MessageHandler


    public void testCon() throws Exception {
       
        HttpServer server = new HttpServer(new RequestHandler());
        server.start();
       
        HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());

        FutureResponseHandler hdl = new FutureResponseHandler();
        BodyDataSink ds = con.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());
       
        con.close();
        server.close();
    }
View Full Code Here


       
        RequestHandler reqHdl = new RequestHandler();
        HttpServer server = new HttpServer(reqHdl);
        server.start();
       
        HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
       
        FutureResponseHandler respHdl = new FutureResponseHandler();
        BodyDataSink dataSink = con.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/"), respHdl);
       
        dataSink.write("test");
        QAUtil.sleep(200);
       
        dataSink.write("OneTwo");
        QAUtil.sleep(200);
       
        dataSink.write("End");
        dataSink.close();
       
        IHttpResponse response = respHdl.getResponse();
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("testOneTwoEnd", DataConverter.toString(reqHdl.getData()));
       
        con.close();
        server.close();
    }
View Full Code Here

       
        RequestHandler reqHdl = new RequestHandler();
        HttpServer server = new HttpServer(reqHdl);
        server.start();
       
        HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
       
        File file = QAUtil.createTestfile_4k();
       
        FutureResponseHandler respHdl = new FutureResponseHandler();
        BodyDataSink dataSink = con.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/"), respHdl);
       
       
        RandomAccessFile raf = new RandomAccessFile(file, "r");
        FileChannel fc = raf.getChannel();
        dataSink.transferFrom(fc);
        fc.close();
        raf.close();
        dataSink.close();
       
        IHttpResponse response = respHdl.getResponse();
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertTrue(QAUtil.isEquals(file, reqHdl.getData()));
       
        file.delete();
        con.close();
        server.close();
    }
View Full Code Here

       
        RequestHandler2 reqHdl = new RequestHandler2();
        HttpServer server = new HttpServer(reqHdl);
        server.start();
       
        HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
       
        File file = QAUtil.createTestfile_4k();
       
        FutureResponseHandler respHdl = new FutureResponseHandler();
        BodyDataSink dataSink = con.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/"), respHdl);
       
       
        RandomAccessFile raf = new RandomAccessFile(file, "r");
        FileChannel fc = raf.getChannel();
        dataSink.transferFrom(fc);
        fc.close();
        raf.close();
        dataSink.close();
       
        IHttpResponse response = respHdl.getResponse();
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertTrue(QAUtil.isEquals(file, "ISO-8859-1", reqHdl.getData()));
       
        file.delete();
        con.close();
        server.close();
    }
View Full Code Here

      server.start();
     
      NonBlockingConnectionPool pool = new NonBlockingConnectionPool();
             
        for (int i = 0; i < 1000; i++) {
            HttpClientConnection httpCon = new HttpClientConnection(pool.getNonBlockingConnection("localhost", server.getLocalPort()));
            IHttpResponse resp = httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
       
            InputStream in = Channels.newInputStream(resp.getBlockingBody());
            in.close();
               
            httpCon.close();
        }
       
        pool.close();
  }
View Full Code Here

      IServer server = new Server(dh);
      server.start();
     
      HttpClientConnectionPool pool = new HttpClientConnectionPool();
             
      HttpClientConnection httpCon = pool.getHttpClientConnection("localhost", server.getLocalPort());
      IHttpResponse resp = httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
       
      InputStream in = Channels.newInputStream(resp.getBlockingBody());
      in.close();

View Full Code Here

      server.start();
     
      HttpClientConnectionPool pool = new HttpClientConnectionPool();
             
        for (int i = 0; i < 1000; i++) {
            HttpClientConnection httpCon = pool.getHttpClientConnection("localhost", server.getLocalPort());
            IHttpResponse resp = httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
       
            InputStream in = Channels.newInputStream(resp.getBlockingBody());
            in.close();
            System.out.print(".");
        }
View Full Code Here

            
        HttpClientConnectionPool pool = new HttpClientConnectionPool();

       
        for (int i = 0; i < 100; i++) {
            HttpClientConnection con = pool.getHttpClientConnection("localhost", container.getLocalPort());
           
            FutureResponseHandler respHdl = new FutureResponseHandler();
            BodyDataSink dataSink = con.send(new HttpRequestHeader("POST", "http://localhost:" + container.getLocalPort() + "/test"), respHdl);
           
            dataSink.write("test");
           
            IHttpResponse response = respHdl.getResponse();
            Assert.assertEquals(200, response.getStatus());
           
            BlockingBodyDataSource dataSource = response.getBlockingBody();
            Assert.assertEquals("test", dataSource.readStringByLength(4));
           
            dataSink.write("12345");
            Assert.assertEquals("12345", dataSource.readStringByLength(5));
           
            dataSink.write("789");
            Assert.assertEquals("789", dataSource.readStringByLength(3));
           
            dataSink.close();
            con.close();   
           
            System.out.print(".");
        }
       
       
View Full Code Here

   
    IServer server = new Server(hdl);
    server.start();
   
   
    HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
    IHttpResponse response = con.call(new GetRequest("/"));
   
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("12345", response.getBlockingBody().readString());
    Assert.assertEquals("me", response.getServer());
   
    con.close();
    server.close();
  }
View Full Code Here

   
    IServer server = new Server(hdl);
    server.start();
   
   
    HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
    IHttpResponse response = con.call(new GetRequest("/"));
   
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("12345", response.getBlockingBody().readString());
    Assert.assertEquals("me", response.getServer());
    Assert.assertEquals("", response.getHeader("ETag"));
   
    con.close();
    server.close();
  }
View Full Code Here

TOP

Related Classes of org.xlightweb.client.HttpClientConnection$MessageHandler

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.