Package org.xsocket.connection

Examples of org.xsocket.connection.INonBlockingConnection


      return true;
    }
   
   
    public boolean onData(INonBlockingConnection connection) throws IOException, BufferUnderflowException, MaxReadSizeExceededException {
      INonBlockingConnection forwardConnection = (INonBlockingConnection) connection.getAttachment();

      ByteBuffer[] data = connection.readByteBufferByLength(connection.available());
      forwardConnection.write(data);
      forwardConnection.flush();
     
      return true;
    }
View Full Code Here


   
    public SSLClientToProxyHandler(String forwardHost, int forwardPort, INonBlockingConnection clientToProxyConnection) throws IOException {
      clientToProxyConnection.setFlushmode(FlushMode.ASYNC); // set flush mode async for performance reasons
      clientToProxyConnection.setAutoflush(true);
     
      INonBlockingConnection proxyToServerConnection = new NonBlockingConnection(InetAddress.getByName(forwardHost), forwardPort, new ProxyHandler(), 60 * 1000, SSLTestContextFactory.getSSLContext(), true, clientToProxyConnection.getWorkerpool());
     
      proxyToServerConnection.setFlushmode(FlushMode.ASYNC); // set flush mode async for performance reasons
      proxyToServerConnection.setAutoflush(true);
      proxyToServerConnection.setAttachment(clientToProxyConnection);
     
      clientToProxyConnection.setAttachment(proxyToServerConnection);
    }
View Full Code Here

   
    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.getBlockingBody().readString());
    }
   
    QAUtil.sleep(1000);
    Assert.assertEquals(5, pool.getNumActive());
    Assert.assertEquals(0, pool.getNumIdle());
    Assert.assertEquals(0, 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.getBlockingBody().readString());
View Full Code Here

   
    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.getBlockingBody().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.getBlockingBody().readString());
View Full Code Here

   
    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.getBlockingBody().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.getBlockingBody().readString());
View Full Code Here

        RequestHandler reqHdl = new RequestHandler();       
    HttpServer server = new HttpServer(reqHdl);
    server.start();
   
    INonBlockingConnection con = new NonBlockingConnection("localhost", server.getLocalPort());
    con.write("POST / HTTP/1.1\r\n" +
          "Host: localhost\r\n" +
          "User-Agent: me\r\n" +
          "Expect: 100-Continue\r\n" +
          "Content-Length: 2000\r\n" +
          "\r\n");

   
   
        while (reqHdl.getLastExchange() == null) {
            QAUtil.sleep(50);
        }
       
        reqHdl.getLastExchange().getRequest().getContentLength();
       
       
        QAUtil.sleep(500);
        try {
            con.readStringByDelimiter("\r\n\r\n");
            Assert.fail("BufferUnderflowException expected");
        } catch (BufferUnderflowException expected) { }

        reqHdl.getLastExchange().getRequest().getNonBlockingBody().available();

        QAUtil.sleep(500);
        String header = con.readStringByDelimiter("\r\n\r\n") + "\r\n";
        Assert.assertTrue(header.indexOf("100") != -1);

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

   
    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.getBlockingBody().readString());
    }
   
    QAUtil.sleep(1000);
    Assert.assertEquals(5, pool.getNumActive());
    Assert.assertEquals(0, pool.getNumIdle());
    Assert.assertEquals(0, 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.getBlockingBody().readString());
View Full Code Here

   
    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.getBlockingBody().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.getBlockingBody().readString());
View Full Code Here

   
    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.getBlockingBody().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.getBlockingBody().readString());
View Full Code Here

     public void testAutoContinueBodyAccess() throws Exception {
         RequestHandler reqHdl = new RequestHandler();       
         HttpServer server = new HttpServer(reqHdl);
         server.start();
        
         INonBlockingConnection con = new NonBlockingConnection("localhost", server.getLocalPort());
         con.write("POST / HTTP/1.1\r\n" +
                   "Host: localhost\r\n" +
                   "User-Agent: me\r\n" +
                   "Expect: 100-Continue\r\n" +
                   "Content-Length: 2000\r\n" +
                   "\r\n");
        
         while (reqHdl.getLastExchange() == null) {
             QAUtil.sleep(50);
         }
        
         IHttpExchange serverExchange = reqHdl.getLastExchange();
         IHttpRequest srvReq = serverExchange.getRequest();
         srvReq.getHeader("Content-Length");
        
         QAUtil.sleep(500);
         try {
             con.readStringByDelimiter("\r\n\r\n");
             Assert.fail("BufferUnderflowException expected");
         } catch (BufferUnderflowException expected) { }
        
         srvReq.getBody().isOpen();
        
         QAUtil.sleep(500);
         Assert.assertTrue(con.readStringByDelimiter("\r\n\r\n").indexOf("100") != -1);
        
         con.close();
         server.close();
     }
View Full Code Here

TOP

Related Classes of org.xsocket.connection.INonBlockingConnection

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.