Examples of IServer


Examples of org.xsocket.connection.IServer

                return true;
            }
        };
       
        IServer server = new Server(dh);
        server.start();
       
        HttpClient httpClient = new HttpClient();
       
        PutRequest request = new PutRequest("http://localhost:" + server.getLocalPort() + "/test", "text/plain", "12345");
        IHttpResponse response = httpClient.call(request);
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("12345", response.getBlockingBody().readString());
       
        httpClient.close();
        server.close();
    }
View Full Code Here

Examples of org.xsocket.connection.IServer

                return true;
            }
        };
       
        IServer server = new Server(dh);
        server.start();
       
        HttpClient httpClient = new HttpClient();
       
        PutRequest request = new PutRequest("http://localhost:" + server.getLocalPort() + "/test", "text/plain", "12345");
        IHttpResponse response = httpClient.call(request);
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("12345", response.getBlockingBody().readString());
       
        httpClient.close();
        server.close();
    }   
View Full Code Here

Examples of org.xsocket.connection.IServer

      Context rootCtx = new Context("");
      rootCtx.addHandler(new PersonRequestHandler());
      rootCtx.addHandler(new AccountRequestHandler());

      IServer server = new HttpServer(port, rootCtx);
      server.start();

      HttpClient httpClient = new HttpClient()
     
      IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/Person/1"));
      Assert.assertEquals(200, response.getStatus());
      Assert.assertEquals("person", response.getBlockingBody().readString());
     
      response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/Account/1"));
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("account", response.getBlockingBody().readString());
     
      httpClient.close();
      server.close();
    }
View Full Code Here

Examples of org.xsocket.connection.IServer

    root.addLast(h1);
   
    RequestHandler h2 = new RequestHandler();
    root.addLast(h2);
   
    IServer server = new HttpServer(root);
    ConnectionUtils.start(server);
   
    Assert.assertEquals(1, h1.getCountOnInitCalled());
    Assert.assertEquals(1, h2.getCountOnInitCalled());
   
    server.close();
   
    Assert.assertEquals(1, h1.getCountOnDestroyCalled());
    Assert.assertEquals(1, h2.getCountOnDestroyCalled());
  }
View Full Code Here

Examples of org.xsocket.connection.IServer

    root.addLast(h1);
   
    RequestHandler h2 = new RequestHandler();
    root.addLast(h2);
   
    IServer server = new HttpServer(root);
    server.start();
   
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());

    con.write("GET / HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "\r\n");
     
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
     
    con.readByteBufferByLength(contentLength);

   
    QAUtil.sleep(400);
   
    if (h1.countOnRequestCalled() != 1) {
      String msg = "RequestFilter should haven been called once not " + h1.countOnRequestCalled();
      System.out.println(msg);
      Assert.fail(msg)
    }
   
   
    if (h2.countOnRequestCalled() != 1) {
      String msg = "RequestHandler should haven been called once not " + h2.countOnRequestCalled();
      System.out.println(msg);
      Assert.fail(msg)
    }

   
    if (!h2.getOnRequestThreadname().startsWith("xServerPool")) {
      String msg = "RequestHandler should be executed by xServerPool not by " + h2.getOnRequestThreadname();
      System.out.println(msg);
      Assert.fail(msg);
    }
   
    con.close();
    server.close();
  }
View Full Code Here

Examples of org.xsocket.connection.IServer

    root.addLast(h1);
   
    NonThreadedRequestHandler h2 = new NonThreadedRequestHandler();
    root.addLast(h2);
   
    IServer server = new HttpServer(root);
    server.start();
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());

    con.write("GET / HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "\r\n");
     
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
     
    con.readByteBufferByLength(contentLength);
   
   
    QAUtil.sleep(200);
   
    Assert.assertEquals(1, h1.countOnRequestCalled());
    Assert.assertFalse(h1.onRequestThreadname.startsWith("xServerPool"));
    Assert.assertEquals(1, h2.countOnRequestCalled());
    Assert.assertFalse(h2.onRequestThreadname.startsWith("xServerPool"));
   
    con.close();
    server.close();
  }
View Full Code Here

Examples of org.xsocket.connection.IServer

    root.addLast(h1);
   
    MessageRequestHandler h2 = new MessageRequestHandler();
    root.addLast(h2);
   
    IServer server = new HttpServer(root);
    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" +
          "Content-Length: 4\r\n" +
          "\r\n");
     
   
    QAUtil.sleep(500);

    Assert.assertEquals(0, h1.countOnRequestCalled());
    Assert.assertEquals(0, h2.countOnRequestCalled());

    con.write("1234");

    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
     
    con.readByteBufferByLength(contentLength);
   

   
    QAUtil.sleep(200);
   
    Assert.assertEquals(1, h1.countOnRequestCalled());
    Assert.assertTrue(h1.getOnRequestThreadname().startsWith("xServerPool"));
    Assert.assertEquals(1, h2.countOnRequestCalled());
    Assert.assertTrue(h2.getOnRequestThreadname().startsWith("xServerPool"));
   
    con.close();
    server.close();
  }
View Full Code Here

Examples of org.xsocket.connection.IServer

    c1.addLast(h1);
   
    RequestHandler h2 = new RequestHandler();
    c1.addLast(h2);
   
    IServer server = new HttpServer(root);
    ConnectionUtils.start(server);
   
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());

    con.write("GET / HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "\r\n");
     
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
     
    con.readByteBufferByLength(contentLength);

   
    QAUtil.sleep(400);
   
    if (h1.countOnRequestCalled() != 1) {
      String msg = "RequestFilter should haven been called once not " + h1.countOnRequestCalled();
      System.out.println(msg);
      Assert.fail(msg)
    }
   
   
    if (h2.countOnRequestCalled() != 1) {
      String msg = "RequestHandler should haven been called once not " + h2.countOnRequestCalled();
      System.out.println(msg);
      Assert.fail(msg)
    }

   
    if (!h2.getOnRequestThreadname().startsWith("xServerPool")) {
      String msg = "RequestHandler should be executed by xServerPool not by " + h2.getOnRequestThreadname();
      System.out.println(msg);
      Assert.fail(msg);
    }
   
    con.close();
    server.close();
  }
View Full Code Here

Examples of org.xsocket.connection.IServer

   
   
    RequestHandler h2 = new RequestHandler();
    c1.addLast(h2);
   
    IServer server = new HttpServer(root);
    ConnectionUtils.start(server);
   
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());

    con.write("GET / HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "\r\n");
     
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
     
    con.readByteBufferByLength(contentLength);

   
    QAUtil.sleep(400);
   
    if (h1.countOnRequestCalled() != 1) {
      String msg = "RequestFilter should haven been called once not " + h1.countOnRequestCalled();
      System.out.println(msg);
      Assert.fail(msg)
    }
   
   
    if (h2.countOnRequestCalled() != 1) {
      String msg = "RequestHandler should haven been called once not " + h2.countOnRequestCalled();
      System.out.println(msg);
      Assert.fail(msg)
    }

   
    if (!h2.getOnRequestThreadname().startsWith("xServerPool")) {
      String msg = "RequestHandler should be executed by xServerPool not by " + h2.getOnRequestThreadname();
      System.out.println(msg);
      Assert.fail(msg);
    }
   
    con.close();
    server.close();
  }
View Full Code Here

Examples of org.xsocket.connection.IServer

    RequestHandlerChain chain = new RequestHandlerChain();
    chain.addLast(new RequestFilter());
    chain.addLast(new BlockingReadHandler());
   
   
    final IServer server = new HttpServer(chain);
    ConnectionUtils.start(server);

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

    con.write("POST / HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "Content-Length: 4\r\n" +
          "\r\n");
     
    con.write("12");

    QAUtil.sleep(400);
    con.write("34");
   
    QAUtil.sleep(500);
   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
   
    String body = con.readStringByLength(contentLength);
    Assert.assertTrue(header.indexOf("200") != -1);
    Assert.assertEquals("1234", body);
   


    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.