Package org.xlightweb.server

Examples of org.xlightweb.server.HttpServer


 
    RequestHandlerChain root = new RequestHandlerChain();
    DoNothingFilter doNothingFilter = new DoNothingFilter();
    root.addLast(doNothingFilter);
   
    IServer server = new HttpServer(root);
    ConnectionUtils.start(server);
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
 
    con.write("POST /test/path?param1=value1 HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "Content-Length: 4\r\n" +
View Full Code Here


  @Test
  public void testSSLHttpClient() throws Exception {
 
    System.out.println("testSSLHttpClient");
   
    HttpServer server = new HttpServer(0, new RequestHandler(), SSLTestContextFactory.getSSLContext(), true);
    server.start();

    HttpProxy2 proxy = new HttpProxy2(false);
    proxy.start();
   
   
    HttpClient httpClient = new HttpClient(SSLTestContextFactory.getSSLContext());
    httpClient.setProxySecuredHost("localhost");
    httpClient.setProxySecuredPort(proxy.getLocalPort());
    httpClient.setProxyUser("test");
    httpClient.setProxyPassword("test");

    IHttpResponse response = httpClient.call(new GetRequest("https://localhost:" + server.getLocalPort() + "/"));
   
    String body = response.getBlockingBody().readString();

    Assert.assertEquals(200, response.getStatus());
    Assert.assertTrue(body.indexOf("it works") != -1);
   
   
    httpClient.close();
    proxy.close();
    server.close();
 
View Full Code Here

    @Test
    public void testSSLHttpClient2() throws Exception {
   
        System.out.println("testSSLHttpClient");
       
        HttpServer server = new HttpServer(0, new RequestHandler(), SSLTestContextFactory.getSSLContext(), true);
        server.start();

        HttpProxy2 proxy = new HttpProxy2(false);
        proxy.start();
       
       
        HttpClient httpClient = new HttpClient(SSLTestContextFactory.getSSLContext());
        httpClient.setProxyHost("localhost");
        httpClient.setProxyPort(proxy.getLocalPort());
        httpClient.setProxyUser("test");
        httpClient.setProxyPassword("test");

        IHttpResponse response = httpClient.call(new GetRequest("https://localhost:" + server.getLocalPort() + "/"));
       
        String body = response.getBlockingBody().readString();

        Assert.assertEquals(200, response.getStatus());
        Assert.assertTrue(body.indexOf("it works") != -1);
       
       
        httpClient.close();
        proxy.close();
        server.close();
    }    
View Full Code Here

                    throw new IOException(e.toString());
                }
            }
        };
       
        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(301, 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(301, resp.getStatus());
        Assert.assertNotNull(resp.getHeader("Location"));
        Assert.assertTrue(resp.getHeader(CacheHandler.XHEADER_NAME).startsWith("HIT"));
       
       
        Assert.assertEquals(1, httpClient.getNumCacheHit());
        Assert.assertEquals(1, httpClient.getNumCacheMiss());
       
        httpClient.close();
        server.close();
  }  
View Full Code Here

                    throw new IOException(e.toString());
                }
            }
        };
       
        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(301, 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(301, 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

                    throw new IOException(e.toString());
                }
            }
        };
       
        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.assertTrue(resp.getHeader(CacheHandler.XHEADER_NAME).startsWith("HIT"));
       
       
        Assert.assertEquals(1, httpClient.getNumCacheHit());
        Assert.assertEquals(1, httpClient.getNumCacheMiss());
       
        httpClient.close();
        server.close();
    }
View Full Code Here

                exchange.send(resp);

            }
        };
       
        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

                    throw new IOException(e.toString());
                }
            }
        };
       
        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

                    throw new IOException(e.toString());
                }
            }
        };
       
        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 testServerMixedHandler() throws Exception {
        HttpServer server = new HttpServer(new MixedRequestHandler());
        server.start();

        BlockingConnection bc = new BlockingConnection("localhost", server.getLocalPort());

        bc.write("GET / HTTP/1.1\r\n"+
                 "Host: localhost:" + server.getLocalPort() + "\r\n"+
                 "User-Agent: xLightweb/2.11\r\n"+
                 "Upgrade: WebSocket\r\n"+
                 "Connection: Upgrade\r\n"+
                 "Origin: http://localhost:5161/\r\n"+
                 "\r\n");

        bc.readStringByDelimiter("\r\n\r\n");

       
        byte[] msg1 = bc.readBytesByLength(11);
        Assert.assertArrayEquals(new byte[] { 0x00, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x79, 0x6f, 0x75, (byte) 0xFF}, msg1);

    

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

TOP

Related Classes of org.xlightweb.server.HttpServer

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.