Package org.xlightweb.client

Examples of org.xlightweb.client.HttpClient


   
    Server server = new HttpServer(ctx);
    server.start();
   
   
    HttpClient httpClient = new HttpClient();
   
    IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/site/" + testFile.getName()));
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("application/octet-stream", response.getContentType());
    Assert.assertTrue(response.hasBody());
   
    response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/rpc/getCustomers"));
    Assert.assertEquals(200, response.getStatus());
    Assert.assertTrue(response.getContentType().startsWith("text/plain"));
    Assert.assertTrue(response.hasBody());
   
    httpClient.close();
    server.close();
   
   
    testFile.delete();
  }
View Full Code Here


   
    Server server = new HttpServer(ctx);
    server.start();
   
   
    HttpClient httpClient = new HttpClient();
   
    IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/site/" + testFile.getName()));
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("application/octet-stream", response.getContentType());
    Assert.assertTrue(response.hasBody());
   
    response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/rpc/getCustomers"));
    Assert.assertEquals(200, response.getStatus());
    Assert.assertTrue(response.getContentType().startsWith("text/plain"));
    Assert.assertTrue(response.hasBody());
   
    httpClient.close();
    server.close();
   
   
    testFile.delete();
  }
View Full Code Here

      rootCtx.addHandler(new AccountRequestHandler());

      IServer server = new HttpServer(port, rootCtx);
      server.start();

      HttpClient httpClient = new HttpClient()
     
      IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/Person/1"));
      Assert.assertEquals(200, response.getStatus());
      Assert.assertEquals("person", response.getBlockingBody().readString());
     
      response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/Account/1"));
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("account", response.getBlockingBody().readString());
     
      httpClient.close();
      server.close();
    }
View Full Code Here

   
    Server server = new HttpServer(ctx);
    server.start();
   
   
    HttpClient httpClient = new HttpClient();
   
    IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/test"));
    Assert.assertEquals(200, response.getStatus());
   
    response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/badRequest"));
    Assert.assertEquals(400, response.getStatus());

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

    ctx.addHandler("/test/*", new TestRequestHandler());
    HttpServer server = new HttpServer(ctx);
    server.start();
   
   
    HttpClient httpClient = new HttpClient();
   
    IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + jettyServer.getConnectors()[0].getLocalPort() + "/ctx1/test/you"));
    if (response.getStatus() != 200) {
      System.out.println("got " + response.getStatus() + " instead of 200");
      Assert.fail();
    }
   
    String body = response.getBlockingBody().readString();
    if (body.indexOf("contextPath=/ctx1") == -1) {
      System.out.println("contextPath=/ctx1 expected");
      Assert.fail();
    }
   
    if (body.indexOf("contextPath=/ctx1") == -1) {
      System.out.println("servletPath=/test expected");
      Assert.fail();
    }

   
    response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/ctx1/test/you"));
    if (response.getStatus() != 200) {
      System.out.println("got " + response.getStatus());
      Assert.fail();
    }
   
    body = response.getBlockingBody().readString();
    Assert.assertTrue(body.indexOf("contextPath=/ctx1") != -1);
    Assert.assertTrue(body.indexOf("servletPath=/test") != -1);

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

        @Override
        public void run() {

          running.incrementAndGet();
          try {
            HttpClient httpClient = new HttpClient();
            httpClient.setMaxRetries(0);

            for (int j = 0; j< 1000; j++) {
              GetRequest request = new GetRequest("http://localhost:" + webContainer.getLocalPort() + "/");
              IHttpResponse response = httpClient.call(request);
             
              Assert.assertEquals(200, response.getStatus());
              Assert.assertEquals("OK", response.getBlockingBody().readString());
            }
           
            httpClient.close();

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

        @Override
        public void run() {

          running.incrementAndGet();
          try {
            HttpClient httpClient = new HttpClient();
            httpClient.setMaxRetries(0);

            for (int j = 0; j< 1000; j++) {
              IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
             
              Assert.assertEquals(200, response.getStatus());
              Assert.assertEquals("OK", response.getBlockingBody().readString());
            }
           
            httpClient.close();

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

        @Override
        public void run() {

          running.incrementAndGet();
          try {
            HttpClient httpClient = new HttpClient();
            httpClient.setMaxRetries(0);

            for (int j = 0; j< 1000; j++) {
              GetRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/");
              IHttpResponse response = httpClient.call(request);
             
              Assert.assertEquals(200, response.getStatus());
              Assert.assertEquals("OK", response.getBlockingBody().readString());
            }
           
            httpClient.close();
           
           
          } catch (Exception e) {
            e.printStackTrace();
            errors.add(e.toString());
View Full Code Here

        @Override
        public void run() {

          running.incrementAndGet();
          try {
            HttpClient httpClient = new HttpClient();
            httpClient.setMaxRetries(0);

            for (int j = 0; j< 1000; j++) {
              GetRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/");
              IHttpResponse response = httpClient.call(request);
             
              Assert.assertEquals(200, response.getStatus());
              Assert.assertEquals("OK", response.getBlockingBody().readString());
            }
           
            httpClient.close();

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

        @Override
        public void run() {

          running.incrementAndGet();
          try {
            HttpClient httpClient = new HttpClient();
            httpClient.setMaxRetries(0);

            for (int j = 0; j< 1000; j++) {
              GetRequest request = new GetRequest("http://localhost:" + webContainer.getLocalPort() + "/");
              IHttpResponse response = httpClient.call(request);
             
              if (response.getStatus() != 200) {
                System.out.println("status 200 expected. Got " + response);
                errors.add("status 200 expected. Got " + response.getStatus());
              }
             
              String body = response.getBlockingBody().readString();
              if (!body.equals("OK")) {
                System.out.println("content OK expected. Got " + body);
              }
            }
           
            httpClient.close();

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

TOP

Related Classes of org.xlightweb.client.HttpClient

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.