Examples of HttpServer


Examples of org.xlightweb.server.HttpServer

    public void testByteOrientedReverseInterceptor() throws Exception {
       
        RequestHandlerChain chain = new RequestHandlerChain();
        chain.addLast(new ByteorientedReverseInterceptor());
        chain.addLast(new RequestHandler());
        HttpServer server = new HttpServer(chain);
        server.start();
       
       
        HttpClient httpClient = new HttpClient();
       
        FutureResponseHandler hdl = new FutureResponseHandler();
        BodyDataSink ds = httpClient.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/test"), 100, hdl);
        for (int i = 0; i < 10; i++) {
            ds.write("0123456789");
        }
        ds.close();
       
       
        IHttpResponse response = hdl.get();
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals(100, response.getBlockingBody().readBytes().length);
       
        httpClient.close();
        server.close();
    }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

    public void testNonThreadedByteOrientedReverseInterceptor() throws Exception {
       
        RequestHandlerChain chain = new RequestHandlerChain();
        chain.addLast(new NonThreadedByteorientedReverseInterceptor());
        chain.addLast(new RequestHandler());
        HttpServer server = new HttpServer(chain);
        server.start();
       
       
        HttpClient httpClient = new HttpClient();
       
        FutureResponseHandler hdl = new FutureResponseHandler();
        BodyDataSink ds = httpClient.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/test"), 100, hdl);
        for (int i = 0; i < 10; i++) {
            ds.write("0123456789");
        }
        ds.close();
       
       
        IHttpResponse response = hdl.get();
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals(100, response.getBlockingBody().readBytes().length);
       
        httpClient.close();
        server.close();
    }   
View Full Code Here

Examples of org.xlightweb.server.HttpServer


    @Test
    public void testCon() throws Exception {
       
        HttpServer server = new HttpServer(new RequestHandler());
        server.start();
       
        HttpClientConnection con = new HttpClientConnection("localhost", server.getLocalPort());

        FutureResponseHandler hdl = new FutureResponseHandler();
        BodyDataSink ds = con.send(new HttpRequestHeader("POST", "http://localhost:"  +server.getLocalPort() + "/", "text/plain"), 200, hdl);
        for (int i = 0; i < 20; i++) {
            ds.write("0123456789");
            QAUtil.sleep(50);
        }
        ds.close();
           
        IHttpResponse response = hdl.get();
        Assert.assertEquals(200, response.getStatus());
       
        con.close();
        server.close();
    }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

   

  @Test
  public void testSimple() throws Exception {
     
      HttpServer server = new HttpServer(new RequestHandler());
      server.start();
     
    HttpClient httpClient = new HttpClient();

    FutureResponseHandler hdl = new FutureResponseHandler();
    BodyDataSink ds = httpClient.send(new HttpRequestHeader("POST", "http://localhost:"  +server.getLocalPort() + "/", "text/plain"), 200, hdl);
    for (int i = 0; i < 20; i++) {
        ds.write("0123456789");
        QAUtil.sleep(50);
    }
    ds.close();
       
    IHttpResponse response = hdl.get();
    Assert.assertEquals(200, response.getStatus());
   
    httpClient.close();
    server.close();
  }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

 

    @Test
    public void testCompletionHandler() throws Exception {
       
        HttpServer server = new HttpServer(new RequestHandler());
        server.start();
       
        HttpClient httpClient = new HttpClient();

        FutureResponseHandler hdl = new FutureResponseHandler();
        BodyDataSink ds = httpClient.send(new HttpRequestHeader("POST", "http://localhost:"  +server.getLocalPort() + "/", "text/plain"), 200, hdl);
      
       
        try {
            for (int i = 0; i < 20; i++) {
               
                IWriteCompletionHandler ch = new IWriteCompletionHandler() {
                    public void onWritten(int written) throws IOException {
                        System.out.println("written " + written);
                    }
                   
                    public void onException(IOException ioe) {
                        ioe.printStackTrace();
                    }
                };
               
                ds.write(new ByteBuffer[] { DataConverter.toByteBuffer("0123456789", "UTF-8") }, ch);
                QAUtil.sleep(50);
            }
            ds.close();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
           
        IHttpResponse response = hdl.get();
        Assert.assertEquals(200, response.getStatus());
       
        httpClient.close();
        server.close();
   
View Full Code Here

Examples of org.xlightweb.server.HttpServer

  
 
  @Test
  public void testAutoContinue() throws Exception {

    HttpServer server = new HttpServer(new ItWorksHandler());
    server.start();
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
    con.write("POST / HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "Expect: 100-Continue\r\n" +
          "Content-Length: 2000\r\n" +
          "\r\n");
   
   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    Assert.assertTrue(header.indexOf("100") != -1);
   
   
    con.write(QAUtil.generateByteArray(2000));
   
    header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    Assert.assertTrue(header.indexOf("200") != -1);
   
   
   
    con.close();
    server.close();
  }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

 
    @Test
    public void testManualContinue() throws Exception {

        ContinueHandler hdl = new ContinueHandler();
        HttpServer server = new HttpServer(hdl);
        server.start();
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("POST / HTTP/1.1\r\n" +
                  "Host: localhost\r\n" +
                  "User-Agent: me\r\n" +
                  "Expect: 100-Continue\r\n" +
                  "Content-Length: 2000\r\n" +
                  "\r\n");
       
       
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);
       
        QAUtil.sleep(300);
       
        Assert.assertTrue(hdl.is100ContinueSent());
       
        con.write(QAUtil.generateByteArray(2000));

        header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("200") != -1);
        int length = QAUtil.readContentLength(header);
        String txt = con.readStringByLength(length);
        Assert.assertEquals("OK", txt);
       
       
       
        con.close();
        server.close();
    }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

    @Test
    public void testManualContinue2() throws Exception {

        ContinueHandler2 hdl = new ContinueHandler2();
        HttpServer server = new HttpServer(hdl);
        server.start();
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("POST / HTTP/1.1\r\n" +
                  "Host: localhost\r\n" +
                  "User-Agent: me\r\n" +
                  "Expect: 100-Continue\r\n" +
                  "Content-Length: 2000\r\n" +
                  "\r\n");
       
       
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);
        QAUtil.sleep(300);
       
        Assert.assertTrue(hdl.is100ContinueSent());
       
        con.write(QAUtil.generateByteArray(2000));

        header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("200") != -1);
        int length = QAUtil.readContentLength(header);
        String txt = con.readStringByLength(length);
        Assert.assertEquals("OK", txt);
       
       
       
        con.close();
        server.close();
    }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

               
                exchange.send(new HttpResponse(200, "text/plain", "OK"));
            }
        };

        HttpServer server = new HttpServer(hdl);
        server.start();
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("POST / HTTP/1.1\r\n" +
                  "Host: localhost\r\n" +
                  "User-Agent: me\r\n" +
                  "Expect: 100-Continue\r\n" +
                  "Content-Length: 2000\r\n" +
                  "\r\n");
       
       
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);
       
        QAUtil.sleep(300);
       
        con.write(QAUtil.generateByteArray(2000));

        header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("200") != -1);
        int length = QAUtil.readContentLength(header);
        String txt = con.readStringByLength(length);
        Assert.assertEquals("OK", txt);
       
       
       
        con.close();
        server.close();
    }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

                exchange.send(new HttpResponse(200, "text/plain", "OK"));
            }
        };
       
       
        HttpServer server = new HttpServer(hdl);
        server.start();
       
        IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
        con.write("POST / HTTP/1.1\r\n" +
                  "Host: localhost\r\n" +
                  "User-Agent: me\r\n" +
                  "Expect: 100-Continue\r\n" +
                  "Content-Length: 2000\r\n" +
                  "\r\n");
       
       
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);
       
        QAUtil.sleep(300);
       
        con.write(QAUtil.generateByteArray(2000));

        header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("200") != -1);
        int length = QAUtil.readContentLength(header);
        String txt = con.readStringByLength(length);
        Assert.assertEquals("OK", txt);
       
       
       
        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.