Examples of HttpServer


Examples of org.xlightweb.server.HttpServer

      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.xlightweb.server.HttpServer

    ctx.addHandler("/*", new GoodRequestHandler());
    Assert.assertEquals(2, ctx.size());
 

   
    Server server = new HttpServer(ctx);
    server.start();
   
   
    HttpClient httpClient = new HttpClient();
   
    IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/test"));
    Assert.assertEquals(200, response.getStatus());
   
    response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/badRequest"));
    Assert.assertEquals(400, response.getStatus());

    httpClient.close();
    server.close();
  }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

    jettyServer.start();
   
   
    Context ctx = new Context("/ctx1");
    ctx.addHandler("/test/*", new TestRequestHandler());
    HttpServer server = new HttpServer(ctx);
    server.start();
   
   
    HttpClient httpClient = new HttpClient();
   
    IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + jettyServer.getConnectors()[0].getLocalPort() + "/ctx1/test/you"));
    if (response.getStatus() != 200) {
      System.out.println("got " + response.getStatus() + " instead of 200");
      Assert.fail();
    }
   
    String body = response.getBlockingBody().readString();
    if (body.indexOf("contextPath=/ctx1") == -1) {
      System.out.println("contextPath=/ctx1 expected");
      Assert.fail();
    }
   
    if (body.indexOf("contextPath=/ctx1") == -1) {
      System.out.println("servletPath=/test expected");
      Assert.fail();
    }

   
    response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/ctx1/test/you"));
    if (response.getStatus() != 200) {
      System.out.println("got " + response.getStatus());
      Assert.fail();
    }
   
    body = response.getBlockingBody().readString();
    Assert.assertTrue(body.indexOf("contextPath=/ctx1") != -1);
    Assert.assertTrue(body.indexOf("servletPath=/test") != -1);

   
    httpClient.close();
    jettyServer.stop();
    server.close();
  }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

    OnMessageReceivedHandler hdl = new OnMessageReceivedHandler();

    // start xSocket
    Context ctx = new Context("");
    ctx.addHandler("/ctx1/*", hdl);
    Server server = new HttpServer(ctx);
    ConnectionUtils.start(server);
   
   

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

    con.write("POST /ctx1/test/test2 HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "Content-Length: 10\r\n" +
          "\r\n" +
          "12345");

   
    QAUtil.sleep(300);
    Assert.assertNull(hdl.getOnRequestThreadname());
   
    con.write("67890");
    QAUtil.sleep(200);
    Assert.assertNotNull(hdl.getOnRequestThreadname());
   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
     
    String body = con.readStringByLength(contentLength);
    Assert.assertEquals("OK", body);
   
    con.close();
    server.close();
  }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

    MultithreadedHandler hdl = new MultithreadedHandler();

    // start xSocket
    Context ctx = new Context("");
    ctx.addHandler("/ctx1/*", hdl);
    Server server = new HttpServer(ctx);
    ConnectionUtils.start(server);
   
   
    GetRequest req = new GetRequest("http://localhost:" + server.getLocalPort() + "/ctx1/test/test2");
    req.setHeader("Host", "localhost");
    req.setHeader("User-Agent", "me");
   
   
    IBlockingConnection con = new BlockingConnection("localhost", server.getLocalPort());

    con.write(req.toString());
   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
     
    String body = con.readStringByLength(contentLength);
    Assert.assertEquals("OK", body);
   
    System.out.println(hdl.getOnRequestThreadname());
    Assert.assertTrue(hdl.getOnRequestThreadname().startsWith("xServerPool"));

    con.close();
    server.close();
  }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

    OnMessageReceivedHandler hdl = new OnMessageReceivedHandler();

    // start xSocket
    Context ctx = new Context("");
    ctx.addHandler("/ctx1/*", hdl);
    Server server = new HttpServer(ctx);
    ConnectionUtils.start(server);
   
    QAUtil.sleep(200);
    Assert.assertEquals(1, hdl.getCountOnInitCalled());
    Assert.assertEquals(0, hdl.getCountOnDestroyCalled());
     
    server.close();
    QAUtil.sleep(200);
    Assert.assertEquals(1, hdl.getCountOnInitCalled());
    Assert.assertEquals(1, hdl.getCountOnDestroyCalled());

  }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

    NonthreadedHandler hdl = new NonthreadedHandler();

    // start xSocket
    Context ctx = new Context("");
    ctx.addHandler("/ctx1/*", hdl);
    Server server = new HttpServer(ctx);
    server.start();
   
   
    GetRequest req = new GetRequest("http://localhost:" + server.getLocalPort() + "/ctx1/test/test2");
    req.setHeader("Host", "localhost");
    req.setHeader("User-Agent", "me");

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

    con.write(req.toString());
   
    String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
    int contentLength = QAUtil.readContentLength(header);
     
    String body = con.readStringByLength(contentLength);
    Assert.assertEquals("OK", body);

    con.close();
    server.close();
  }
View Full Code Here

Examples of org.xlightweb.server.HttpServer


    // start xSocket
    Context ctx = new Context("");
    ctx.addHandler("/ctx1/*", new CompareParametersHandler());
    Server server = new HttpServer(ctx);
    ConnectionUtils.start(server);
   
   
   
    GetRequest reqXSocket = new GetRequest("http://localhost:" + server.getLocalPort() + "/ctx1/test/test2");
    reqXSocket.setHeader("Host", "localhost");
    reqXSocket.setHeader("User-Agent", "me");

    GetRequest reqJetty = new GetRequest("http://localhost:" + servletEngine.getLocalPort() + "/ctx1/test/test2");
    reqJetty.setHeader("Host", "localhost");
    reqJetty.setHeader("User-Agent", "me");

   
    IBlockingConnection conXSocket = new BlockingConnection("localhost", server.getLocalPort());
    IBlockingConnection conJetty = new BlockingConnection("localhost", servletEngine.getLocalPort());

    conXSocket.write(reqXSocket.toString());
   
    String header = conXSocket.readStringByDelimiter("\r\n\r\n");
    int contentLength = QAUtil.readContentLength(header);
     
    String bodyXSocket = conXSocket.readStringByLength(contentLength);
   
   
    conJetty.write(reqJetty.toString());
   
    String headerJetty = conJetty.readStringByDelimiter("\r\n\r\n");
    int contentLengthJetty = QAUtil.readContentLength(headerJetty);
     
    String bodyJetty = conJetty.readStringByLength(contentLengthJetty);
   
    Assert.assertEquals(bodyXSocket, bodyJetty);
   

    conXSocket.close();
    conJetty.close();
    servletEngine.stop();
    server.close();
  }
View Full Code Here

Examples of org.xlightweb.server.HttpServer


    // start xSocket
    Context ctx = new Context("/ctx0");
    ctx.addHandler("/ctx1/*", new CompareParametersHandler());
    Server server = new HttpServer(ctx);
    ConnectionUtils.start(server);
   
   
   
   
    GetRequest reqXSocket = new GetRequest("http://localhost:" + server.getLocalPort() + "/ctx0/ctx1/test/test2");
    reqXSocket.setHeader("Host", "localhost");
    reqXSocket.setHeader("User-Agent", "me");

   
    GetRequest reqJetty = new GetRequest("http://localhost:" + servletEngine.getLocalPort() + "/ctx0/ctx1/test/test2");
    reqJetty.setHeader("Host", "localhost");
    reqJetty.setHeader("User-Agent", "me");

   
    IBlockingConnection conXSocket = new BlockingConnection("localhost", server.getLocalPort());
    IBlockingConnection conJetty = new BlockingConnection("localhost", servletEngine.getLocalPort());

    conXSocket.write(reqXSocket.toString());
   
    String header = conXSocket.readStringByDelimiter("\r\n\r\n");
    int contentLength = QAUtil.readContentLength(header);
     
    String bodyXSocket = conXSocket.readStringByLength(contentLength);
   
   
    conJetty.write(reqJetty.toString());
   
    String headerJetty = conJetty.readStringByDelimiter("\r\n\r\n");
    int contentLengthJetty = QAUtil.readContentLength(headerJetty);
     
    String bodyJetty = conJetty.readStringByLength(contentLengthJetty);
   
    Assert.assertEquals(bodyXSocket, bodyJetty);

    conJetty.close();
    conXSocket.close();
    servletEngine.stop();
    server.close();
  }
View Full Code Here

Examples of org.xlightweb.server.HttpServer

    Context ctxSub = new Context(ctxRoot, "/ctx1");
   
    ctxRoot.addHandler("/ctx1/uuu/*", new DoNothingHandler());
   
    ctxSub.addHandler("/test/*", new CompareParametersHandler());
    Server server = new HttpServer(ctxRoot);
    ConnectionUtils.start(server);
   
   

    GetRequest reqXSocket = new GetRequest("http://localhost:" + server.getLocalPort() + "/ctx0/ctx1/test/test2");
    reqXSocket.setHeader("Host", "localhost");
    reqXSocket.setHeader("User-Agent", "me");

   
    GetRequest reqJetty = new GetRequest("http://localhost:" + jettyServer.getConnectors()[0].getLocalPort() + "/ctx0/ctx1/test/test2");
    reqJetty.setHeader("Host", "localhost");
    reqJetty.setHeader("User-Agent", "me");

   
    IBlockingConnection conXSocket = new BlockingConnection("localhost", server.getLocalPort());
    IBlockingConnection conJetty = new BlockingConnection("localhost", jettyServer.getConnectors()[0].getLocalPort());

    conXSocket.write(reqXSocket.toString());
   
    String header = conXSocket.readStringByDelimiter("\r\n\r\n");
    int contentLength = QAUtil.readContentLength(header);
     
    String bodyXSocket = conXSocket.readStringByLength(contentLength);
   
   
    conJetty.write(reqJetty.toString());
   
    String headerJetty = conJetty.readStringByDelimiter("\r\n\r\n");
    int contentLengthJetty = QAUtil.readContentLength(headerJetty);
     
    String bodyJetty = conJetty.readStringByLength(contentLengthJetty);
   
    Assert.assertEquals(bodyXSocket, bodyJetty);

    conJetty.close();
    conXSocket.close();
   
    jettyServer.stop();
    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.