Package org.xlightweb

Examples of org.xlightweb.RequestHandlerChain


 

  @Test
  public void testReadingBlockingBodyWithinServerHandler() throws Exception {
   
    RequestHandlerChain chain = new RequestHandlerChain();
    chain.addLast(new RequestFilter());
    chain.addLast(new BlockingReadHandler());
   
   
    final IServer server = new HttpServer(chain);
    ConnectionUtils.start(server);
View Full Code Here


 
 
  @Test
  public void testEmptyChain() throws Exception {
 
    RequestHandlerChain root = new RequestHandlerChain();
   
    IServer server = new HttpServer(root);
    ConnectionUtils.start(server);
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());
View Full Code Here


  @Test
  public void testUnhandledRequest() throws Exception {
 
    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());
View Full Code Here

public final class RequestHandlerChainTest {

  @Test
  public void testFirstHandler() throws Exception {
     RequestHandlerChain chain = new RequestHandlerChain();
   
    RequestHandler h1 = new RequestHandler("/test");
    chain.addLast(h1);
   
    RequestHandler h2 = new RequestHandler("/bs");
    chain.addLast(h2);

    IHttpServer server = new HttpServer(chain);
    server.start();
   
   
View Full Code Here

  }

 
  @Test
  public void testSecondHandler() throws Exception {
        RequestHandlerChain chain = new RequestHandlerChain();
       
        RequestHandler h1 = new RequestHandler("/test");
        chain.addLast(h1);
       
        RequestHandler h2 = new RequestHandler("/bs");
        chain.addLast(h2);

        IHttpServer server = new HttpServer(chain);
        server.start();
       
       
View Full Code Here

 
 
    @Test
    public void testNoHandler() throws Exception {
        RequestHandlerChain chain = new RequestHandlerChain();
       
        RequestHandler h1 = new RequestHandler("/test");
        chain.addLast(h1);
       
        RequestHandler h2 = new RequestHandler("/bs");
        chain.addLast(h2);

        IHttpServer server = new HttpServer(chain);
        server.start();
       
       
View Full Code Here

 
 
  @Test
    public void testStreamedResponse() throws Exception {
     
        RequestHandlerChain chain = new RequestHandlerChain();

       
        IHttpRequestHandler rh = new IHttpRequestHandler() {
           
            public void onRequest(IHttpExchange exchange) throws IOException, BadMessageException {
                IHttpRequest request = exchange.getRequest();
               
                BodyDataSink dataSink = exchange.send(new HttpResponseHeader(200));
                dataSink.write("test");
               
                QAUtil.sleep(200);
                dataSink.write("1234");
                dataSink.close();
            }
        };
        chain.addLast(rh);
       
        IHttpServer server = new HttpServer(chain);
        server.start();
       
       
View Full Code Here

    
    @Test
    public void testStreamedForward() throws Exception {
        System.setProperty("org.xlightweb.showDetailedError", "true");
       
        RequestHandlerChain chain = new RequestHandlerChain();

       
        IHttpRequestHandler rh = new IHttpRequestHandler() {
           
            public void onRequest(IHttpExchange exchange) throws IOException, BadMessageException {
                IHttpRequest request = exchange.getRequest();
               
                BodyDataSink dataSink = exchange.forward(request.getRequestHeader());
                dataSink.write("addedLine\r\n");
                dataSink.write(request.getBlockingBody().readString());
                dataSink.close();
            }
        };
        chain.addLast(rh);
       
       
        IHttpRequestHandler rh2 = new IHttpRequestHandler() {
           
            public void onRequest(IHttpExchange exchange) throws IOException, BadMessageException {
                IHttpRequest request = exchange.getRequest();
                exchange.send(new HttpResponse(200, request.getBlockingBody().readString()));
            }
        };
        chain.addLast(rh2);

       
        IHttpServer server = new HttpServer(chain);
        server.start();
       
View Full Code Here

 
 
  @Test
  public void testReplaceRequest() throws Exception {
 
    RequestHandlerChain chain = new RequestHandlerChain();
   
    IHttpRequestHandler filter = new IHttpRequestHandler() {

      public void onRequest(final IHttpExchange exchange) throws IOException {

        PostRequest newRequest = new PostRequest(exchange.getRequest().getRequestUrl().toString(), "text/plain", "Hello");
       
        IHttpResponseHandler respHdl = new IHttpResponseHandler() {
       
          public void onResponse(IHttpResponse response) throws IOException {
            exchange.send(response);
          }
         
          public void onException(IOException ioe) {
           
          }
         
        };
       
       
        exchange.forward(newRequest, respHdl);
      }
    };
   
   
    chain.addLast(filter);
    chain.addLast(new EchoHandler());
   
    IServer server = new HttpServer(0, chain);
    ConnectionUtils.start(server);
   
   
View Full Code Here

  public void testReplaceStreamedRequest() throws Exception {
 
      System.setProperty("org.xlightweb.showDetailedError", "true");

     
    RequestHandlerChain chain = new RequestHandlerChain();
   
    IHttpRequestHandler filter = new IHttpRequestHandler() {

      public void onRequest(final IHttpExchange exchange) throws IOException {
       
        IHttpResponseHandler respHdl = new IHttpResponseHandler() {
       
          public void onResponse(IHttpResponse response) throws IOException {
            exchange.send(response);
          }
         
          public void onException(IOException ioe) {
           
          }
         
        };
       
       
       
        BodyDataSink bodyDataSink = exchange.forward(new HttpRequestHeader("POST", exchange.getRequest().getRequestUrl().toString()), respHdl);
        bodyDataSink.write("Hel");
        QAUtil.sleep(200);
       
        bodyDataSink.write("lo");
        bodyDataSink.close();
      }
    };
   
   
    chain.addLast(filter);
    chain.addLast(new EchoHandler());
   
    IServer server = new HttpServer(chain);
    server.start();
   
   
View Full Code Here

TOP

Related Classes of org.xlightweb.RequestHandlerChain

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.