Package org.xlightweb.client

Examples of org.xlightweb.client.HttpClient


                @Override
                public void run() {

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

                        for (int j = 0; j< 100; 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


                @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

        @Override
        public void run() {

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

            for (int j = 0; j< 1000; j++) {
              IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
             
              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

        @Override
        public void run() {

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

            for (int j = 0; j< 1000; j++) {
              GetRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/");
              IHttpResponse response = httpClient.call(request);
             
              if (response.getStatus() != 200) {
                System.out.println("status 200 expected. Got " + response.getStatus());
                Assert.fail("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

        };
       
        IServer server = new Server(dh);
        server.start();

        HttpClient httpClient = new HttpClient();

        GetRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/");
        IHttpResponse response = httpClient.call(request);
           
        if (response.getStatus() != 200) {
            System.out.println("status 200 expected. Got " + response.getStatus());
            Assert.fail("status 200 expected. Got " + response.getStatus());
        }
           
        try {
            response.getBlockingBody().readString();
            Assert.fail("ProtocolException expected");
        } catch (ProtocolException expected) { }
       
        httpClient.close();
        server.close();
    }
View Full Code Here

  @Test
  public void testRewriteCookie() throws Exception {
      HttpServer server = new HttpServer(new RequestHandler());
      server.start();
     
      HttpClient httpClient = new HttpClient();
     
      GetRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/test");
      IHttpResponse response = httpClient.call(request);
      Assert.assertEquals(200, response.getStatus());
     
      request = new GetRequest("http://localhost:" + server.getLocalPort() + "/test");
      response = httpClient.call(request);
      Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("JSESSIONID=1", request.getHeader("Cookie"));
     
        request = new GetRequest("http://localhost:" + server.getLocalPort() + "/test");
        response = httpClient.call(request);
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("JSESSIONID=2", request.getHeader("Cookie"));

        request = new GetRequest("http://localhost:" + server.getLocalPort() + "/test");
        response = httpClient.call(request);
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("JSESSIONID=3", request.getHeader("Cookie"));

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

    public void testWebSockets() throws Exception {
       
        HttpServer server = new HttpServer(new DualHandler());
        server.start();
       
        HttpClient httpClient = new HttpClient();
       
        IWebSocketConnection webSocketConnection = httpClient.openWebSocketConnection("ws://localhost:" +  server.getLocalPort());
       
        webSocketConnection.writeMessage(new TextMessage("GetData"));
        WebSocketMessage msg = webSocketConnection.readMessage();
        Assert.assertEquals("id: 556\r\ndata: 566;555\r\n\r\n", msg.toString());
        System.out.println(msg);

        webSocketConnection.writeMessage(new TextMessage("GetData"));
        msg = webSocketConnection.readMessage();
        Assert.assertEquals("id: 557\r\ndata: 567;556\r\n\r\n", msg.toString());
        System.out.println(msg);
       
        webSocketConnection.close();
        httpClient.close();
        server.close();
    }
View Full Code Here

       
        HttpServer server = new HttpServer(new DualHandler());
        server.start();
       
       
        HttpClient httpClient = new HttpClient();
       
        IEventDataSource eventSource = httpClient.openEventDataSource("http://localhost:" +  server.getLocalPort() + "/", false);
       
        Event event = eventSource.readMessage();
        Assert.assertEquals(": keep-alive\r\n\r\n", event.toString());
        System.out.println(event);
       
        event = eventSource.readMessage();
        Assert.assertEquals("id: 556\r\ndata: 566;555\r\n\r\n", event.toString());
        System.out.println(event);
       
        eventSource.close();
       
        httpClient.close();
       
        server.close();
    }
View Full Code Here

  public void testLocal() throws Exception {
   
    IServer server = new HttpServer(new RequestHandler());
    server.start();
   
    HttpClient httpClient = new HttpClient();
    IHttpResponse resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
    BodyDataSource body = resp.getBody();
   
    body.markReadPosition();
    Assert.assertEquals("line one", body.readStringByDelimiter("\r\n"));
   
    body.resetToReadMark();
    Assert.assertEquals("line one", body.readStringByDelimiter("\r\n"));
    Assert.assertEquals("line two", body.readStringByDelimiter("\r\n"));
   
   
   
    httpClient.close();
    server.close();
  }
View Full Code Here

       
        HttpServer server = new HttpServer(hdl);
        server.start();
       
       
        HttpClient client = new HttpClient();
       
        GetRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/Events");
        request.setHeader("Accept", "text/event-stream");
       
        IHttpResponse response = client.call(request);
        BodyDataSource body = response.getBody();
       
        Assert.assertEquals(200, response.getStatus());
       
        Event event = Event.parse(body.readStringByDelimiter("\r\n\r\n"));
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.