Package org.xlightweb.server

Examples of org.xlightweb.server.HttpServer


   
    @BeforeClass
    public static void setUp() throws Exception {
        IHttpRequestHandler hdl = new RequestHandler();
       
        proxyServer = new HttpServer(0, hdl);
        proxyServer.start();
       
        proxySslServer = new HttpServer(0, hdl, SSLTestContextFactory.getSSLContext(), true);
        proxySslServer.start();
       
       
        IHttpRequestHandler busiHdl = new BusinessRequestHandler();
        server = new HttpServer(0, busiHdl);
        server.start();
       
        sslServer = new HttpServer(0, busiHdl, SSLTestContextFactory.getSSLContext(), true);
        sslServer.start();

    }
View Full Code Here


  @Test
  public void testSimple() throws Exception {
     

      RequestHandler reqHdl = new RequestHandler();
      HttpServer server = new HttpServer(reqHdl);
      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

    public void testMessageOrientedInterceptor() throws Exception {

        RequestHandlerChain chain = new RequestHandlerChain();
        chain.addLast(new MessageorientedInterceptor());
        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("true", response.getHeader("X-Intercepted"));
        Assert.assertEquals(100, response.getBlockingBody().readBytes().length);
       
        httpClient.close();
        server.close();
    }
View Full Code Here

    public void testByteOrientedInterceptor() throws Exception {

        RequestHandlerChain chain = new RequestHandlerChain();
        chain.addLast(new ByteorientedForwardInterceptor());
        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

    public void testNonThreadedByteOrientedInterceptor() throws Exception {

        RequestHandlerChain chain = new RequestHandlerChain();
        chain.addLast(new NonTheadedByteorientedForwardInterceptor());
        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

    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

    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


    @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

   

  @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

 

    @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

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.