Package org.xlightweb.client

Examples of org.xlightweb.client.HttpClientConnection$ClientExchange$ConnectHandler


    chain.addFirst(new EchoHandler());
   
      HttpServer server = new HttpServer(chain);
      server.start();
     
      HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
     
     
      FutureResponseHandler respHandler = new FutureResponseHandler();
      BodyDataSink dataSink = con.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/"), respHandler);
      dataSink.write("test");
      QAUtil.sleep(300);
     
      dataSink.write("123");
      QAUtil.sleep(300);
     
      dataSink.write("456");
      QAUtil.sleep(300);
     
      dataSink.close();
     
     
      IHttpResponse response = respHandler.getResponse();
      Assert.assertEquals("test123456", response.getBlockingBody().readString());
     
       
      con.close();
      server.close();
  }
View Full Code Here


    chain.addFirst(echoHandler);
   
      HttpServer server = new HttpServer(chain);
      server.start();
     
      HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
     
 
      FutureResponseHandler respHandler = new FutureResponseHandler();
      BodyDataSink dataSink = con.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/?isSuspend=true&durationMillis=2000"), respHandler);
     
      StringBuilder sb = new StringBuilder();
     
      for (int i = 1; i < 2; i++) {
        String data = new String(QAUtil.generateByteArray(222000 * i));
        sb.append(data);
       
        System.out.println("write data");
        dataSink.write(data);
        QAUtil.sleep(200);
      }
     
      System.out.println("clsoe data sink");
      dataSink.close();
     
     
      System.out.println("get response handle");
      IHttpResponse response = respHandler.getResponse();
     
      System.out.println("reading response");
      Assert.assertEquals(sb.toString(), response.getBlockingBody().readString());
  
      System.out.println("close con & server");
      con.close();
      server.close();
     
      System.gc();
  }
View Full Code Here

        EchoHandler echoHandler = new EchoHandler();
       
        HttpServer server = new HttpServer(echoHandler);
        server.start();
       
        HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
       
   
        FutureResponseHandler respHandler = new FutureResponseHandler();
        BodyDataSink dataSink = con.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/?isSuspend=true&durationMillis=2000"), respHandler);
       
        StringBuilder sb = new StringBuilder();
       
        for (int i = 1; i < 20; i++) {
            String data = new String(QAUtil.generateByteArray(22 * i));
            sb.append(data);
            dataSink.write(data);
            QAUtil.sleep(200);
        }
       
        dataSink.close();
       
       
        IHttpResponse response = respHandler.getResponse();
        Assert.assertEquals(sb.toString(), response.getBlockingBody().readString());
    
        con.close();
        server.close();
       
        System.gc();

  }
View Full Code Here

        EchoHandler echoHandler = new EchoHandler();
       
        HttpServer server = new HttpServer(echoHandler);
        server.start();
       
        HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
       
   
        FutureResponseHandler respHandler = new FutureResponseHandler();
        BodyDataSink dataSink = con.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/?isSuspend=true&durationMillis=2000"), respHandler);
       
        StringBuilder sb = new StringBuilder();
       
        for (int i = 1; i < 2; i++) {
            String data = new String(QAUtil.generateByteArray(222000 * i));
            sb.append(data);
            dataSink.write(data);
            QAUtil.sleep(200);
        }
       
        System.out.println("data sink close");
        dataSink.close();
       
        System.out.println("get response handle");
        IHttpResponse response = respHandler.getResponse();
        Assert.assertEquals(sb.toString(), response.getBlockingBody().readString());
          
        con.close();
        server.close();
       
        System.gc();
  }
View Full Code Here

        FileHandler srvHdl = new FileHandler();
        HttpServer server = new HttpServer(srvHdl);
        server.start();
       
        HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
       
        File file = QAUtil.createTestfile_40k();
       
        FutureResponseHandler respHdl = new FutureResponseHandler();
        BodyDataSink dataSink = con.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/"), respHdl);
          
        RandomAccessFile raf = new RandomAccessFile(file, "r");
        AsyncWriter writer = new AsyncWriter(dataSink, raf);
        writer.onWritten(0);
       
       

        IHttpResponse response = respHdl.getResponse();
       
        Assert.assertEquals(200,response.getStatus());
        Assert.assertTrue(QAUtil.isEquals(file, "ISO-8859-1", srvHdl.getData()));
       
        file.delete();
        con.close();
        server.close();
    }
View Full Code Here

   
    public HeartbeatLink(String host, int port, boolean isGood) throws IOException {
      this.isGood = isGood;
     
      con = new HttpClientConnection(host, port);
    }
View Full Code Here

        HttpServer server = new HttpServer(new ContinueHandler());
        server.start();
       
        System.out.println("testAutoConnectionContinueHeader server: " + server.getLocalPort());
       
        HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
        PostRequest request = new PostRequest("http://localhost:" + server.getLocalPort() + "/test", "text/plain", "test1234567890");
        request.setHeader("Expect", "100-Continue");
       
       
        IHttpResponse response = con.call(request);
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("test1234567890", response.getBlockingBody().readString());
       
        con.close();
        server.close();
    }
View Full Code Here

        server.start();
       
        System.out.println("testManualConnectionContinueHeader server: " + server.getLocalPort());
       
       
        HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
        HttpRequestHeader requestHeader = new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/test", "text/plain; charset=iso-8859-1");
        requestHeader.setHeader("Expect", "100-Continue");
       
    
        String data = "1234567890";
        ResponseHandlerContinueNotSupported respHdl = new ResponseHandlerContinueNotSupported(data);
        BodyDataSink dataSink = con.send(requestHeader, respHdl);
        respHdl.setBodyDataSink(dataSink);
        dataSink.flush();
       
        while ((respHdl.getLastResponse() == null)) {
            QAUtil.sleep(100);
        }

        QAUtil.sleep(300);
       
        IHttpResponse response = respHdl.getLastResponse();

        Assert.assertNull(respHdl.getLastContinue());
        Assert.assertEquals(200, response.getStatus());
       
       
        con.close();
        server.close();
    }
View Full Code Here

        server.start();
       
        System.out.println("testManualConnectionContinueHeader server: " + server.getLocalPort());
       
       
        HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
        HttpRequestHeader requestHeader = new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/test", "text/plain; charset=iso-8859-1");
        requestHeader.setHeader("Expect", "100-Continue");
       
    
        String data = "test1234567890";
        ResponseHandler respHdl = new ResponseHandler(data);
        BodyDataSink dataSink = con.send(requestHeader, respHdl);
        respHdl.setBodyDataSink(dataSink);
        dataSink.flush();

       
        while ((respHdl.getLastResponse() == null) || (respHdl.getLastResponse().getStatus() == 100)) {
            QAUtil.sleep(100);
        }
       
       
        QAUtil.sleep(300);
       
        IHttpResponse response = respHdl.getLastResponse();
       
        Assert.assertEquals(100, respHdl.getLastContinue().getStatus());
        Assert.assertEquals("Continue", respHdl.getLastContinue().getReason());
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals(data, response.getBlockingBody().readString());
       
        con.close();
        server.close();
    }
View Full Code Here

        server.start();
       
        System.out.println("testManualConnectionContinueHeader server: " + server.getLocalPort());
       
       
        HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());
        HttpRequestHeader requestHeader = new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/test", "text/plain; charset=iso-8859-1");
        requestHeader.setHeader("Expect", "100-Continue");
       
    
        String data = "test1234567890";
        ResponseHandlerContinueNotSupported respHdl = new ResponseHandlerContinueNotSupported(data);
        BodyDataSink dataSink = con.send(requestHeader, respHdl);
        respHdl.setBodyDataSink(dataSink);
        dataSink.flush();
       
        while ((respHdl.getLastResponse() == null)) {
            QAUtil.sleep(100);
        }
       
       
        IHttpResponse response = respHdl.getLastResponse();
        Assert.assertNull(respHdl.getLastContinue());
        Assert.assertEquals(200, response.getStatus());
       
        con.close();
        server.close();
    }
View Full Code Here

TOP

Related Classes of org.xlightweb.client.HttpClientConnection$ClientExchange$ConnectHandler

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.