Examples of IHttpClientEndpoint


Examples of org.xlightweb.client.IHttpClientEndpoint

  @Test
  public void testChunkedTransferEncoding() throws Exception {
    System.out.println("testChunkedTransferEncoding");
   
    IHttpClientEndpoint httpClient = new HttpClient();

    IServer server = new HttpServer(new EchoHandler());
    server.start();



    PostRequest postRequest = new PostRequest("http://localhost:" + server.getLocalPort() + "/", "text/plain", "Herzlichen Gl\u00FCckwunsch, Sie haben sich zur Reinigung des Aufzugs entschlossen.");
    postRequest.setTransferEncoding("chunked");

    IHttpResponse response = httpClient.call(postRequest);
    String body = response.getBlockingBody().readString();

    server.close();
    httpClient.close();
   
    Assert.assertEquals("Herzlichen Gl\u00FCckwunsch, Sie haben sich zur Reinigung des Aufzugs entschlossen.", body);
  }
View Full Code Here

Examples of org.xlightweb.client.IHttpClientEndpoint


  @Test
  public void testPlainBodyData() throws Exception {
    System.out.println("testPlainBodyData");
    IHttpClientEndpoint httpClient = new HttpClient();
   
    IServer server = new HttpServer(new EchoHandler());
    ConnectionUtils.start(server);



    File file = QAUtil.createTestfile_40k();
    RandomAccessFile raf = new RandomAccessFile(file, "r");
    FileChannel fc = raf.getChannel();
   
    System.out.println("call");
    FutureResponseHandler respHdl = new FutureResponseHandler();
    BodyDataSink bodyDataSink = httpClient.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/", "text/plain"), (int) fc.size(), respHdl);
    bodyDataSink.transferFrom(fc);
    bodyDataSink.close();
    fc.close();
    raf.close();
   
    IHttpResponse response = respHdl.getResponse();
   
    BlockingBodyDataSource bodyChannel = response.getBlockingBody();
    String body = bodyChannel.readString();

    System.out.println("closing erver & httpClient");
    server.close();
    httpClient.close();

    if (body.indexOf("Architecture of a Highly Scalable NIO-Based Server") == -1) {
      System.out.println("error got:\r\n" + body);
      Assert.fail();
    }
View Full Code Here

Examples of org.xlightweb.client.IHttpClientEndpoint

    System.out.println("testPlainBodyData2");

    IServer server = new HttpServer(new EchoHandler());
    server.start();

    IHttpClientEndpoint httpClient = new HttpClient();

    FutureResponseHandler hdl = new FutureResponseHandler();

    byte[] data = "hello".getBytes("UTF-8");

    HttpRequestHeader header = new HttpRequestHeader("POST", "http://localhost:" +  server.getLocalPort() + "/");
    header.setContentType("text/plain; charset=UTF-8");

    BodyDataSink bodyDataSink = httpClient.send(header, data.length, hdl);
    bodyDataSink.write(data);
    bodyDataSink.close();

    IHttpResponse response = hdl.getResponse();
    String body = response.getBlockingBody().readString();


    server.close();
    httpClient.close();


    Assert.assertEquals("hello", body);
  }
View Full Code Here

Examples of org.xlightweb.client.IHttpClientEndpoint

  @Test
  public void testBulkPlainBodyData() throws Exception {
    System.out.println("testBulkPlainBodyData");
   
    IHttpClientEndpoint httpClient = new HttpClient();

    IServer server = new HttpServer(new EchoHandler());
    ConnectionUtils.start(server);


    IHttpResponseHandler hdl = new IHttpResponseHandler() {
      public void onResponse(IHttpResponse response) throws IOException {
      }
     
      public void onException(IOException ioe) {
      }
    };
   
    BodyDataSink bodyDataSink = httpClient.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/"), hdl);
    bodyDataSink.write(QAUtil.generateByteArray(10000));
    bodyDataSink.flush();
    bodyDataSink.write(QAUtil.generateByteArray(10000));

    server.close();
    httpClient.close();
  }
View Full Code Here

Examples of org.xlightweb.client.IHttpClientEndpoint

    System.out.println("running testFlushedPlainBodyData");
   
    IServer server = new HttpServer(new EchoHandler());
    server.start();

    IHttpClientEndpoint httpClient = new HttpClient();

    FutureResponseHandler hdl = new FutureResponseHandler();
    HttpRequestHeader header = new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/");
    header.setContentType("text/plain; charset=UTF-8");


    int chunkSize = 100;
    int loops = 10;
   
    BodyDataSink bodyDataSink = httpClient.send(header, chunkSize * loops, hdl);

    for (int i = 0; i < loops; i++) {
      bodyDataSink.write(QAUtil.generateByteBuffer(chunkSize));
    }
   
    bodyDataSink.close();
   
    IHttpResponse response = hdl.getResponse();
   
    byte[] result = response.getBlockingBody().readBytes();
    Assert.assertEquals(chunkSize * loops, result.length);
   
    server.close();
    httpClient.close()
  }
View Full Code Here

Examples of org.xlightweb.client.IHttpClientEndpoint

   
    final IServer server = new HttpServer(new TestHandler());
    ConnectionUtils.start(server);


    IHttpClientEndpoint httpClient = new HttpClient();


    File file = QAUtil.createTestfile_40k();

    FutureResponseHandler hdl = new FutureResponseHandler();
    HttpRequestHeader header = new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/");
    header.setContentType("text/plain; charset=UTF-8");


   
    BodyDataSink bodyDataSink = httpClient.send(header, (int) file.length(), hdl);

    InputStream is = new FileInputStream(file);
    int chunkSize = 63;
    int read = 0;
    int total = 0;
   
    do {
      byte[] chunk = new byte[chunkSize];
      read = is.read(chunk);
     
      if (read > 0) {
        total += read;
        if (read < chunkSize) {
          byte[] newArray = new byte[read];
          System.arraycopy(chunk, 0, newArray, 0, read);
          chunk = newArray;
        }       
        bodyDataSink.write(chunk);
      }
    } while (read > 0);
   
    bodyDataSink.close();
   
    IHttpResponse response = hdl.getResponse();
   
    Assert.assertTrue(response.getStatus() == 200)
    Assert.assertEquals("it works", response.getBlockingBody().readString());
   
    System.out.print(".");
   
    file.delete();
    server.close();
    httpClient.close();
 
  }
View Full Code Here

Examples of org.xlightweb.client.IHttpClientEndpoint

   
    final IServer server = new HttpServer(new EchoHandler());
    ConnectionUtils.start(server);


    IHttpClientEndpoint httpClient = new HttpClient();

    FutureResponseHandler hdl = new FutureResponseHandler();
    HttpRequestHeader header = new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/");
    header.setContentType("text/plain; charset=UTF-8");
    BodyDataSink bodyDataSink = httpClient.send(header, hdl);

    File file = QAUtil.createTestfile_40k();
    InputStream is = new FileInputStream(file);
    int chunkSize = 64;
    int read = 0;
    do {
      byte[] chunk = new byte[chunkSize];
      read = is.read(chunk);
      if (read > 0) {
        if (read < chunkSize) {
          byte[] newArray = new byte[read];
          System.arraycopy(chunk, 0, newArray, 0, read);
          chunk = newArray;
        }
        bodyDataSink.write(chunk);
      }
    } while (read > 0);

    bodyDataSink.close();

    IHttpResponse response = hdl.getResponse();
    String body = response.getBlockingBody().readString();

    file.delete();
    server.close();
    httpClient.close();

    Assert.assertTrue("got " + body, body.indexOf("</html>") != -1);
  }
View Full Code Here

Examples of org.xlightweb.client.IHttpClientEndpoint

   
    final IServer server = new HttpServer(new EchoHandler());
    server.start();


    IHttpClientEndpoint httpClient = new HttpClient();

    FutureResponseHandler hdl = new FutureResponseHandler();
    HttpRequestHeader header = new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/");
    header.setContentType("text/plain; charset=UTF-8");
    BodyDataSink bodyDataSink = httpClient.send(header, hdl);
    Assert.assertTrue("flushmode is not sync", bodyDataSink.getFlushmode() == FlushMode.SYNC);

    File file = QAUtil.createTestfile_40k();
    InputStream is = new FileInputStream(file);
    System.out.println("got inputstream " + is);
   
    int chunkSize = 64;
    int count = 1;
    do {
      byte[] chunk = new byte[chunkSize];
      count = is.read(chunk);
      if (count > 0) {
        if (count < chunkSize) {
          byte[] newArray = new byte[count];
          System.arraycopy(chunk, 0, newArray, 0, count);
          chunk = newArray;
        }
        try {
          bodyDataSink.write(chunk);
          bodyDataSink.flush();
        } catch (Exception e) {
          System.out.println("error occured by writing chunk " + e.toString());
          throw e;
        }
      }
    } while (count >= 0);

    bodyDataSink.close();
    System.out.println("close bodyDataSink");
   
    IHttpResponse response = hdl.getResponse();
    if (!response.hasBody()) {
      System.out.println("response should have a body");
      Assert.fail("response should have a body");
    }
   
    String body = response.getBlockingBody().readString();

    file.delete();
    server.close();
    httpClient.close();

    if (body.indexOf("</html>") == -1) {
      System.out.println("incomplete or wrong body");
      Assert.fail("incomplete or wrong body");
    }
View Full Code Here

Examples of org.xlightweb.client.IHttpClientEndpoint

        public void run() {
         
          try {
            running.incrementAndGet();
         
            IHttpClientEndpoint httpClient = new HttpClient();

            for (int i = 0; i < 50; i++) {
              FutureResponseHandler hdl = new FutureResponseHandler();
              HttpRequestHeader header = new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/");
              header.setContentType("text/plain; charset=UTF-8");
             
              BodyDataSink bodyDataSink = httpClient.send(header, hdl);
              if (bodyDataSink.getFlushmode() != FlushMode.SYNC) {
                System.out.println("flushmode should be sync");
                Assert.fail();
              }
             
              for (int k = 0; k < 10; k++) {
                try {
                  byte[] data = QAUtil.generateByteArray(128);
                  bodyDataSink.write(data);
                  bodyDataSink.flush();
                } catch (Exception e) {
                  System.out.println("error occured by writing chunk " + e.toString());
                  Assert.fail();
                }
              }
         
              bodyDataSink.close();
             
              IHttpResponse response = hdl.getResponse();
              if (!response.hasBody()) {
                System.out.println("response should have a body");
                Assert.fail();
              }
             
              response.getBlockingBody().readString();
            }

            httpClient.close();
           
           
          } catch (Exception e) {
            errors.add(e.toString());
          }
View Full Code Here

Examples of org.xlightweb.client.IHttpClientEndpoint

    Assert.assertEquals(302, response.getStatus());
  }
 
  @Test
  public void testLiveGet2() throws Exception {
    IHttpClientEndpoint httpClient = new HttpClient();
 
    IHttpResponse response = httpClient.call(new GetRequest("http://sourceforge.net/project/stats/index.php?group_id=169583&ugn=xsocket"));
    Assert.assertEquals(200, response.getStatus());
  }
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.