Package org.xlightweb.client

Examples of org.xlightweb.client.HttpClient


        };
       
        HttpServer server = new HttpServer(reqHdl);
        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setFollowsRedirectMode(FollowsRedirectMode.ALL);
        httpClient.setCacheMaxSizeKB(100);
       
        IHttpResponse resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/test"));
        Assert.assertEquals(200, resp.getStatus());
       
        QAUtil.sleep(1000);
       
        resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/test"));
        Assert.assertEquals(200, resp.getStatus());
        Assert.assertTrue(resp.getHeader(CacheHandler.XHEADER_NAME).startsWith("HIT"));
       
        Assert.assertEquals(2, 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() + "/test"));
        Assert.assertEquals(303, resp.getStatus());
        Assert.assertNotNull(resp.getHeader("Location"));
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
       
        QAUtil.sleep(1000);
       
        resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/test"));
        Assert.assertEquals(303, resp.getStatus());
        Assert.assertNotNull(resp.getHeader("Location"));
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
       
       
        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() + "/test"));
        Assert.assertEquals(302, resp.getStatus());
        Assert.assertNotNull(resp.getHeader("Location"));
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
       
        QAUtil.sleep(1000);
       
        resp = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/test"));
        Assert.assertEquals(302, resp.getStatus());
        Assert.assertNotNull(resp.getHeader("Location"));
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
       
       
        Assert.assertEquals(0, httpClient.getNumCacheHit());
        Assert.assertEquals(2, httpClient.getNumCacheMiss());
       
        httpClient.close();
        server.close();
    }
View Full Code Here

    @Test
    public void testClientAndServer() throws Exception {
        HttpServer server = new HttpServer(new MixedRequestHandler());
        server.start();
        HttpClient httpClient = new HttpClient();
       
        IWebSocketConnection webSocketConnection = httpClient.openWebSocketConnection("ws://localhost:" + server.getLocalPort());
       
        WebSocketMessage msg = webSocketConnection.readMessage();
        Assert.assertTrue(msg.isTextMessage());
        Assert.assertEquals("Hello you", msg.toString());
       
        webSocketConnection.writeMessage(new TextMessage("01234567890"));
       
        msg = webSocketConnection.readMessage();
        Assert.assertTrue(msg.isTextMessage());
        Assert.assertEquals("01234567890", msg.toString());
       
        httpClient.close();
        server.close();
    }
View Full Code Here

    @Test
    public void testClientAndServerClose() throws Exception {
        HttpServer server = new HttpServer(new MixedRequestHandler());
        server.start();
       
        HttpClient httpClient = new HttpClient();
       
        IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("OK", response.getBody().toString());
       
       
        IWebSocketConnection webSocketConnection = httpClient.openWebSocketConnection("ws://localhost:" + server.getLocalPort());
       
        WebSocketMessage msg = webSocketConnection.readMessage();
        Assert.assertTrue(msg.isTextMessage());
        Assert.assertEquals("Hello you", msg.toString());
       
        webSocketConnection.writeMessage(new TextMessage("01234567890"));
       
        msg = webSocketConnection.readMessage();
        Assert.assertEquals("01234567890", msg.toString("UTF-8"));
  
       
        webSocketConnection.close();
        Assert.assertFalse(webSocketConnection.isOpen());
       
        QAUtil.sleep(500);
       
        httpClient.close();
        server.close();
    }
View Full Code Here

        };
       
        HttpServer server = new HttpServer(hdl);
        server.start();
       
        HttpClient httpClient = new HttpClient();
       
        try {
            httpClient.openWebSocketConnection("ws://localhost:" + server.getLocalPort());
            Assert.fail("UnsupportedProtocolException expected");
        } catch (UnsupportedProtocolException expected) { }
               
        httpClient.close();
        server.close();
    }
View Full Code Here

    @Test
    public void testClientAndServerSSL() throws Exception {
        HttpServer server = new HttpServer(0, new MixedRequestHandler(), SSLTestContextFactory.getSSLContext(), true);
        server.start();
       
        HttpClient httpClient = new HttpClient(SSLTestContextFactory.getSSLContext());
       
        IWebSocketConnection webSocketConnection = httpClient.openWebSocketConnection("wss://localhost:" + server.getLocalPort());
       
        WebSocketMessage msg = webSocketConnection.readMessage();
        Assert.assertTrue(msg.isTextMessage());
        Assert.assertEquals("Hello you", msg.toString());
       
        webSocketConnection.writeMessage(new TextMessage("01234567890"));
       
        msg = webSocketConnection.readMessage();
        Assert.assertTrue(msg.isTextMessage());
        Assert.assertEquals("01234567890", msg.toString());
       
        httpClient.close();
        server.close();
    }
View Full Code Here

     
      WebContainer container = new WebContainer(new MyServlet());
      container.start();
     
   
    HttpClient httpClient = new HttpClient();

    String txt = "Test now return \n another at the end\n";
    PostRequest request = new PostRequest("http://localhost:" + container.getLocalPort() + "/");
    request.setParameter("\r\ntest ", txt);
    IHttpResponse response = httpClient.call(request);

    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals(txt, response.getBody().readString());
   
    httpClient.close();
    container.stop();
  }
View Full Code Here

       
        WebContainer container = new WebContainer(new MyServlet());
        container.start();
       
       
        HttpClient httpClient = new HttpClient();

        String txt = "Test now return \n another at the end\n";
        IHttpRequest request = new FormURLEncodedRequest("http://localhost:" + container.getLocalPort() + "/");
        request.setParameter("\r\ntest ", txt);
        IHttpResponse response = httpClient.call(request);

        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals(txt, response.getBody().readString());
       
        httpClient.close();
        container.stop();
    }
View Full Code Here

       
       
        HttpServer server = new HttpServer(reqHdl);
        server.start();
       
        HttpClient httpClient = new HttpClient();
        httpClient.setCacheMaxSizeKB(100);
       
        IHttpRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/");
        request.setHeader("If-None-Match", "\"23\"");
        IHttpResponse resp = httpClient.call(request);
        Assert.assertEquals(304, resp.getStatus());
        Assert.assertNull(resp.getHeader(CacheHandler.XHEADER_NAME));
       
        QAUtil.sleep(1000);
       
        Assert.assertEquals(0, httpClient.getNumCacheHit());
        Assert.assertEquals(0, httpClient.getNumCacheMiss());
       
        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.