Package org.xsocket.connection

Examples of org.xsocket.connection.Server


                return true;
            }
        };
       
        IServer server = new Server(dh);
        server.start();

       
        HttpClient httpClient = new HttpClient();
        httpClient.setMaxRetries(0);
       
        GetRequest request = new GetRequest("http://localhost:" + server.getLocalPort() + "/test");
       
        try {
            IHttpResponse response = httpClient.call(request);
            Assert.fail("IOException expected");
        } catch (IOException expected) {  }
       
        httpClient.close();
        server.close();
    }
View Full Code Here


                return true;
            }
        };
       
        IServer server = new Server(dh);
        server.start();

       
        HttpClient httpClient = new HttpClient();
       
        DeleteRequest request = new DeleteRequest("http://localhost:" + server.getLocalPort() + "/test");
        IHttpResponse response = httpClient.call(request);
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("12345", response.getBlockingBody().readString());
       
        httpClient.close();
        server.close();
    }
View Full Code Here

                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

                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

    // start xSocket
    Context ctx = new Context("");
    ctx.addHandler("/site/*", new FileServiceRequestHandler(basePath, true));
    ctx.addHandler("/rpc/*", new MyBusinessHandler());
   
    Server server = new HttpServer(ctx);
    server.start();
   
   
    HttpClient httpClient = new HttpClient();
   
    IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/site/" + testFile.getName()));
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("application/octet-stream", response.getContentType());
    Assert.assertTrue(response.hasBody());
   
    response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/rpc/getCustomers"));
    Assert.assertEquals(200, response.getStatus());
    Assert.assertTrue(response.getContentType().startsWith("text/plain"));
    Assert.assertTrue(response.hasBody());
   
    httpClient.close();
    server.close();
   
   
    testFile.delete();
  }
View Full Code Here

    // start xSocket
    Context ctx = new Context("");
    ctx.addHandler("/site/*", new FileServiceRequestHandler(basePath, true));
    ctx.addHandler(new AnnotatedHandler());
   
    Server server = new HttpServer(ctx);
    server.start();
   
   
    HttpClient httpClient = new HttpClient();
   
    IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/site/" + testFile.getName()));
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("application/octet-stream", response.getContentType());
    Assert.assertTrue(response.hasBody());
   
    response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/rpc/getCustomers"));
    Assert.assertEquals(200, response.getStatus());
    Assert.assertTrue(response.getContentType().startsWith("text/plain"));
    Assert.assertTrue(response.hasBody());
   
    httpClient.close();
    server.close();
   
   
    testFile.delete();
  }
View Full Code Here

    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

    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

    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

    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

TOP

Related Classes of org.xsocket.connection.Server

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.