Package org.xlightweb.client

Examples of org.xlightweb.client.HttpClient


    };
    HttpServer server = new HttpServer(0, reqHdl, 0, 10);
    server.start();

   
    HttpClient httpClient = new HttpClient();

    for (int i = 0; i < 10; i++) {
        IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, response.getStatus());
       
        QAUtil.sleep(200);
      }
   
    Assert.assertEquals(1, ((WorkerPool) server.getWorkerpool()).getLargestPoolSize());
   
   
    httpClient.close();
        server.close();
    }
View Full Code Here


        };
        HttpServer server = new HttpServer(0, reqHdl, 3, 10);
        server.start();

       
        HttpClient httpClient = new HttpClient();

        for (int i = 0; i < 10; i++) {
            IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
            Assert.assertEquals(200, response.getStatus());
           
            QAUtil.sleep(200);
        }
       
        Assert.assertEquals(3, ((WorkerPool) server.getWorkerpool()).getLargestPoolSize());
       
       
        httpClient.close();
        server.close();
    }  
View Full Code Here

    public void testClientMultiFile() throws Exception {
       
        WebContainer server = new WebContainer(new TestServlet());
        server.start();
           
        HttpClient httpClient = new HttpClient();
       

        MultipartFormDataRequest req = new MultipartFormDataRequest("http://localhost:" + server.getLocalPort()+ "/");
       
        String name1 = "file4k";
        File file1 = QAUtil.createTestfile_4k();
        String name2 = "file40k";
        File file2 = QAUtil.createTestfile_40k();
       
        req.addPart(name1, file1);
        req.addPart(name2, file2);
           
        IHttpResponse resp = httpClient.call(req);
       
        String body = resp.getBody().toString();
        Assert.assertTrue(body.contains("name=file4k"));
        Assert.assertTrue(body.contains("name=file40k"));
       
        Assert.assertEquals(200, resp.getStatus());
       
       
        file1.delete();
        file2.delete();
        httpClient.close();
        server.stop();
    }   
View Full Code Here

    public void testClientMultiFile2() throws Exception {

        WebContainer server = new WebContainer(new TestServlet());
        server.start();
           
        HttpClient httpClient = new HttpClient();
       

        MultipartFormDataRequest req = new MultipartFormDataRequest("http://localhost:" + server.getLocalPort()+ "/");
       
        String name1 = "file4k";
        File file1 = File.createTempFile("test", "tmp");
        FileWriter fw = new FileWriter(file1);
        fw.write("0123456789");
        fw.close();
       
       
        String name2 = "file40k";
        File file2 = QAUtil.createTestfile_40k();
       
        req.addPart(name1, file1);
        req.addPart(name2, file2);
           
        IHttpResponse resp = httpClient.call(req);
       
        String body = resp.getBody().toString();
        Assert.assertTrue(body.contains("name=file4k"));
        Assert.assertTrue(body.contains("name=file40k"));
       
        Assert.assertEquals(200, resp.getStatus());
       
       
        file1.delete();
        file2.delete();
        httpClient.close();
        server.stop();
    }   
View Full Code Here

            }
        };
        Server server = new Server(hdl);
        server.start();

        HttpClient httpClient = new HttpClient();
       
        IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("iso-8859-1", response.getCharacterEncoding());
        Assert.assertFalse("Herzlichen Gl\u00FCckwunsch, Sie haben sich zur Reinigung des Aufzugs entschlossen.".equals(response.getBody().readString()));
       
        httpClient.close();
        server.close();
    }
View Full Code Here

            }
        };
        Server server = new Server(hdl);
        server.start();

        HttpClient httpClient = new HttpClient();
        httpClient.setResponseBodyDefaultEncoding("utf-8");
       
        IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("utf-8", response.getCharacterEncoding());
        Assert.assertEquals("Herzlichen Gl\u00FCckwunsch, Sie haben sich zur Reinigung des Aufzugs entschlossen.", response.getBody().readString());
       
        httpClient.close();
        server.close();
    }
View Full Code Here

            }
        };
        Server server = new Server(hdl);
        server.start();

        HttpClient httpClient = new HttpClient();
        httpClient.setResponseBodyDefaultEncoding("utf-8");
       
        IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("iso-8859-1", response.getCharacterEncoding());
        Assert.assertFalse("Herzlichen Gl\u00FCckwunsch, Sie haben sich zur Reinigung des Aufzugs entschlossen.".equals(response.getBody().readString()));
       
        httpClient.close();
        server.close();
    }     
View Full Code Here

    @Test
    public void testClientHandler() throws Exception {
        WebContainer webContainer = new WebContainer(new EchoWebSocketServlet());
        webContainer.start();
       
        HttpClient httpClient = new HttpClient();
       
       
        class MyWebSocketHandler implements IWebSocketHandler {
           
            public void onConnect(IWebSocketConnection con) throws IOException, UnsupportedProtocolException {
                String webSocketProtocol = con.getProtocol();
                IHttpRequestHeader header = con.getUpgradeRequestHeader();
            }
           
            public void onMessage(IWebSocketConnection con) throws IOException {
                WebSocketMessage msg = con.readMessage();
            }
           
            public void onDisconnect(IWebSocketConnection con) throws IOException {
               
            }
        }
       
        IWebSocketConnection webSocketConnection = httpClient.openWebSocketConnection("ws://localhost:" +  webContainer.getLocalPort(), new MyWebSocketHandler());

        webSocketConnection.writeMessage(new TextMessage("Hello jetty"));

       
        httpClient.close();
        webContainer.stop();
    }
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

        };
       
        IServer server = new Server(dh);
        server.start();
       
        HttpClient httpClient = new HttpClient();
       
        try {
            IWebSocketConnection ws = httpClient.openWebSocketConnection("ws://localhost:" + server.getLocalPort());

            ws.readMessage();
            Assert.fail("IOException expected");
        }catch (IOException expected) {  }
       
        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.