Package org.xlightweb

Examples of org.xlightweb.WebContainer


 

    @Test
    public void testStreaming() throws Exception {

        WebContainer container = new WebContainer(new MyServlet());
        container.start();
            
        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(".");
        }
       
       
        pool.close();
        container.stop();
    }   
View Full Code Here


 

    @Test
    public void testStreaming() throws Exception {

        WebContainer container = new WebContainer(new MyServlet());
        container.start();
            
        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(".");
        }
       
       
        pool.close();
        container.stop();
    }   
View Full Code Here

 

  @Test
  public void testClientSideUsage() throws Exception {

        WebContainer server = new WebContainer(new TestServlet());
        server.start();
           
        HttpClient httpClient = new HttpClient();
           
        MultipartFormDataRequest req = new MultipartFormDataRequest("http://localhost:" + server.getLocalPort()+ "/");
       
       

       
        String name = "file40k";
        File file = QAUtil.createTestfile_4k();
        req.addPart(name, file);
        req.addPart("test1", "I wake up early and ...");
        req.addPart("test2", "... saw the light");       
       
        IHttpResponse resp = httpClient.call(req);
       
        FileInputStream fis = new FileInputStream(file);
        Content content = new Content(name, file.getName(), "text/html", fis);
        String body = resp.getBlockingBody().toString();
       
        Assert.assertEquals(content.toString() + "\r\n", body);
          
        fis.close();
        file.delete();
        httpClient.close();
        server.stop();
    }
View Full Code Here

 

    @Test
    public void testStreaming() throws Exception {

        WebContainer container = new WebContainer(new MyServlet());
        container.start();
            
        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());
           
            BodyDataSource dataSource = response.getBody();
            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(".");
        }
       
       
        pool.close();
        container.stop();
    }   
View Full Code Here

TOP

Related Classes of org.xlightweb.WebContainer

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.