Examples of IHttpServer


Examples of org.xlightweb.server.IHttpServer

    chain.addLast(h1);
   
    RequestHandler h2 = new RequestHandler("/bs");
    chain.addLast(h2);

    IHttpServer server = new HttpServer(chain);
    server.start();
   
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
   
    con.write("GET /test HTTP/1.1\r\n" +
              "Host: localhost:" + server.getLocalPort() + "\r\n" +
              "User-Agent: me\r\n\r\n");
   
    String header = con.readStringByDelimiter("\r\n\r\n");
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertFalse(h1.isForwardedRef.get());
   
    h1.reset();
    h2.reset();
    con.close();
   
    con = new BlockingConnection("localhost", server.getLocalPort());
    con.write("GET /bs HTTP/1.1\r\n" +
                "Host: localhost:" + server.getLocalPort() + "\r\n" +
                "User-Agent: me\r\n\r\n");
     
    header = con.readStringByDelimiter("\r\n\r\n");
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertTrue(h1.isForwardedRef.get());
      Assert.assertFalse(h2.isForwardedRef.get());
     
        con.close();
    con.close();
    server.close();
  }
View Full Code Here

Examples of org.xlightweb.server.IHttpServer

        chain.addLast(h1);
       
        RequestHandler h2 = new RequestHandler("/bs");
        chain.addLast(h2);

        IHttpServer server = new HttpServer(chain);
        server.start();
       
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
       
       
        con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("GET /bs HTTP/1.1\r\n" +
                "Host: localhost:" + server.getLocalPort() + "\r\n" +
                "User-Agent: me\r\n\r\n");
     
        String header = con.readStringByDelimiter("\r\n\r\n");
        Assert.assertTrue(header.indexOf("200") != -1);
        Assert.assertTrue(h1.isForwardedRef.get());
        Assert.assertFalse(h2.isForwardedRef.get());
       
        h1.reset();
        h2.reset();
       
        con.close();
        server.close();  
    }
View Full Code Here

Examples of org.xlightweb.server.IHttpServer

        chain.addLast(h1);
       
        RequestHandler h2 = new RequestHandler("/bs");
        chain.addLast(h2);

        IHttpServer server = new HttpServer(chain);
        server.start();
       
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
       
        con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("GET /tztz HTTP/1.1\r\n" +
                "Host: localhost:" + server.getLocalPort() + "\r\n" +
                "User-Agent: me\r\n\r\n");
     
        String header = con.readStringByDelimiter("\r\n\r\n");
        Assert.assertTrue(header.indexOf("404") != -1);
        Assert.assertTrue(h1.isForwardedRef.get());
        Assert.assertTrue(h2.isForwardedRef.get());
       
        con.close();
        server.close();
    }
View Full Code Here

Examples of org.xlightweb.server.IHttpServer

                dataSink.close();
            }
        };
        chain.addLast(rh);
       
        IHttpServer server = new HttpServer(chain);
        server.start();
       
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
       
        con.write("GET /test HTTP/1.1\r\n" +
                  "Host: localhost:" + server.getLocalPort() + "\r\n" +
                  "User-Agent: me\r\n\r\n");
       
        String header = con.readStringByDelimiter("\r\n\r\n");
        Assert.assertTrue(header.indexOf("200") != -1);
       
        con.close();
        server.close();
    }
View Full Code Here

Examples of org.xlightweb.server.IHttpServer

            }
        };
        chain.addLast(rh2);

       
        IHttpServer server = new HttpServer(chain);
        server.start();
       
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
       
        con.write("POST /test HTTP/1.1\r\n" +
                  "Host: localhost:" + server.getLocalPort() + "\r\n" +
                  "User-Agent: me\r\n" +
                  "Content-Length: 5\r\n" +
                  "\r\n" +
                  "12345");
       
        String header = con.readStringByDelimiter("\r\n\r\n");
        Assert.assertTrue(header.indexOf("200") != -1);
       
        QAUtil.sleep(1000);
        Assert.assertEquals("addedLine\r\n12345", con.readStringByLength(16));
       
        con.close();
        server.close();
    }
View Full Code Here

Examples of org.xlightweb.server.IHttpServer

                BodyDataSink ds = exchange.send(new HttpResponseHeader(200, "text/plain"));
                ds.write("0123456789");
                ds.destroy();
            }
        };
        IHttpServer server = new HttpServer(hdl);
        server.start();
       
       
        HttpClient httpClient = new HttpClient();
        IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
        Assert.assertEquals(200, response.getStatus());
       
       
        DestroyListener ds = new DestroyListener();
        response.getNonBlockingBody().addDestroyListener(ds);
       
       
        while (!ds.isDestroyed()) {
            QAUtil.sleep(100);
        }
       
       
        httpClient.close();
        server.close();
  }
View Full Code Here

Examples of org.xlightweb.server.IHttpServer

    @Test
    public void testNonThreaded() throws Exception {

        NonThreadedRequestHandler requestHdl = new NonThreadedRequestHandler();
        IHttpServer server = new HttpServer(requestHdl);
        server.start();
     
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("GET /test HTTP/1.1\r\n" +
                  "User-Agent: me\r\n" +
                  "Host: localhost:" + server.getLocalPort() + "\r\n\r\n");
       
        String header = con.readStringByDelimiter("\r\n\r\n");
        Assert.assertTrue(header.indexOf("200") != -1);
       
        Assert.assertFalse(requestHdl.threadnameRef.get().startsWith("xWorker"));
               
        con.close();
        server.close();
    }   
View Full Code Here

Examples of org.xlightweb.server.IHttpServer

   
    @Test
    public void testMultiThreaded() throws Exception {

        MultiThreadedRequestHandler requestHdl = new MultiThreadedRequestHandler();
        IHttpServer server = new HttpServer(requestHdl);
        server.start();
     
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("GET /test HTTP/1.1\r\n" +
                  "User-Agent: me\r\n" +
                  "Host: localhost:" + server.getLocalPort() + "\r\n\r\n");
       
        String header = con.readStringByDelimiter("\r\n\r\n");
        Assert.assertTrue(header.indexOf("200") != -1);
             
        Assert.assertTrue(requestHdl.threadnameRef.get().startsWith("xWorker"));
       
        con.close();
        server.close();
    }   
View Full Code Here

Examples of org.xlightweb.server.IHttpServer

   

    @Test
    public void testPiplining() throws Exception {

        IHttpServer server = new HttpServer(new SlowRequestHandler());
        server.start();

        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
       
        int sleepTime = 1000;
        for (int i = 0; i < 10; i++) {
            con.write("GET /test?num=" + i + "&wait=" + sleepTime + " HTTP/1.1\r\n" +
                      "User-Agent: me\r\n" +
                      "Host: localhost:" + server.getLocalPort() + "\r\n\r\n");
           
            sleepTime = sleepTime / 2;
        }

       
        for (int i = 0; i < 10; i++) {
            String header = con.readStringByDelimiter("\r\n\r\n");
            Assert.assertTrue(header.indexOf("200") != -1);
            // content length is 1
            int num = Integer.parseInt(con.readStringByLength(1));
            Assert.assertEquals(i, num);
        }
       
        con.close();
        server.close();
    }   
View Full Code Here

Examples of org.xlightweb.server.IHttpServer

    chain.addLast(h1);
   
    RequestHandler h2 = new RequestHandler("/bs");
    chain.addLast(h2);

    IHttpServer server = new HttpServer(chain);
    server.start();
   
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
   
    con.write("GET /test HTTP/1.1\r\n" +
              "Host: localhost:" + server.getLocalPort() + "\r\n" +
              "User-Agent: me\r\n\r\n");
   
    String header = con.readStringByDelimiter("\r\n\r\n");
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertFalse(h1.isForwardedRef.get());
   
    h1.reset();
    h2.reset();
    con.close();
   
    con = new BlockingConnection("localhost", server.getLocalPort());
    con.write("GET /bs HTTP/1.1\r\n" +
                "Host: localhost:" + server.getLocalPort() + "\r\n" +
                "User-Agent: me\r\n\r\n");
     
    header = con.readStringByDelimiter("\r\n\r\n");
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertTrue(h1.isForwardedRef.get());
      Assert.assertFalse(h2.isForwardedRef.get());
     
        con.close();
    con.close();
    server.close();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.