Package org.xlightweb.client

Examples of org.xlightweb.client.HttpClient


        private HttpClient httpClient;

       
        public void onInit() {
            httpClient = new HttpClient();
        }
View Full Code Here


        };
       
        HttpServer server = new HttpServer(reqHdl);
        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setCacheMaxSizeKB(100);
       
        IHttpResponse resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertEquals("test", resp.getBody().readString());
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
       
        QAUtil.sleep(1000);
       
        resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertTrue(resp.getHeader(CacheHandler.XHEADER_NAME).startsWith("HIT"));
        Assert.assertEquals("test", resp.getBody().readString());
       
       
        Assert.assertEquals(1, httpClient.getNumCacheHit());
        Assert.assertEquals(1, httpClient.getNumCacheMiss());
       
        httpClient.close();
        server.close();
  }  
View Full Code Here

        };
       
        HttpServer server = new HttpServer(reqHdl);
        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setCacheMaxSizeKB(100);
       
        IHttpResponse resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertEquals("test", resp.getBody().readString());
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
       
        QAUtil.sleep(1000);
       
        resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
        Assert.assertEquals("test", resp.getBody().readString());
       
       
        Assert.assertEquals(0, httpClient.getNumCacheHit());
        Assert.assertEquals(2, httpClient.getNumCacheMiss());
       
        httpClient.close();
        server.close();
    }  
View Full Code Here

        };
       
        HttpServer server = new HttpServer(reqHdl);
        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setCacheMaxSizeKB(100);
       
        IHttpResponse resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertEquals("test", resp.getBody().readString());
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
       
        QAUtil.sleep(1000);
       
        resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
        Assert.assertEquals("test", resp.getBody().readString());
       
       
        Assert.assertEquals(0, httpClient.getNumCacheHit());
        Assert.assertEquals(2, httpClient.getNumCacheMiss());
       
        httpClient.close();
        server.close();
    }    
View Full Code Here

  public void testMultipleCookies() throws Exception {
   
    HttpServer server = new HttpServer(new RequestHandler());
    server.start();
   
    HttpClient httpClient = new HttpClient();
    httpClient.setAutoHandleCookies(true);
   
    IHttpRequest req = new GetRequest("http://localhost:" + server.getLocalPort() + "/");
    httpClient.call(req);
   
    req = new GetRequest("http://localhost:" + server.getLocalPort() + "/");
    httpClient.call(req);
   
    Assert.assertEquals("name1=1; name2=2", req.getHeader("Cookie"));
   
    httpClient.close();
    server.close();
  }
View Full Code Here

      Thread t = new Thread() {
        public void run() {
          running++;
         
          try {
            HttpClient httpClient = new HttpClient();
 
            for (int j = 0; j < loops; j++) {
              long start = System.currentTimeMillis();
              IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + port + "/"));

              long elapsed = (System.currentTimeMillis() - start);
              total.addAndGet((int) elapsed);
         
             
View Full Code Here

   
    public static void main(String[] args) throws IOException {
       
        int port = Integer.parseInt(args[0]);
   
        HttpClient httpClient = new HttpClient();
   
    
        /////////////////////////
        // with handler
        IWebSocketHandler handler = new IWebSocketHandler() {
           
            public void onMessage(IWebSocketConnection con) throws IOException {
                WebSocketMessage msg = con.readMessage();
                System.out.println(msg);
            }
           
            public void onDisconnect(IWebSocketConnection con) throws IOException { }
           
            public void onConnect(IWebSocketConnection con) throws IOException, UnsupportedProtocolException {  }
        };
        IWebSocketConnection webSocketConnection = httpClient.openWebSocketConnection("ws://localhost:" + port, "com.example.echo", handler);
       
        webSocketConnection.writeMessage(new TextMessage("0123456789"));

       
       
        ////////////////////////////////////////////
        // without handler 
        IWebSocketConnection webSocketConnection2 = httpClient.openWebSocketConnection("ws://localhost:" + port, "com.example.echo");
   
        webSocketConnection2.writeMessage(new TextMessage("0123456789"));
        WebSocketMessage msg = webSocketConnection2.readMessage();
        Assert.assertEquals("0123456789", msg.toString());
View Full Code Here

        RequestHandler hdl = new RequestHandler();
        HttpServer server = new HttpServer(hdl);
        server.start();

        HttpClient httpClient = new HttpClient();
       
        long start = System.currentTimeMillis();
        IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/test?delay=2000"));
       
        long elapsed = System.currentTimeMillis() - start;
        System.out.println("elapsed " + elapsed);
       
        Assert.assertTrue(elapsed < 2000);
        Assert.assertEquals(200, response.getStatus());
        Assert.assertFalse(response.getNonBlockingBody().isCompleteReceived());
       
        httpClient.close();
        server.close();
    }
View Full Code Here

        RequestHandler hdl = new RequestHandler();
        HttpServer server = new HttpServer(hdl);
        server.start();

        HttpClient httpClient = new HttpClient();
        httpClient.setCallReturnOnMessage(true);
       
        long start = System.currentTimeMillis();
        IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/test?delay=2000"));
       
        long elapsed = System.currentTimeMillis() - start;
        System.out.println("elapsed " + elapsed);
       
        Assert.assertTrue(elapsed >= 2000);
        Assert.assertEquals(200, response.getStatus());
        Assert.assertTrue(response.getNonBlockingBody().isCompleteReceived());
       
        httpClient.close();
        server.close();
    }
View Full Code Here

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


        HttpClient httpClient = new HttpClient();
        httpClient.setCallReturnOnMessage(true);
       
        IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/test"));
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertTrue(response.getNonBlockingBody().isCompleteReceived());
       
        httpClient.close();
        server.close();
    }
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.