Package org.xsocket.connection

Examples of org.xsocket.connection.Server


                     "12");
        connection.close();
        return true;
      }
    };
    IServer server = new Server(dh);
    server.start();
   
   
    NonBlockingConnectionPool pool = new NonBlockingConnectionPool();
   
    for (int i = 0; i < 5; i++) {
     
      INonBlockingConnection con = pool.getNonBlockingConnection("localhost", server.getLocalPort());
      HttpClientConnection httpCon = new HttpClientConnection(con);
     
      IHttpResponse response =  httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
      Assert.assertEquals(200, response.getStatus());
      Assert.assertEquals("12", response.getBody().readString());
    }
   
    QAUtil.sleep(1000);
    Assert.assertEquals(0, pool.getNumActive());
    Assert.assertEquals(5, pool.getNumDestroyed());
   
   
    INonBlockingConnection con = pool.getNonBlockingConnection("localhost", server.getLocalPort());
    HttpClientConnection httpCon = new HttpClientConnection(con);
    IHttpResponse response =  httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
   
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("12", response.getBody().readString());
    httpCon.close();
   
    QAUtil.sleep(1000);
    con = pool.getNonBlockingConnection("localhost", server.getLocalPort());
    httpCon = new HttpClientConnection(con);
    response =  httpCon.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
   
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("12", response.getBody().readString());
    httpCon.close();

    QAUtil.sleep(1000);
    Assert.assertEquals(0, pool.getNumActive());
    Assert.assertEquals(7, pool.getNumDestroyed());
   
    pool.destroy();
    server.close();
  }
View Full Code Here


                          "\r\n");
                con.write(data);
                return true;
            }
        };
        Server server = new Server(hdl);
        server.start();

        HttpClient httpClient = new HttpClient();
       
        IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("iso-8859-1", response.getCharacterEncoding());
        Assert.assertFalse("Herzlichen Gl\u00FCckwunsch, Sie haben sich zur Reinigung des Aufzugs entschlossen.".equals(response.getBody().readString()));
       
        httpClient.close();
        server.close();
    }
View Full Code Here

                          "\r\n");
                con.write(data);
                return true;
            }
        };
        Server server = new Server(hdl);
        server.start();

        HttpClient httpClient = new HttpClient();
        httpClient.setResponseBodyDefaultEncoding("utf-8");
       
        IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("utf-8", response.getCharacterEncoding());
        Assert.assertEquals("Herzlichen Gl\u00FCckwunsch, Sie haben sich zur Reinigung des Aufzugs entschlossen.", response.getBody().readString());
       
        httpClient.close();
        server.close();
    }
View Full Code Here

                          "\r\n");
                con.write(data);
                return true;
            }
        };
        Server server = new Server(hdl);
        server.start();

        HttpClient httpClient = new HttpClient();
        httpClient.setResponseBodyDefaultEncoding("utf-8");
       
        IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort()+ "/"));
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("iso-8859-1", response.getCharacterEncoding());
        Assert.assertFalse("Herzlichen Gl\u00FCckwunsch, Sie haben sich zur Reinigung des Aufzugs entschlossen.".equals(response.getBody().readString()));
       
        httpClient.close();
        server.close();
    }     
View Full Code Here

                connection.close();
                return true;
            }
        };
       
        IServer server = new Server(dh);
        server.start();
       
        HttpClient httpClient = new HttpClient();
       
        try {
            IWebSocketConnection ws = httpClient.openWebSocketConnection("ws://localhost:" + server.getLocalPort());

            ws.readMessage();
            Assert.fail("IOException expected");
        }catch (IOException expected) {  }
       
        httpClient.close();
        server.close();
    }
View Full Code Here

 
  @Test
  public void testCallTimeout() throws Exception {
      System.out.println("testCallTimeout");
     
    IServer server = new Server(new DevNullHandler());
    server.start();

    HttpClient httpClient = new HttpClient();
    httpClient.setResponseTimeoutMillis(1000);

    try {
      httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/"));
      Assert.fail("timeout exepction shoud haven been thrown");
    } catch (SocketTimeoutException expeceted) { }

    QAUtil.sleep(100);

    Assert.assertEquals(1, httpClient.getNumCreated());
    Assert.assertEquals(1, httpClient.getNumDestroyed());
    Assert.assertEquals(0, httpClient.getIdleConnectionInfos().size());

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

               
                return true;
            }
        };
       
        Server server3 = new Server(dh);
        server3.start();
       
        System.out.println("testManualConnectionContinueHeaderUnexpectedResponse server: " + server3.getLocalPort());

       
        HttpClientConnection con = new HttpClientConnection("localhost", server3.getLocalPort());
        System.out.println("conn connected to " + con.getRemotePort());
       
        HttpRequestHeader requestHeader = new HttpRequestHeader("POST", "http://localhost:" + server3.getLocalPort() + "/test", "text/plain; charset=iso-8859-1");
       
        String data = "test1234567890";
        FutureResponseHandler respHdl = new FutureResponseHandler();
        BodyDataSink dataSink = con.send(requestHeader, data.length(), respHdl);
        dataSink.write("test1234567890");
       
        IHttpResponse response = respHdl.getResponse();
       
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals(data, response.getBlockingBody().readString());
       
       
        con.close();
        server3.close();
    }
View Full Code Here

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

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

                               "\r\n" +
                               "12345");
              return false;
          }
      };
      IServer server = new Server(dh);
      server.start();
     
     
    HttpClient httpClient = new HttpClient();
   
    ResponseHandler rh = new ResponseHandler();
    httpClient.send(new GetRequest("http://localhost:" + server.getLocalPort() + "/"), rh);
   
    QAUtil.sleep(1000);
   
    Assert.assertTrue(rh.threadnameRef.get().indexOf("ool-") != -1);
    Assert.assertNotNull(rh.responseRef.get());
View Full Code Here

                                 "Conte");
                connection.close();
                return false;
            }
        };
        IServer server = new Server(dh);
        server.start();
       
       
        HttpClient httpClient = new HttpClient();
       
        ResponseHandler rh = new ResponseHandler();
        httpClient.send(new GetRequest("http://localhost:" + server.getLocalPort() + "/"), rh);
       
        QAUtil.sleep(1000);
       
        Assert.assertTrue(rh.threadnameRef.get().indexOf("Pool-") != -1);
        Assert.assertNull(rh.responseRef.get());
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.